2018-09-04 16:26:15 -04:00
|
|
|
<?php
|
2024-03-06 05:54:58 -05:00
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2018-09-04 16:26:15 -04:00
|
|
|
/**
|
2024-05-24 13:43:47 -04:00
|
|
|
* SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2018-09-04 16:26:15 -04:00
|
|
|
*/
|
|
|
|
|
namespace OC\Core\Command\App;
|
|
|
|
|
|
|
|
|
|
use OC\Installer;
|
2025-05-14 09:51:42 -04:00
|
|
|
use OCP\App\AppPathNotFoundException;
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCP\App\IAppManager;
|
2024-12-06 13:25:32 -05:00
|
|
|
use OCP\IConfig;
|
2022-04-12 11:55:01 -04:00
|
|
|
use Psr\Log\LoggerInterface;
|
2018-09-04 16:26:15 -04:00
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
2019-11-22 14:52:10 -05:00
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
2018-09-04 16:26:15 -04:00
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
|
|
class Update extends Command {
|
2024-12-06 13:25:32 -05:00
|
|
|
public const APP_STORE_URL = 'https://apps.nextcloud.com/api/v1';
|
|
|
|
|
|
2023-06-12 11:02:59 -04:00
|
|
|
public function __construct(
|
|
|
|
|
protected IAppManager $manager,
|
2024-12-06 13:25:32 -05:00
|
|
|
protected IConfig $config,
|
2023-06-12 11:02:59 -04:00
|
|
|
private Installer $installer,
|
|
|
|
|
private LoggerInterface $logger,
|
|
|
|
|
) {
|
2018-09-04 16:26:15 -04:00
|
|
|
parent::__construct();
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-06 04:00:27 -04:00
|
|
|
protected function configure(): void {
|
2018-09-04 16:26:15 -04:00
|
|
|
$this
|
|
|
|
|
->setName('app:update')
|
|
|
|
|
->setDescription('update an app or all apps')
|
|
|
|
|
->addArgument(
|
|
|
|
|
'app-id',
|
|
|
|
|
InputArgument::OPTIONAL,
|
|
|
|
|
'update the specified app'
|
|
|
|
|
)
|
|
|
|
|
->addOption(
|
|
|
|
|
'all',
|
|
|
|
|
null,
|
|
|
|
|
InputOption::VALUE_NONE,
|
|
|
|
|
'update all updatable apps'
|
|
|
|
|
)
|
|
|
|
|
->addOption(
|
|
|
|
|
'showonly',
|
|
|
|
|
null,
|
|
|
|
|
InputOption::VALUE_NONE,
|
|
|
|
|
'show update(s) without updating'
|
|
|
|
|
)
|
2020-04-30 03:43:33 -04:00
|
|
|
->addOption(
|
|
|
|
|
'allow-unstable',
|
|
|
|
|
null,
|
|
|
|
|
InputOption::VALUE_NONE,
|
|
|
|
|
'allow updating to unstable releases'
|
|
|
|
|
)
|
2018-09-04 16:26:15 -04:00
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 08:54:51 -04:00
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int {
|
2024-12-06 13:25:32 -05:00
|
|
|
$appStoreEnabled = $this->config->getSystemValueBool('appstoreenabled', true);
|
|
|
|
|
if ($appStoreEnabled === false) {
|
|
|
|
|
$output->writeln('App store access is disabled');
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$internetAvailable = $this->config->getSystemValueBool('has_internet_connection', true);
|
|
|
|
|
$isDefaultAppStore = $this->config->getSystemValueString('appstoreurl', self::APP_STORE_URL) === self::APP_STORE_URL;
|
|
|
|
|
if ($internetAvailable === false && $isDefaultAppStore === true) {
|
|
|
|
|
$output->writeln('Internet connection is disabled, and therefore the default public App store is not reachable');
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-04 16:26:15 -04:00
|
|
|
$singleAppId = $input->getArgument('app-id');
|
2023-09-20 10:32:29 -04:00
|
|
|
$updateFound = false;
|
2018-09-04 16:26:15 -04:00
|
|
|
|
|
|
|
|
if ($singleAppId) {
|
2020-03-26 04:30:18 -04:00
|
|
|
$apps = [$singleAppId];
|
2018-09-04 16:26:15 -04:00
|
|
|
try {
|
|
|
|
|
$this->manager->getAppPath($singleAppId);
|
2025-05-14 09:51:42 -04:00
|
|
|
} catch (AppPathNotFoundException $e) {
|
2018-09-04 16:26:15 -04:00
|
|
|
$output->writeln($singleAppId . ' not installed');
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
2020-04-10 04:35:09 -04:00
|
|
|
} elseif ($input->getOption('all') || $input->getOption('showonly')) {
|
2024-09-12 10:38:35 -04:00
|
|
|
$apps = $this->manager->getAllAppsInAppsFolders();
|
2018-09-04 16:26:15 -04:00
|
|
|
} else {
|
2024-08-23 09:10:27 -04:00
|
|
|
$output->writeln('<error>Please specify an app to update or "--all" to update all updatable apps"</error>');
|
2018-09-04 16:26:15 -04:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$return = 0;
|
|
|
|
|
foreach ($apps as $appId) {
|
2020-04-30 03:43:33 -04:00
|
|
|
$newVersion = $this->installer->isUpdateAvailable($appId, $input->getOption('allow-unstable'));
|
2018-09-04 16:26:15 -04:00
|
|
|
if ($newVersion) {
|
2023-09-20 10:32:29 -04:00
|
|
|
$updateFound = true;
|
2018-09-04 16:26:15 -04:00
|
|
|
$output->writeln($appId . ' new version available: ' . $newVersion);
|
|
|
|
|
|
|
|
|
|
if (!$input->getOption('showonly')) {
|
|
|
|
|
try {
|
2020-04-30 03:43:33 -04:00
|
|
|
$result = $this->installer->updateAppstoreApp($appId, $input->getOption('allow-unstable'));
|
2020-04-10 08:19:56 -04:00
|
|
|
} catch (\Exception $e) {
|
2022-04-12 11:55:01 -04:00
|
|
|
$this->logger->error('Failure during update of app "' . $appId . '"', [
|
|
|
|
|
'app' => 'app:update',
|
|
|
|
|
'exception' => $e,
|
|
|
|
|
]);
|
2018-09-04 16:26:15 -04:00
|
|
|
$output->writeln('Error: ' . $e->getMessage());
|
2023-12-26 15:40:16 -05:00
|
|
|
$result = false;
|
2018-09-04 16:26:15 -04:00
|
|
|
$return = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($result === false) {
|
|
|
|
|
$output->writeln($appId . ' couldn\'t be updated');
|
|
|
|
|
$return = 1;
|
2024-03-06 05:54:58 -05:00
|
|
|
} else {
|
2018-09-04 16:26:15 -04:00
|
|
|
$output->writeln($appId . ' updated');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-20 10:32:29 -04:00
|
|
|
if (!$updateFound) {
|
|
|
|
|
if ($singleAppId) {
|
|
|
|
|
$output->writeln($singleAppId . ' is up-to-date or no updates could be found');
|
|
|
|
|
} else {
|
|
|
|
|
$output->writeln('All apps are up-to-date or no updates could be found');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-04 16:26:15 -04:00
|
|
|
return $return;
|
|
|
|
|
}
|
|
|
|
|
}
|