diff options
Diffstat (limited to 'core/Command/Upgrade.php')
-rw-r--r-- | core/Command/Upgrade.php | 104 |
1 files changed, 44 insertions, 60 deletions
diff --git a/core/Command/Upgrade.php b/core/Command/Upgrade.php index 0a66d63fd32..13e150217b9 100644 --- a/core/Command/Upgrade.php +++ b/core/Command/Upgrade.php @@ -3,17 +3,18 @@ * @copyright Copyright (c) 2016, ownCloud, Inc. * * @author Andreas Fischer <bantu@owncloud.com> - * @author Björn Schießle <bjoern@schiessle.org> + * @author Christoph Wurst <christoph@winzerhof-wurst.at> * @author Joas Schilling <coding@schilljs.com> - * @author Jürgen Haas <juergen@paragon-es.de> * @author Lukas Reschke <lukas@statuscode.ch> * @author Morris Jobke <hey@morrisjobke.de> + * @author Nils Wittenbrink <nilswittenbrink@web.de> * @author Owen Winkler <a_github@midnightcircus.com> * @author Robin Appelman <robin@icewind.nl> * @author Sander Ruitenbeek <sander@grids.be> * @author Thomas Müller <thomas.mueller@tmit.eu> * @author Thomas Pulzer <t.pulzer@kniel.de> - * @author Vincent Petry <pvince81@owncloud.com> + * @author Valdnet <47037905+Valdnet@users.noreply.github.com> + * @author Vincent Petry <vincent@nextcloud.com> * * @license AGPL-3.0 * @@ -30,15 +31,14 @@ * along with this program. If not, see <http://www.gnu.org/licenses/> * */ - namespace OC\Core\Command; use OC\Console\TimestampFormatter; use OC\Installer; use OC\Updater; use OCP\IConfig; -use OCP\ILogger; use OCP\Util; +use Psr\Log\LoggerInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputInterface; @@ -46,26 +46,23 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\EventDispatcher\GenericEvent; class Upgrade extends Command { - - const ERROR_SUCCESS = 0; - const ERROR_NOT_INSTALLED = 1; - const ERROR_MAINTENANCE_MODE = 2; - const ERROR_UP_TO_DATE = 0; - const ERROR_INVALID_ARGUMENTS = 4; - const ERROR_FAILURE = 5; + public const ERROR_SUCCESS = 0; + public const ERROR_NOT_INSTALLED = 1; + public const ERROR_MAINTENANCE_MODE = 2; + public const ERROR_UP_TO_DATE = 0; + public const ERROR_INVALID_ARGUMENTS = 4; + public const ERROR_FAILURE = 5; /** @var IConfig */ private $config; - /** @var ILogger */ + /** @var LoggerInterface */ private $logger; - /** - * @param IConfig $config - * @param ILogger $logger - * @param Installer $installer - */ - public function __construct(IConfig $config, ILogger $logger, Installer $installer) { + /** @var Installer */ + private $installer; + + public function __construct(IConfig $config, LoggerInterface $logger, Installer $installer) { parent::__construct(); $this->config = $config; $this->logger = $logger; @@ -84,9 +81,8 @@ class Upgrade extends Command { * @param InputInterface $input input interface * @param OutputInterface $output output interface */ - protected function execute(InputInterface $input, OutputInterface $output) { - - if(Util::needUpgrade()) { + protected function execute(InputInterface $input, OutputInterface $output): int { + if (Util::needUpgrade()) { if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { // Prepend each line with a little timestamp $timestampFormatter = new TimestampFormatter($this->config, $output->getFormatter()); @@ -104,7 +100,7 @@ class Upgrade extends Command { $dispatcher = \OC::$server->getEventDispatcher(); $progress = new ProgressBar($output); $progress->setFormat(" %message%\n %current%/%max% [%bar%] %percent:3s%%"); - $listener = function($event) use ($progress, $output) { + $listener = function ($event) use ($progress, $output) { if ($event instanceof GenericEvent) { $message = $event->getSubject(); if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { @@ -127,7 +123,7 @@ class Upgrade extends Command { } } }; - $repairListener = function($event) use ($progress, $output) { + $repairListener = function ($event) use ($progress, $output) { if (!$event instanceof GenericEvent) { return; } @@ -152,12 +148,12 @@ class Upgrade extends Command { $output->writeln(''); break; case '\OC\Repair::step': - if(OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { + if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { $output->writeln('<info>Repair step: ' . $event->getArgument(0) . '</info>'); } break; case '\OC\Repair::info': - if(OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { + if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { $output->writeln('<info>Repair info: ' . $event->getArgument(0) . '</info>'); } break; @@ -181,17 +177,17 @@ class Upgrade extends Command { $dispatcher->addListener('\OC\Repair::error', $repairListener); - $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use($output) { + $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($output) { $output->writeln('<info>Turned on maintenance mode</info>'); }); - $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use($output) { + $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($output) { $output->writeln('<info>Turned off maintenance mode</info>'); }); - $updater->listen('\OC\Updater', 'maintenanceActive', function () use($output) { + $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($output) { $output->writeln('<info>Maintenance mode is kept active</info>'); }); $updater->listen('\OC\Updater', 'updateEnd', - function ($success) use($output, $self) { + function ($success) use ($output, $self) { if ($success) { $message = "<info>Update successful</info>"; } else { @@ -199,58 +195,46 @@ class Upgrade extends Command { } $output->writeln($message); }); - $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use($output) { + $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use ($output) { $output->writeln('<info>Updating database schema</info>'); }); - $updater->listen('\OC\Updater', 'dbUpgrade', function () use($output) { + $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($output) { $output->writeln('<info>Updated database</info>'); }); - $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use($output) { - $output->writeln('<info>Checking whether the database schema can be updated (this can take a long time depending on the database size)</info>'); - }); - $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($output) { - $output->writeln('<info>Checked database schema update</info>'); - }); - $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use($output) { + $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use ($output) { $output->writeln('<comment>Disabled incompatible app: ' . $app . '</comment>'); }); - $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use($output) { + $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($output) { $output->writeln('<info>Checking for update of app ' . $app . ' in appstore</info>'); }); - $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use($output) { - $output->writeln('<info>Update app ' . $app . ' from appstore</info>'); + $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($output) { + $output->writeln('<info>Update app ' . $app . ' from App Store</info>'); }); - $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use($output) { - $output->writeln('<info>Checked for update of app "' . $app . '" in appstore </info>'); - }); - $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($output) { - $output->writeln('<info>Checking updates of apps</info>'); + $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($output) { + $output->writeln('<info>Checked for update of app "' . $app . '" in App Store </info>'); }); $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($output) { $output->writeln("<info>Checking whether the database schema for <$app> can be updated (this can take a long time depending on the database size)</info>"); }); - $updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($output) { - $output->writeln('<info>Checked database schema update for apps</info>'); - }); $updater->listen('\OC\Updater', 'appUpgradeStarted', function ($app, $version) use ($output) { $output->writeln("<info>Updating <$app> ...</info>"); }); $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($output) { $output->writeln("<info>Updated <$app> to $version</info>"); }); - $updater->listen('\OC\Updater', 'failure', function ($message) use($output, $self) { + $updater->listen('\OC\Updater', 'failure', function ($message) use ($output, $self) { $output->writeln("<error>$message</error>"); }); - $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use($output) { - $output->writeln("<info>Set log level to debug</info>"); + $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use ($output) { + $output->writeln("<info>Setting log level to debug</info>"); }); - $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use($output) { - $output->writeln("<info>Reset log level</info>"); + $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use ($output) { + $output->writeln("<info>Resetting log level</info>"); }); - $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use($output) { + $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use ($output) { $output->writeln("<info>Starting code integrity check...</info>"); }); - $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use($output) { + $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use ($output) { $output->writeln("<info>Finished code integrity check</info>"); }); @@ -258,14 +242,14 @@ class Upgrade extends Command { $this->postUpgradeCheck($input, $output); - if(!$success) { + if (!$success) { return self::ERROR_FAILURE; } return self::ERROR_SUCCESS; - } else if($this->config->getSystemValueBool('maintenance')) { + } elseif ($this->config->getSystemValueBool('maintenance')) { //Possible scenario: Nextcloud core is updated but an app failed - $output->writeln('<warning>Nextcloud is in maintenance mode</warning>'); + $output->writeln('<comment>Nextcloud is in maintenance mode</comment>'); $output->write('<comment>Maybe an upgrade is already in process. Please check the ' . 'logfile (data/nextcloud.log). If you want to re-run the ' . 'upgrade procedure, remove the "maintenance mode" from ' |