2013-11-26 08:12:48 -05:00
|
|
|
<?php
|
|
|
|
|
/**
|
2016-07-21 11:07:57 -04:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
|
*
|
2019-12-03 13:57:53 -05:00
|
|
|
* @author Daniel Kesselberg <mail@danielkesselberg.de>
|
2016-07-21 11:07:57 -04:00
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
2015-03-26 06:44:34 -04:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2016-07-21 12:13:36 -04:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
2019-12-03 13:57:53 -05:00
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
|
|
|
|
* @author Temtaime <temtaime@gmail.com>
|
2016-05-26 13:56:05 -04:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
2020-12-16 08:54:15 -05:00
|
|
|
* @author Vincent Petry <vincent@nextcloud.com>
|
2015-03-26 06:44:34 -04:00
|
|
|
*
|
|
|
|
|
* @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,
|
2019-12-03 13:57:53 -05:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
2015-03-26 06:44:34 -04:00
|
|
|
*
|
2013-11-26 08:12:48 -05:00
|
|
|
*/
|
|
|
|
|
namespace OC\Core\Command\Maintenance;
|
|
|
|
|
|
2016-04-19 09:36:11 -04:00
|
|
|
use Exception;
|
2017-10-24 08:13:45 -04:00
|
|
|
use OCP\App\IAppManager;
|
2022-08-22 11:59:26 -04:00
|
|
|
use OCP\EventDispatcher\Event;
|
|
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2016-04-26 10:24:50 -04:00
|
|
|
use OCP\IConfig;
|
2022-08-22 11:59:26 -04:00
|
|
|
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;
|
2013-11-26 08:12:48 -05:00
|
|
|
use Symfony\Component\Console\Command\Command;
|
2016-04-26 10:24:50 -04:00
|
|
|
use Symfony\Component\Console\Helper\ProgressBar;
|
2013-11-26 08:12:48 -05:00
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
2015-10-19 10:41:43 -04:00
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
2013-11-26 08:12:48 -05:00
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
|
|
class Repair extends Command {
|
2022-04-12 11:55:01 -04:00
|
|
|
protected \OC\Repair $repair;
|
|
|
|
|
protected IConfig $config;
|
2022-08-22 11:59:26 -04:00
|
|
|
private IEventDispatcher $dispatcher;
|
2022-04-12 11:55:01 -04:00
|
|
|
private ProgressBar $progress;
|
|
|
|
|
private OutputInterface $output;
|
|
|
|
|
private IAppManager $appManager;
|
2023-02-20 08:33:06 -05:00
|
|
|
protected bool $errored = false;
|
2013-11-26 08:12:48 -05:00
|
|
|
|
2022-08-22 11:59:26 -04:00
|
|
|
public function __construct(\OC\Repair $repair, IConfig $config, IEventDispatcher $dispatcher, IAppManager $appManager) {
|
2013-11-26 08:12:48 -05:00
|
|
|
$this->repair = $repair;
|
2014-06-10 05:47:27 -04:00
|
|
|
$this->config = $config;
|
2016-04-26 10:24:50 -04:00
|
|
|
$this->dispatcher = $dispatcher;
|
2017-10-24 08:13:45 -04:00
|
|
|
$this->appManager = $appManager;
|
2013-11-26 08:12:48 -05:00
|
|
|
parent::__construct();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function configure() {
|
|
|
|
|
$this
|
|
|
|
|
->setName('maintenance:repair')
|
2015-10-19 10:41:43 -04:00
|
|
|
->setDescription('repair this installation')
|
|
|
|
|
->addOption(
|
|
|
|
|
'include-expensive',
|
|
|
|
|
null,
|
|
|
|
|
InputOption::VALUE_NONE,
|
2016-04-19 09:36:11 -04:00
|
|
|
'Use this option when you want to include resource and load expensive tasks');
|
2013-11-26 08:12:48 -05:00
|
|
|
}
|
|
|
|
|
|
2020-06-26 08:54:51 -04:00
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int {
|
2019-02-02 12:07:48 -05:00
|
|
|
$repairSteps = $this->repair::getRepairSteps();
|
|
|
|
|
|
|
|
|
|
if ($input->getOption('include-expensive')) {
|
|
|
|
|
$repairSteps = array_merge($repairSteps, $this->repair::getExpensiveRepairSteps());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($repairSteps as $step) {
|
|
|
|
|
$this->repair->addStep($step);
|
2015-10-19 10:41:43 -04:00
|
|
|
}
|
|
|
|
|
|
2017-10-24 08:13:45 -04:00
|
|
|
$apps = $this->appManager->getInstalledApps();
|
2016-04-19 09:36:11 -04:00
|
|
|
foreach ($apps as $app) {
|
2017-12-18 14:26:44 -05:00
|
|
|
if (!$this->appManager->isEnabledForUser($app)) {
|
2016-04-19 09:36:11 -04:00
|
|
|
continue;
|
|
|
|
|
}
|
2022-05-12 11:08:54 -04:00
|
|
|
$info = $this->appManager->getAppInfo($app);
|
2016-04-19 09:36:11 -04:00
|
|
|
if (!is_array($info)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2019-04-18 08:28:00 -04:00
|
|
|
\OC_App::loadApp($app);
|
2016-04-19 09:36:11 -04:00
|
|
|
$steps = $info['repair-steps']['post-migration'];
|
|
|
|
|
foreach ($steps as $step) {
|
|
|
|
|
try {
|
|
|
|
|
$this->repair->addStep($step);
|
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
|
$output->writeln("<error>Failed to load repair step for $app: {$ex->getMessage()}</error>");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 08:33:06 -05:00
|
|
|
|
|
|
|
|
|
2019-02-06 11:08:41 -05:00
|
|
|
$maintenanceMode = $this->config->getSystemValueBool('maintenance');
|
2014-11-18 18:25:26 -05:00
|
|
|
$this->config->setSystemValue('maintenance', true);
|
2014-03-25 07:51:16 -04:00
|
|
|
|
2016-04-26 10:24:50 -04:00
|
|
|
$this->progress = new ProgressBar($output);
|
|
|
|
|
$this->output = $output;
|
2022-08-22 11:59:26 -04:00
|
|
|
$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']);
|
2014-03-25 07:51:16 -04:00
|
|
|
|
2013-11-26 08:12:48 -05:00
|
|
|
$this->repair->run();
|
2014-03-25 07:51:16 -04:00
|
|
|
|
2014-11-18 18:25:26 -05:00
|
|
|
$this->config->setSystemValue('maintenance', $maintenanceMode);
|
2023-02-20 08:33:06 -05:00
|
|
|
return $this->errored ? 1 : 0;
|
2013-11-26 08:12:48 -05:00
|
|
|
}
|
2016-04-26 10:24:50 -04:00
|
|
|
|
2022-08-22 11:59:26 -04:00
|
|
|
public function handleRepairFeedBack(Event $event): void {
|
|
|
|
|
if ($event instanceof RepairStartEvent) {
|
|
|
|
|
$this->progress->start($event->getMaxStep());
|
|
|
|
|
} elseif ($event instanceof RepairAdvanceEvent) {
|
2022-08-25 10:26:31 -04:00
|
|
|
$this->progress->advance($event->getIncrement());
|
2022-08-22 11:59:26 -04:00
|
|
|
} elseif ($event instanceof RepairFinishEvent) {
|
|
|
|
|
$this->progress->finish();
|
|
|
|
|
$this->output->writeln('');
|
|
|
|
|
} elseif ($event instanceof RepairStepEvent) {
|
2022-08-25 10:18:53 -04:00
|
|
|
$this->output->writeln('<info> - ' . $event->getStepName() . '</info>');
|
2022-08-22 11:59:26 -04:00
|
|
|
} elseif ($event instanceof RepairInfoEvent) {
|
2022-08-25 10:18:53 -04:00
|
|
|
$this->output->writeln('<info> - ' . $event->getMessage() . '</info>');
|
2022-08-22 11:59:26 -04:00
|
|
|
} elseif ($event instanceof RepairWarningEvent) {
|
2023-01-20 03:58:22 -05:00
|
|
|
$this->output->writeln('<comment> - WARNING: ' . $event->getMessage() . '</comment>');
|
2022-08-22 11:59:26 -04:00
|
|
|
} elseif ($event instanceof RepairErrorEvent) {
|
|
|
|
|
$this->output->writeln('<error> - ERROR: ' . $event->getMessage() . '</error>');
|
2023-02-20 08:33:06 -05:00
|
|
|
$this->errored = true;
|
2016-04-26 10:24:50 -04:00
|
|
|
}
|
|
|
|
|
}
|
2013-11-26 08:12:48 -05:00
|
|
|
}
|