diff options
Diffstat (limited to 'core/ajax/update.php')
-rw-r--r-- | core/ajax/update.php | 223 |
1 files changed, 84 insertions, 139 deletions
diff --git a/core/ajax/update.php b/core/ajax/update.php index 39a99323cf5..69665cf62df 100644 --- a/core/ajax/update.php +++ b/core/ajax/update.php @@ -1,112 +1,54 @@ <?php + /** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Arthur Schiwon <blizzz@arthur-schiwon.de> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.com> - * @author Ko- <k.stoffelen@cs.ru.nl> - * @author Lukas Reschke <lukas@statuscode.ch> - * @author Michael Gapczynski <GapczynskiM@gmail.com> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * @author Valdnet <47037905+Valdnet@users.noreply.github.com> - * @author Victor Dubiniuk <dubiniuk@owncloud.com> - * @author Vincent Petry <vincent@nextcloud.com> - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * 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, version 3, - * along with this program. If not, see <http://www.gnu.org/licenses/> - * + * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-FileCopyrightText: 2016 ownCloud, Inc. + * SPDX-License-Identifier: AGPL-3.0-only */ -use OCP\ILogger; -use Symfony\Component\EventDispatcher\GenericEvent; - -if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { +use OC\Core\Listener\FeedBackHandler; +use OC\DB\MigratorExecuteSqlEvent; +use OC\Installer; +use OC\IntegrityCheck\Checker; +use OC\Repair\Events\RepairAdvanceEvent; +use OC\Repair\Events\RepairErrorEvent; +use OC\Repair\Events\RepairFinishEvent; +use OC\Repair\Events\RepairInfoEvent; +use OC\Repair\Events\RepairStartEvent; +use OC\Repair\Events\RepairStepEvent; +use OC\Repair\Events\RepairWarningEvent; +use OC\SystemConfig; +use OC\Updater; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\IAppConfig; +use OCP\IConfig; +use OCP\IEventSourceFactory; +use OCP\IL10N; +use OCP\L10N\IFactory; +use OCP\Server; +use OCP\ServerVersion; +use OCP\Util; +use Psr\Log\LoggerInterface; + +if (!str_contains(@ini_get('disable_functions'), 'set_time_limit')) { @set_time_limit(0); } require_once '../../lib/base.php'; -$l = \OC::$server->getL10N('core'); +/** @var IL10N $l */ +$l = Server::get(IFactory::class)->get('core'); -$eventSource = \OC::$server->createEventSource(); +$eventSource = Server::get(IEventSourceFactory::class)->create(); // need to send an initial message to force-init the event source, // which will then trigger its own CSRF check and produces its own CSRF error // message $eventSource->send('success', $l->t('Preparing update')); -class FeedBackHandler { - /** @var integer */ - private $progressStateMax = 100; - /** @var integer */ - private $progressStateStep = 0; - /** @var string */ - private $currentStep; - /** @var \OCP\IEventSource */ - private $eventSource; - /** @var \OCP\IL10N */ - private $l10n; - - public function __construct(\OCP\IEventSource $eventSource, \OCP\IL10N $l10n) { - $this->eventSource = $eventSource; - $this->l10n = $l10n; - } - - public function handleRepairFeedback($event) { - if (!$event instanceof GenericEvent) { - return; - } - - switch ($event->getSubject()) { - case '\OC\Repair::startProgress': - $this->progressStateMax = $event->getArgument(0); - $this->progressStateStep = 0; - $this->currentStep = $event->getArgument(1); - break; - case '\OC\Repair::advance': - $this->progressStateStep += $event->getArgument(0); - $desc = $event->getArgument(1); - if (empty($desc)) { - $desc = $this->currentStep; - } - $this->eventSource->send('success', $this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $desc])); - break; - case '\OC\Repair::finishProgress': - $this->progressStateMax = $this->progressStateStep; - $this->eventSource->send('success', $this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $this->currentStep])); - break; - case '\OC\Repair::step': - $this->eventSource->send('success', $this->l10n->t('Repair step:') . ' ' . $event->getArgument(0)); - break; - case '\OC\Repair::info': - $this->eventSource->send('success', $this->l10n->t('Repair info:') . ' ' . $event->getArgument(0)); - break; - case '\OC\Repair::warning': - $this->eventSource->send('notice', $this->l10n->t('Repair warning:') . ' ' . $event->getArgument(0)); - break; - case '\OC\Repair::error': - $this->eventSource->send('notice', $this->l10n->t('Repair error:') . ' ' . $event->getArgument(0)); - break; - } - } -} - -if (\OCP\Util::needUpgrade()) { - $config = \OC::$server->getSystemConfig(); +if (Util::needUpgrade()) { + $config = Server::get(SystemConfig::class); if ($config->getValue('upgrade.disable-web', false)) { - $eventSource->send('failure', $l->t('Please use the command line updater because automatic updating is disabled in the config.php.')); + $eventSource->send('failure', $l->t('Please use the command line updater because updating via browser is disabled in your config.php.')); $eventSource->close(); exit(); } @@ -115,88 +57,91 @@ if (\OCP\Util::needUpgrade()) { // avoid side effects \OC_User::setIncognitoMode(true); - $logger = \OC::$server->get(\Psr\Log\LoggerInterface::class); - $config = \OC::$server->getConfig(); - $updater = new \OC\Updater( - $config, - \OC::$server->getIntegrityCodeChecker(), - $logger, - \OC::$server->query(\OC\Installer::class) + $config = Server::get(IConfig::class); + $updater = new Updater( + Server::get(ServerVersion::class), + $config, + Server::get(IAppConfig::class), + Server::get(Checker::class), + Server::get(LoggerInterface::class), + Server::get(Installer::class) ); $incompatibleApps = []; - - $dispatcher = \OC::$server->getEventDispatcher(); - $dispatcher->addListener('\OC\DB\Migrator::executeSql', function ($event) use ($eventSource, $l) { - if ($event instanceof GenericEvent) { - $eventSource->send('success', $l->t('[%d / %d]: %s', [$event[0], $event[1], $event->getSubject()])); - } - }); - $dispatcher->addListener('\OC\DB\Migrator::checkTable', function ($event) use ($eventSource, $l) { - if ($event instanceof GenericEvent) { - $eventSource->send('success', $l->t('[%d / %d]: Checking table %s', [$event[0], $event[1], $event->getSubject()])); + $incompatibleOverwrites = $config->getSystemValue('app_install_overwrite', []); + + /** @var IEventDispatcher $dispatcher */ + $dispatcher = Server::get(IEventDispatcher::class); + $dispatcher->addListener( + MigratorExecuteSqlEvent::class, + function (MigratorExecuteSqlEvent $event) use ($eventSource, $l): void { + $eventSource->send('success', $l->t('[%d / %d]: %s', [$event->getCurrentStep(), $event->getMaxStep(), $event->getSql()])); } - }); + ); $feedBack = new FeedBackHandler($eventSource, $l); - $dispatcher->addListener('\OC\Repair::startProgress', [$feedBack, 'handleRepairFeedback']); - $dispatcher->addListener('\OC\Repair::advance', [$feedBack, 'handleRepairFeedback']); - $dispatcher->addListener('\OC\Repair::finishProgress', [$feedBack, 'handleRepairFeedback']); - $dispatcher->addListener('\OC\Repair::step', [$feedBack, 'handleRepairFeedback']); - $dispatcher->addListener('\OC\Repair::info', [$feedBack, 'handleRepairFeedback']); - $dispatcher->addListener('\OC\Repair::warning', [$feedBack, 'handleRepairFeedback']); - $dispatcher->addListener('\OC\Repair::error', [$feedBack, 'handleRepairFeedback']); - - $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($eventSource, $l) { + $dispatcher->addListener(RepairStartEvent::class, [$feedBack, 'handleRepairFeedback']); + $dispatcher->addListener(RepairAdvanceEvent::class, [$feedBack, 'handleRepairFeedback']); + $dispatcher->addListener(RepairFinishEvent::class, [$feedBack, 'handleRepairFeedback']); + $dispatcher->addListener(RepairStepEvent::class, [$feedBack, 'handleRepairFeedback']); + $dispatcher->addListener(RepairInfoEvent::class, [$feedBack, 'handleRepairFeedback']); + $dispatcher->addListener(RepairWarningEvent::class, [$feedBack, 'handleRepairFeedback']); + $dispatcher->addListener(RepairErrorEvent::class, [$feedBack, 'handleRepairFeedback']); + + $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($eventSource, $l): void { $eventSource->send('success', $l->t('Turned on maintenance mode')); }); - $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($eventSource, $l) { + $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($eventSource, $l): void { $eventSource->send('success', $l->t('Turned off maintenance mode')); }); - $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($eventSource, $l) { + $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($eventSource, $l): void { $eventSource->send('success', $l->t('Maintenance mode is kept active')); }); - $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use ($eventSource, $l) { + $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use ($eventSource, $l): void { $eventSource->send('success', $l->t('Updating database schema')); }); - $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($eventSource, $l) { + $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($eventSource, $l): void { $eventSource->send('success', $l->t('Updated database')); }); - $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($eventSource, $l) { + $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($eventSource, $l): void { $eventSource->send('success', $l->t('Update app "%s" from App Store', [$app])); }); - $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($eventSource, $l) { + $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($eventSource, $l): void { $eventSource->send('success', $l->t('Checking whether the database schema for %s can be updated (this can take a long time depending on the database size)', [$app])); }); - $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($eventSource, $l) { + $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($eventSource, $l): void { $eventSource->send('success', $l->t('Updated "%1$s" to %2$s', [$app, $version])); }); - $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use (&$incompatibleApps) { - $incompatibleApps[] = $app; + $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use (&$incompatibleApps, &$incompatibleOverwrites): void { + if (!in_array($app, $incompatibleOverwrites)) { + $incompatibleApps[] = $app; + } }); - $updater->listen('\OC\Updater', 'failure', function ($message) use ($eventSource, $config) { + $updater->listen('\OC\Updater', 'failure', function ($message) use ($eventSource, $config): void { $eventSource->send('failure', $message); $eventSource->close(); $config->setSystemValue('maintenance', false); }); - $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use ($eventSource, $l) { + $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use ($eventSource, $l): void { $eventSource->send('success', $l->t('Set log level to debug')); }); - $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use ($eventSource, $l) { + $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use ($eventSource, $l): void { $eventSource->send('success', $l->t('Reset log level')); }); - $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use ($eventSource, $l) { + $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use ($eventSource, $l): void { $eventSource->send('success', $l->t('Starting code integrity check')); }); - $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use ($eventSource, $l) { + $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use ($eventSource, $l): void { $eventSource->send('success', $l->t('Finished code integrity check')); }); try { $updater->upgrade(); } catch (\Exception $e) { - \OC::$server->getLogger()->logException($e, [ - 'level' => ILogger::ERROR, - 'app' => 'update', - ]); + Server::get(LoggerInterface::class)->error( + $e->getMessage(), + [ + 'exception' => $e, + 'app' => 'update', + ]); $eventSource->send('failure', get_class($e) . ': ' . $e->getMessage()); $eventSource->close(); exit(); |