Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dont error the entire repair process when a repair step errors #25112

Merged
merged 3 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/Command/Maintenance/Repair.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function handleRepairFeedBack($event) {
$this->output->writeln(' - WARNING: ' . $event->getArgument(0));
break;
case '\OC\Repair::error':
$this->output->writeln(' - ERROR: ' . $event->getArgument(0));
$this->output->writeln('<error> - ERROR: ' . $event->getArgument(0) . '</error>');
break;
}
}
Expand Down
4 changes: 3 additions & 1 deletion core/register_command.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@

/** @var Symfony\Component\Console\Application $application */

use Psr\Log\LoggerInterface;

$application->add(new \Stecman\Component\Symfony\Console\BashCompletion\CompletionCommand());
$application->add(new OC\Core\Command\Status);
$application->add(new OC\Core\Command\Check(\OC::$server->getSystemConfig()));
Expand Down Expand Up @@ -161,7 +163,7 @@

$application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->query(\OC\Installer::class)));
$application->add(new OC\Core\Command\Maintenance\Repair(
new \OC\Repair([], \OC::$server->getEventDispatcher()),
new \OC\Repair([], \OC::$server->getEventDispatcher(), \OC::$server->get(LoggerInterface::class)),
\OC::$server->getConfig(),
\OC::$server->getEventDispatcher(),
\OC::$server->getAppManager()
Expand Down
3 changes: 2 additions & 1 deletion lib/private/Migration/BackgroundRepair.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use OC_App;
use OCP\BackgroundJob\IJobList;
use OCP\ILogger;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
Expand Down Expand Up @@ -92,7 +93,7 @@ protected function run($argument) {
}

$step = $argument['step'];
$repair = new Repair([], $this->dispatcher);
$repair = new Repair([], $this->dispatcher, \OC::$server->get(LoggerInterface::class));
try {
$repair->addStep($step);
} catch (\Exception $ex) {
Expand Down
13 changes: 11 additions & 2 deletions lib/private/Repair.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
use OCP\Collaboration\Resources\IManager;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;

Expand All @@ -90,15 +91,18 @@ class Repair implements IOutput {
/** @var string */
private $currentStep;

private $logger;

/**
* Creates a new repair step runner
*
* @param IRepairStep[] $repairSteps array of RepairStep instances
* @param EventDispatcherInterface $dispatcher
*/
public function __construct(array $repairSteps, EventDispatcherInterface $dispatcher) {
public function __construct(array $repairSteps, EventDispatcherInterface $dispatcher, LoggerInterface $logger) {
$this->repairSteps = $repairSteps;
$this->dispatcher = $dispatcher;
$this->logger = $logger;
}

/**
Expand All @@ -114,7 +118,12 @@ public function run() {
foreach ($this->repairSteps as $step) {
$this->currentStep = $step->getName();
$this->emit('\OC\Repair', 'step', [$this->currentStep]);
$step->run($this);
try {
$step->run($this);
} catch (\Exception $e) {
$this->logger->error("Exception while executing repair step " . $step->getName(), ['exception' => $e]);
$this->emit('\OC\Repair', 'error', [$e->getMessage()]);
icewind1991 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions lib/private/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
use OCP\IConfig;
use OCP\ILogger;
use OCP\Util;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\GenericEvent;

/**
Expand Down Expand Up @@ -243,7 +244,7 @@ private function doUpgrade($currentVersion, $installedVersion) {
file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', '');

// pre-upgrade repairs
$repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher());
$repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher(), \OC::$server->get(LoggerInterface::class));
$repair->run();

$this->doCoreUpgrade();
Expand Down Expand Up @@ -276,7 +277,7 @@ private function doUpgrade($currentVersion, $installedVersion) {
}

// post-upgrade repairs
$repair = new Repair(Repair::getRepairSteps(), \OC::$server->getEventDispatcher());
$repair = new Repair(Repair::getRepairSteps(), \OC::$server->getEventDispatcher(), \OC::$server->get(LoggerInterface::class));
$repair->run();

//Invalidate update feed
Expand Down
3 changes: 2 additions & 1 deletion lib/private/legacy/OC_App.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
use OCP\AppFramework\QueryException;
use OCP\Authentication\IAlternativeLogin;
use OCP\ILogger;
use Psr\Log\LoggerInterface;

/**
* This class manages the apps. It allows them to register and integrate in the
Expand Down Expand Up @@ -1041,7 +1042,7 @@ public static function executeRepairSteps(string $appId, array $steps) {
$dispatcher = OC::$server->getEventDispatcher();

// load the steps
$r = new Repair([], $dispatcher);
$r = new Repair([], $dispatcher, \OC::$server->get(LoggerInterface::class));
foreach ($steps as $step) {
try {
$r->addStep($step);
Expand Down
3 changes: 2 additions & 1 deletion tests/lib/RepairStepTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace Test;

use OCP\Migration\IRepairStep;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;

class RepairStepTest implements IRepairStep {
Expand Down Expand Up @@ -41,7 +42,7 @@ class RepairTest extends TestCase {
protected function setUp(): void {
parent::setUp();
$dispatcher = new EventDispatcher();
$this->repair = new \OC\Repair([], $dispatcher);
$this->repair = new \OC\Repair([], $dispatcher, $this->createMock(LoggerInterface::class));

$dispatcher->addListener('\OC\Repair::warning', function ($event) {
/** @var \Symfony\Component\EventDispatcher\GenericEvent $event */
Expand Down