Remove emitter from class Repair
This commit is contained in:
parent
cdcd49b473
commit
bbd2a07525
|
@ -28,7 +28,6 @@
|
||||||
|
|
||||||
namespace OC;
|
namespace OC;
|
||||||
|
|
||||||
use OC\Hooks\BasicEmitter;
|
|
||||||
use OC\Hooks\Emitter;
|
use OC\Hooks\Emitter;
|
||||||
use OC\Repair\AssetCache;
|
use OC\Repair\AssetCache;
|
||||||
use OC\Repair\CleanTags;
|
use OC\Repair\CleanTags;
|
||||||
|
@ -51,7 +50,7 @@ use OCP\Migration\IRepairStep;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||||
use Symfony\Component\EventDispatcher\GenericEvent;
|
use Symfony\Component\EventDispatcher\GenericEvent;
|
||||||
|
|
||||||
class Repair extends BasicEmitter implements IOutput{
|
class Repair implements IOutput{
|
||||||
/* @var IRepairStep[] */
|
/* @var IRepairStep[] */
|
||||||
private $repairSteps;
|
private $repairSteps;
|
||||||
/** @var EventDispatcher */
|
/** @var EventDispatcher */
|
||||||
|
@ -178,10 +177,11 @@ class Repair extends BasicEmitter implements IOutput{
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* @param string $scope
|
||||||
|
* @param string $method
|
||||||
|
* @param array $arguments
|
||||||
*/
|
*/
|
||||||
public function emit($scope, $method, array $arguments = []) {
|
public function emit($scope, $method, array $arguments = []) {
|
||||||
parent::emit($scope, $method, $arguments);
|
|
||||||
if (!is_null($this->dispatcher)) {
|
if (!is_null($this->dispatcher)) {
|
||||||
$this->dispatcher->dispatch("$scope::$method",
|
$this->dispatcher->dispatch("$scope::$method",
|
||||||
new GenericEvent("$scope::$method", $arguments));
|
new GenericEvent("$scope::$method", $arguments));
|
||||||
|
|
|
@ -132,6 +132,8 @@ class Updater extends BasicEmitter {
|
||||||
* @return bool true if the operation succeeded, false otherwise
|
* @return bool true if the operation succeeded, false otherwise
|
||||||
*/
|
*/
|
||||||
public function upgrade() {
|
public function upgrade() {
|
||||||
|
$this->emitRepairEvents();
|
||||||
|
|
||||||
$logLevel = $this->config->getSystemValue('loglevel', \OCP\Util::WARN);
|
$logLevel = $this->config->getSystemValue('loglevel', \OCP\Util::WARN);
|
||||||
$this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]);
|
$this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]);
|
||||||
$this->config->setSystemValue('loglevel', \OCP\Util::DEBUG);
|
$this->config->setSystemValue('loglevel', \OCP\Util::DEBUG);
|
||||||
|
@ -195,26 +197,6 @@ class Updater extends BasicEmitter {
|
||||||
&& (version_compare($oldVersion, $newVersion, '<=') || $this->config->getSystemValue('debug', false)));
|
&& (version_compare($oldVersion, $newVersion, '<=') || $this->config->getSystemValue('debug', false)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Forward messages emitted by the repair routine
|
|
||||||
*
|
|
||||||
* @param Repair $repair repair routine
|
|
||||||
*/
|
|
||||||
private function emitRepairMessages(Repair $repair) {
|
|
||||||
$repair->listen('\OC\Repair', 'warning', function ($description) {
|
|
||||||
$this->emit('\OC\Updater', 'repairWarning', array($description));
|
|
||||||
});
|
|
||||||
$repair->listen('\OC\Repair', 'error', function ($description) {
|
|
||||||
$this->emit('\OC\Updater', 'repairError', array($description));
|
|
||||||
});
|
|
||||||
$repair->listen('\OC\Repair', 'info', function ($description) {
|
|
||||||
$this->emit('\OC\Updater', 'repairInfo', array($description));
|
|
||||||
});
|
|
||||||
$repair->listen('\OC\Repair', 'step', function ($description) {
|
|
||||||
$this->emit('\OC\Updater', 'repairStep', array($description));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* runs the update actions in maintenance mode, does not upgrade the source files
|
* runs the update actions in maintenance mode, does not upgrade the source files
|
||||||
* except the main .htaccess file
|
* except the main .htaccess file
|
||||||
|
@ -245,8 +227,7 @@ class Updater extends BasicEmitter {
|
||||||
file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', '');
|
file_put_contents($this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', '');
|
||||||
|
|
||||||
// pre-upgrade repairs
|
// pre-upgrade repairs
|
||||||
$repair = new Repair(Repair::getBeforeUpgradeRepairSteps());
|
$repair = new Repair(Repair::getBeforeUpgradeRepairSteps(), \OC::$server->getEventDispatcher());
|
||||||
$this->emitRepairMessages($repair);
|
|
||||||
$repair->run();
|
$repair->run();
|
||||||
|
|
||||||
// simulate DB upgrade
|
// simulate DB upgrade
|
||||||
|
@ -278,8 +259,7 @@ class Updater extends BasicEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
// post-upgrade repairs
|
// post-upgrade repairs
|
||||||
$repair = new Repair(Repair::getRepairSteps());
|
$repair = new Repair(Repair::getRepairSteps(), \OC::$server->getEventDispatcher());
|
||||||
$this->emitRepairMessages($repair);
|
|
||||||
$repair->run();
|
$repair->run();
|
||||||
|
|
||||||
//Invalidate update feed
|
//Invalidate update feed
|
||||||
|
@ -362,7 +342,6 @@ class Updater extends BasicEmitter {
|
||||||
* @throws NeedsUpdateException
|
* @throws NeedsUpdateException
|
||||||
*/
|
*/
|
||||||
protected function doAppUpgrade() {
|
protected function doAppUpgrade() {
|
||||||
$this->emitRepairEvents();
|
|
||||||
$apps = \OC_App::getEnabledApps();
|
$apps = \OC_App::getEnabledApps();
|
||||||
$priorityTypes = array('authentication', 'filesystem', 'logging');
|
$priorityTypes = array('authentication', 'filesystem', 'logging');
|
||||||
$pseudoOtherType = 'other';
|
$pseudoOtherType = 'other';
|
||||||
|
|
|
@ -0,0 +1,134 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com>
|
||||||
|
* This file is licensed under the Affero General Public License version 3 or
|
||||||
|
* later.
|
||||||
|
* See the COPYING-README file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Test;
|
||||||
|
|
||||||
|
use OCP\Migration\IRepairStep;
|
||||||
|
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||||
|
|
||||||
|
class TestRepairStep implements IRepairStep {
|
||||||
|
private $warning;
|
||||||
|
|
||||||
|
public function __construct($warning = false) {
|
||||||
|
$this->warning = $warning;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName() {
|
||||||
|
return 'Test Name';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function run(\OCP\Migration\IOutput $out) {
|
||||||
|
if ($this->warning) {
|
||||||
|
$out->warning('Simulated warning');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$out->info('Simulated info');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class RepairTest extends TestCase {
|
||||||
|
/** @var \OC\Repair */
|
||||||
|
private $repair;
|
||||||
|
|
||||||
|
/** @var string[] */
|
||||||
|
private $outputArray;
|
||||||
|
|
||||||
|
public function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
$dispatcher = new EventDispatcher();
|
||||||
|
$this->repair = new \OC\Repair([], $dispatcher);
|
||||||
|
|
||||||
|
$dispatcher->addListener('\OC\Repair::warning', function ($event) {
|
||||||
|
/** @var \Symfony\Component\EventDispatcher\GenericEvent $event */
|
||||||
|
$this->outputArray[] = 'warning: ' . $event->getArgument(0);
|
||||||
|
});
|
||||||
|
$dispatcher->addListener('\OC\Repair::info', function ($event) {
|
||||||
|
/** @var \Symfony\Component\EventDispatcher\GenericEvent $event */
|
||||||
|
$this->outputArray[] = 'info: ' . $event->getArgument(0);
|
||||||
|
});
|
||||||
|
$dispatcher->addListener('\OC\Repair::step', function ($event) {
|
||||||
|
/** @var \Symfony\Component\EventDispatcher\GenericEvent $event */
|
||||||
|
$this->outputArray[] = 'step: ' . $event->getArgument(0);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRunRepairStep() {
|
||||||
|
|
||||||
|
$this->repair->addStep(new TestRepairStep(false));
|
||||||
|
$this->repair->run();
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
array(
|
||||||
|
'step: Test Name',
|
||||||
|
'info: Simulated info',
|
||||||
|
),
|
||||||
|
$this->outputArray
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRunRepairStepThatFail() {
|
||||||
|
|
||||||
|
$this->repair->addStep(new TestRepairStep(true));
|
||||||
|
$this->repair->run();
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
array(
|
||||||
|
'step: Test Name',
|
||||||
|
'warning: Simulated warning',
|
||||||
|
),
|
||||||
|
$this->outputArray
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRunRepairStepsWithException() {
|
||||||
|
$mock = $this->getMock('\Test\TestRepairStep');
|
||||||
|
$mock->expects($this->any())
|
||||||
|
->method('run')
|
||||||
|
->will($this->throwException(new \Exception()));
|
||||||
|
$mock->expects($this->any())
|
||||||
|
->method('getName')
|
||||||
|
->will($this->returnValue('Exception Test'));
|
||||||
|
|
||||||
|
$this->repair->addStep($mock);
|
||||||
|
$this->repair->addStep(new TestRepairStep(false));
|
||||||
|
|
||||||
|
$thrown = false;
|
||||||
|
try {
|
||||||
|
$this->repair->run();
|
||||||
|
}
|
||||||
|
catch (\Exception $e) {
|
||||||
|
$thrown = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertTrue($thrown);
|
||||||
|
// jump out after exception
|
||||||
|
$this->assertEquals(
|
||||||
|
array(
|
||||||
|
'step: Exception Test',
|
||||||
|
),
|
||||||
|
$this->outputArray
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRunRepairStepsContinueAfterWarning() {
|
||||||
|
$this->repair->addStep(new TestRepairStep(true));
|
||||||
|
$this->repair->addStep(new TestRepairStep(false));
|
||||||
|
$this->repair->run();
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
array(
|
||||||
|
'step: Test Name',
|
||||||
|
'warning: Simulated warning',
|
||||||
|
'step: Test Name',
|
||||||
|
'info: Simulated info',
|
||||||
|
),
|
||||||
|
$this->outputArray
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,159 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com>
|
|
||||||
* This file is licensed under the Affero General Public License version 3 or
|
|
||||||
* later.
|
|
||||||
* See the COPYING-README file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
use OCP\Migration\IRepairStep;
|
|
||||||
|
|
||||||
class TestRepairStep implements IRepairStep {
|
|
||||||
private $warning;
|
|
||||||
|
|
||||||
public function __construct($warning = false) {
|
|
||||||
$this->warning = $warning;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getName() {
|
|
||||||
return 'Test Name';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function run(\OCP\Migration\IOutput $out) {
|
|
||||||
if ($this->warning) {
|
|
||||||
$out->warning('Simulated warning');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$out->info('Simulated info');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Test_Repair extends \Test\TestCase {
|
|
||||||
public function testRunRepairStep() {
|
|
||||||
$output = array();
|
|
||||||
|
|
||||||
$repair = new \OC\Repair();
|
|
||||||
$repair->addStep(new TestRepairStep(false));
|
|
||||||
|
|
||||||
$repair->listen('\OC\Repair', 'warning', function ($description) use (&$output) {
|
|
||||||
$output[] = 'warning: ' . $description;
|
|
||||||
});
|
|
||||||
$repair->listen('\OC\Repair', 'info', function ($description) use (&$output) {
|
|
||||||
$output[] = 'info: ' . $description;
|
|
||||||
});
|
|
||||||
$repair->listen('\OC\Repair', 'step', function ($description) use (&$output) {
|
|
||||||
$output[] = 'step: ' . $description;
|
|
||||||
});
|
|
||||||
|
|
||||||
$repair->run();
|
|
||||||
|
|
||||||
$this->assertEquals(
|
|
||||||
array(
|
|
||||||
'step: Test Name',
|
|
||||||
'info: Simulated info',
|
|
||||||
),
|
|
||||||
$output
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testRunRepairStepThatFail() {
|
|
||||||
$output = array();
|
|
||||||
|
|
||||||
$repair = new \OC\Repair();
|
|
||||||
$repair->addStep(new TestRepairStep(true));
|
|
||||||
|
|
||||||
$repair->listen('\OC\Repair', 'warning', function ($description) use (&$output) {
|
|
||||||
$output[] = 'warning: ' . $description;
|
|
||||||
});
|
|
||||||
$repair->listen('\OC\Repair', 'info', function ($description) use (&$output) {
|
|
||||||
$output[] = 'info: ' . $description;
|
|
||||||
});
|
|
||||||
$repair->listen('\OC\Repair', 'step', function ($description) use (&$output) {
|
|
||||||
$output[] = 'step: ' . $description;
|
|
||||||
});
|
|
||||||
|
|
||||||
$repair->run();
|
|
||||||
|
|
||||||
$this->assertEquals(
|
|
||||||
array(
|
|
||||||
'step: Test Name',
|
|
||||||
'warning: Simulated warning',
|
|
||||||
),
|
|
||||||
$output
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testRunRepairStepsWithException() {
|
|
||||||
$output = array();
|
|
||||||
|
|
||||||
$mock = $this->getMock('TestRepairStep');
|
|
||||||
$mock->expects($this->any())
|
|
||||||
->method('run')
|
|
||||||
->will($this->throwException(new Exception));
|
|
||||||
$mock->expects($this->any())
|
|
||||||
->method('getName')
|
|
||||||
->will($this->returnValue('Exception Test'));
|
|
||||||
|
|
||||||
$repair = new \OC\Repair();
|
|
||||||
$repair->addStep($mock);
|
|
||||||
$repair->addStep(new TestRepairStep(false));
|
|
||||||
|
|
||||||
$repair->listen('\OC\Repair', 'warning', function ($description) use (&$output) {
|
|
||||||
$output[] = 'warning: ' . $description;
|
|
||||||
});
|
|
||||||
$repair->listen('\OC\Repair', 'info', function ($description) use (&$output) {
|
|
||||||
$output[] = 'info: ' . $description;
|
|
||||||
});
|
|
||||||
$repair->listen('\OC\Repair', 'step', function ($description) use (&$output) {
|
|
||||||
$output[] = 'step: ' . $description;
|
|
||||||
});
|
|
||||||
|
|
||||||
$thrown = false;
|
|
||||||
try {
|
|
||||||
$repair->run();
|
|
||||||
}
|
|
||||||
catch (Exception $e) {
|
|
||||||
$thrown = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->assertTrue($thrown);
|
|
||||||
// jump out after exception
|
|
||||||
$this->assertEquals(
|
|
||||||
array(
|
|
||||||
'step: Exception Test',
|
|
||||||
),
|
|
||||||
$output
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testRunRepairStepsContinueAfterWarning() {
|
|
||||||
$output = array();
|
|
||||||
|
|
||||||
$repair = new \OC\Repair();
|
|
||||||
$repair->addStep(new TestRepairStep(true));
|
|
||||||
$repair->addStep(new TestRepairStep(false));
|
|
||||||
|
|
||||||
$repair->listen('\OC\Repair', 'warning', function ($description) use (&$output) {
|
|
||||||
$output[] = 'warning: ' . $description;
|
|
||||||
});
|
|
||||||
$repair->listen('\OC\Repair', 'info', function ($description) use (&$output) {
|
|
||||||
$output[] = 'info: ' . $description;
|
|
||||||
});
|
|
||||||
$repair->listen('\OC\Repair', 'step', function ($description) use (&$output) {
|
|
||||||
$output[] = 'step: ' . $description;
|
|
||||||
});
|
|
||||||
|
|
||||||
$repair->run();
|
|
||||||
|
|
||||||
$this->assertEquals(
|
|
||||||
array(
|
|
||||||
'step: Test Name',
|
|
||||||
'warning: Simulated warning',
|
|
||||||
'step: Test Name',
|
|
||||||
'info: Simulated info',
|
|
||||||
),
|
|
||||||
$output
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue