Skip to content

Commit

Permalink
log full expection during repair step
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <robin@icewind.nl>
  • Loading branch information
icewind1991 authored and MorrisJobke committed Mar 18, 2021
1 parent 9135a42 commit 9e37756
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
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
7 changes: 6 additions & 1 deletion 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 @@ -117,6 +121,7 @@ public function run() {
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()]);
}
}
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

0 comments on commit 9e37756

Please sign in to comment.