aboutsummaryrefslogtreecommitdiffstats
path: root/core/ajax/update.php
diff options
context:
space:
mode:
Diffstat (limited to 'core/ajax/update.php')
-rw-r--r--core/ajax/update.php94
1 files changed, 31 insertions, 63 deletions
diff --git a/core/ajax/update.php b/core/ajax/update.php
index 0868eff72b4..69665cf62df 100644
--- a/core/ajax/update.php
+++ b/core/ajax/update.php
@@ -5,7 +5,10 @@
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-only
*/
+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;
@@ -13,15 +16,18 @@ 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\IEventSource;
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')) {
@@ -30,55 +36,17 @@ if (!str_contains(@ini_get('disable_functions'), 'set_time_limit')) {
require_once '../../lib/base.php';
-/** @var \OCP\IL10N $l */
-$l = \OC::$server->get(IFactory::class)->get('core');
+/** @var IL10N $l */
+$l = Server::get(IFactory::class)->get('core');
-$eventSource = \OC::$server->get(IEventSourceFactory::class)->create();
+$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 {
- private int $progressStateMax = 100;
- private int $progressStateStep = 0;
- private string $currentStep = '';
-
- public function __construct(
- private IEventSource $eventSource,
- private IL10N $l10n,
- ) {
- }
-
- public function handleRepairFeedback(Event $event): void {
- if ($event instanceof RepairStartEvent) {
- $this->progressStateMax = $event->getMaxStep();
- $this->progressStateStep = 0;
- $this->currentStep = $event->getCurrentStepName();
- } elseif ($event instanceof RepairAdvanceEvent) {
- $this->progressStateStep += $event->getIncrement();
- $desc = $event->getDescription();
- if (empty($desc)) {
- $desc = $this->currentStep;
- }
- $this->eventSource->send('success', $this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $desc]));
- } elseif ($event instanceof RepairFinishEvent) {
- $this->progressStateMax = $this->progressStateStep;
- $this->eventSource->send('success', $this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $this->currentStep]));
- } elseif ($event instanceof RepairStepEvent) {
- $this->eventSource->send('success', $this->l10n->t('Repair step:') . ' ' . $event->getStepName());
- } elseif ($event instanceof RepairInfoEvent) {
- $this->eventSource->send('success', $this->l10n->t('Repair info:') . ' ' . $event->getMessage());
- } elseif ($event instanceof RepairWarningEvent) {
- $this->eventSource->send('notice', $this->l10n->t('Repair warning:') . ' ' . $event->getMessage());
- } elseif ($event instanceof RepairErrorEvent) {
- $this->eventSource->send('error', $this->l10n->t('Repair error:') . ' ' . $event->getMessage());
- }
- }
-}
-
-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 updating via browser is disabled in your config.php.'));
$eventSource->close();
@@ -90,19 +58,19 @@ if (\OCP\Util::needUpgrade()) {
\OC_User::setIncognitoMode(true);
$config = Server::get(IConfig::class);
- $updater = new \OC\Updater(
- Server::get(\OCP\ServerVersion::class),
+ $updater = new Updater(
+ Server::get(ServerVersion::class),
$config,
Server::get(IAppConfig::class),
- \OC::$server->getIntegrityCodeChecker(),
+ Server::get(Checker::class),
Server::get(LoggerInterface::class),
- Server::get(\OC\Installer::class)
+ Server::get(Installer::class)
);
$incompatibleApps = [];
$incompatibleOverwrites = $config->getSystemValue('app_install_overwrite', []);
/** @var IEventDispatcher $dispatcher */
- $dispatcher = \OC::$server->get(IEventDispatcher::class);
+ $dispatcher = Server::get(IEventDispatcher::class);
$dispatcher->addListener(
MigratorExecuteSqlEvent::class,
function (MigratorExecuteSqlEvent $event) use ($eventSource, $l): void {
@@ -118,50 +86,50 @@ if (\OCP\Util::needUpgrade()) {
$dispatcher->addListener(RepairWarningEvent::class, [$feedBack, 'handleRepairFeedback']);
$dispatcher->addListener(RepairErrorEvent::class, [$feedBack, 'handleRepairFeedback']);
- $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($eventSource, $l) {
+ $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, &$incompatibleOverwrites) {
+ $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'));
});