aboutsummaryrefslogtreecommitdiffstats
path: root/core/Command/Maintenance/Repair.php
diff options
context:
space:
mode:
Diffstat (limited to 'core/Command/Maintenance/Repair.php')
-rw-r--r--core/Command/Maintenance/Repair.php142
1 files changed, 53 insertions, 89 deletions
diff --git a/core/Command/Maintenance/Repair.php b/core/Command/Maintenance/Repair.php
index 2a3d7a908e2..f0c88f6811b 100644
--- a/core/Command/Maintenance/Repair.php
+++ b/core/Command/Maintenance/Repair.php
@@ -1,69 +1,41 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Daniel Kesselberg <mail@danielkesselberg.de>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Temtaime <temtaime@gmail.com>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- * @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
*/
namespace OC\Core\Command\Maintenance;
use Exception;
+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 OCP\App\IAppManager;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Symfony\Component\EventDispatcher\GenericEvent;
class Repair extends Command {
- /** @var \OC\Repair $repair */
- protected $repair;
- /** @var IConfig */
- protected $config;
- /** @var EventDispatcherInterface */
- private $dispatcher;
- /** @var ProgressBar */
- private $progress;
- /** @var OutputInterface */
- private $output;
- /** @var IAppManager */
- private $appManager;
-
- /**
- * @param \OC\Repair $repair
- * @param IConfig $config
- * @param EventDispatcherInterface $dispatcher
- * @param IAppManager $appManager
- */
- public function __construct(\OC\Repair $repair, IConfig $config, EventDispatcherInterface $dispatcher, IAppManager $appManager) {
- $this->repair = $repair;
- $this->config = $config;
- $this->dispatcher = $dispatcher;
- $this->appManager = $appManager;
+ private ProgressBar $progress;
+ private OutputInterface $output;
+ protected bool $errored = false;
+
+ public function __construct(
+ protected \OC\Repair $repair,
+ protected IConfig $config,
+ private IEventDispatcher $dispatcher,
+ private IAppManager $appManager,
+ ) {
parent::__construct();
}
@@ -89,16 +61,16 @@ class Repair extends Command {
$this->repair->addStep($step);
}
- $apps = $this->appManager->getInstalledApps();
+ $apps = $this->appManager->getEnabledApps();
foreach ($apps as $app) {
if (!$this->appManager->isEnabledForUser($app)) {
continue;
}
- $info = \OC_App::getAppInfo($app);
+ $info = $this->appManager->getAppInfo($app);
if (!is_array($info)) {
continue;
}
- \OC_App::loadApp($app);
+ $this->appManager->loadApp($app);
$steps = $info['repair-steps']['post-migration'];
foreach ($steps as $step) {
try {
@@ -109,52 +81,44 @@ class Repair extends Command {
}
}
+
+
$maintenanceMode = $this->config->getSystemValueBool('maintenance');
$this->config->setSystemValue('maintenance', true);
$this->progress = new ProgressBar($output);
$this->output = $output;
- $this->dispatcher->addListener('\OC\Repair::startProgress', [$this, 'handleRepairFeedBack']);
- $this->dispatcher->addListener('\OC\Repair::advance', [$this, 'handleRepairFeedBack']);
- $this->dispatcher->addListener('\OC\Repair::finishProgress', [$this, 'handleRepairFeedBack']);
- $this->dispatcher->addListener('\OC\Repair::step', [$this, 'handleRepairFeedBack']);
- $this->dispatcher->addListener('\OC\Repair::info', [$this, 'handleRepairFeedBack']);
- $this->dispatcher->addListener('\OC\Repair::warning', [$this, 'handleRepairFeedBack']);
- $this->dispatcher->addListener('\OC\Repair::error', [$this, 'handleRepairFeedBack']);
+ $this->dispatcher->addListener(RepairStartEvent::class, [$this, 'handleRepairFeedBack']);
+ $this->dispatcher->addListener(RepairAdvanceEvent::class, [$this, 'handleRepairFeedBack']);
+ $this->dispatcher->addListener(RepairFinishEvent::class, [$this, 'handleRepairFeedBack']);
+ $this->dispatcher->addListener(RepairStepEvent::class, [$this, 'handleRepairFeedBack']);
+ $this->dispatcher->addListener(RepairInfoEvent::class, [$this, 'handleRepairFeedBack']);
+ $this->dispatcher->addListener(RepairWarningEvent::class, [$this, 'handleRepairFeedBack']);
+ $this->dispatcher->addListener(RepairErrorEvent::class, [$this, 'handleRepairFeedBack']);
$this->repair->run();
$this->config->setSystemValue('maintenance', $maintenanceMode);
- return 0;
+ return $this->errored ? 1 : 0;
}
- public function handleRepairFeedBack($event) {
- if (!$event instanceof GenericEvent) {
- return;
- }
- switch ($event->getSubject()) {
- case '\OC\Repair::startProgress':
- $this->progress->start($event->getArgument(0));
- break;
- case '\OC\Repair::advance':
- $this->progress->advance($event->getArgument(0));
- break;
- case '\OC\Repair::finishProgress':
- $this->progress->finish();
- $this->output->writeln('');
- break;
- case '\OC\Repair::step':
- $this->output->writeln(' - ' . $event->getArgument(0));
- break;
- case '\OC\Repair::info':
- $this->output->writeln(' - ' . $event->getArgument(0));
- break;
- case '\OC\Repair::warning':
- $this->output->writeln(' - WARNING: ' . $event->getArgument(0));
- break;
- case '\OC\Repair::error':
- $this->output->writeln('<error> - ERROR: ' . $event->getArgument(0) . '</error>');
- break;
+ public function handleRepairFeedBack(Event $event): void {
+ if ($event instanceof RepairStartEvent) {
+ $this->progress->start($event->getMaxStep());
+ } elseif ($event instanceof RepairAdvanceEvent) {
+ $this->progress->advance($event->getIncrement());
+ } elseif ($event instanceof RepairFinishEvent) {
+ $this->progress->finish();
+ $this->output->writeln('');
+ } elseif ($event instanceof RepairStepEvent) {
+ $this->output->writeln('<info> - ' . $event->getStepName() . '</info>');
+ } elseif ($event instanceof RepairInfoEvent) {
+ $this->output->writeln('<info> - ' . $event->getMessage() . '</info>');
+ } elseif ($event instanceof RepairWarningEvent) {
+ $this->output->writeln('<comment> - WARNING: ' . $event->getMessage() . '</comment>');
+ } elseif ($event instanceof RepairErrorEvent) {
+ $this->output->writeln('<error> - ERROR: ' . $event->getMessage() . '</error>');
+ $this->errored = true;
}
}
}