2018-09-04 23:26:15 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2018, michag86 (michag86@arcor.de)
|
|
|
|
*
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author michag86 <micha_g@arcor.de>
|
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
|
|
|
*
|
2018-09-04 23:26:15 +03:00
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2018-09-04 23:26:15 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OC\Core\Command\App;
|
|
|
|
|
|
|
|
use OC\Installer;
|
2019-11-22 22:52:10 +03:00
|
|
|
use OCP\App\IAppManager;
|
2018-11-01 19:07:55 +03:00
|
|
|
use OCP\ILogger;
|
2018-09-04 23:26:15 +03:00
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
2019-11-22 22:52:10 +03:00
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
2018-09-04 23:26:15 +03:00
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
class Update extends Command {
|
|
|
|
|
|
|
|
/** @var IAppManager */
|
|
|
|
protected $manager;
|
|
|
|
/** @var Installer */
|
|
|
|
private $installer;
|
2018-11-01 19:07:55 +03:00
|
|
|
/** @var ILogger */
|
|
|
|
private $logger;
|
|
|
|
|
2018-09-04 23:26:15 +03:00
|
|
|
/**
|
|
|
|
* @param IAppManager $manager
|
|
|
|
* @param Installer $installer
|
|
|
|
*/
|
2018-11-01 19:07:55 +03:00
|
|
|
public function __construct(IAppManager $manager, Installer $installer, ILogger $logger) {
|
2018-09-04 23:26:15 +03:00
|
|
|
parent::__construct();
|
|
|
|
$this->manager = $manager;
|
|
|
|
$this->installer = $installer;
|
2018-11-01 19:07:55 +03:00
|
|
|
$this->logger = $logger;
|
2018-09-04 23:26:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function configure() {
|
|
|
|
$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 10:43:33 +03:00
|
|
|
->addOption(
|
|
|
|
'allow-unstable',
|
|
|
|
null,
|
|
|
|
InputOption::VALUE_NONE,
|
|
|
|
'allow updating to unstable releases'
|
|
|
|
)
|
2018-09-04 23:26:15 +03:00
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2020-06-26 15:54:51 +03:00
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int {
|
2018-09-04 23:26:15 +03:00
|
|
|
$singleAppId = $input->getArgument('app-id');
|
|
|
|
|
|
|
|
if ($singleAppId) {
|
2020-03-26 11:30:18 +03:00
|
|
|
$apps = [$singleAppId];
|
2018-09-04 23:26:15 +03:00
|
|
|
try {
|
|
|
|
$this->manager->getAppPath($singleAppId);
|
|
|
|
} catch (\OCP\App\AppPathNotFoundException $e) {
|
|
|
|
$output->writeln($singleAppId . ' not installed');
|
|
|
|
return 1;
|
|
|
|
}
|
2020-04-10 11:35:09 +03:00
|
|
|
} elseif ($input->getOption('all') || $input->getOption('showonly')) {
|
2018-09-04 23:26:15 +03:00
|
|
|
$apps = \OC_App::getAllApps();
|
|
|
|
} else {
|
|
|
|
$output->writeln("<error>Please specify an app to update or \"--all\" to update all updatable apps\"</error>");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$return = 0;
|
|
|
|
foreach ($apps as $appId) {
|
2020-04-30 10:43:33 +03:00
|
|
|
$newVersion = $this->installer->isUpdateAvailable($appId, $input->getOption('allow-unstable'));
|
2018-09-04 23:26:15 +03:00
|
|
|
if ($newVersion) {
|
|
|
|
$output->writeln($appId . ' new version available: ' . $newVersion);
|
|
|
|
|
|
|
|
if (!$input->getOption('showonly')) {
|
|
|
|
try {
|
2020-04-30 10:43:33 +03:00
|
|
|
$result = $this->installer->updateAppstoreApp($appId, $input->getOption('allow-unstable'));
|
2020-04-10 15:19:56 +03:00
|
|
|
} catch (\Exception $e) {
|
2018-11-01 19:07:55 +03:00
|
|
|
$this->logger->logException($e, ['message' => 'Failure during update of app "' . $appId . '"','app' => 'app:update']);
|
2018-09-04 23:26:15 +03:00
|
|
|
$output->writeln('Error: ' . $e->getMessage());
|
|
|
|
$return = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($result === false) {
|
|
|
|
$output->writeln($appId . ' couldn\'t be updated');
|
|
|
|
$return = 1;
|
2020-04-10 15:19:56 +03:00
|
|
|
} elseif ($result === true) {
|
2018-09-04 23:26:15 +03:00
|
|
|
$output->writeln($appId . ' updated');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $return;
|
|
|
|
}
|
|
|
|
}
|