diff options
author | Vincent Petry <pvince81@owncloud.com> | 2014-03-25 15:51:16 +0400 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2014-06-12 19:38:26 +0400 |
commit | 6fcd1af4db2d1bf8d61fa0c627c308e7257294b9 (patch) | |
tree | 3ec301f0ed7ca4697673d3de9cbfc7719b4e32d2 /lib/private/repair.php | |
parent | ab7cff6dfd63213746a29f4c0557e92a84561498 (diff) |
Add support for repair step classes
This also makes it possible to unit test each repair step class
individually
Diffstat (limited to 'lib/private/repair.php')
-rw-r--r-- | lib/private/repair.php | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/lib/private/repair.php b/lib/private/repair.php index e9de3baa7ce..4a155c403a6 100644 --- a/lib/private/repair.php +++ b/lib/private/repair.php @@ -11,11 +11,51 @@ namespace OC; use OC\Hooks\BasicEmitter; class Repair extends BasicEmitter { + private $stepClasses; + /** - * run a series of repair steps for common problems - * progress can be reported by emitting \OC\Repair::step events + * Creates a new repair step runner + * + * @param array $stepClasses optional list of step classes + */ + public function __construct($stepClasses = array()) { + $this->stepClasses = $stepClasses; + } + + /** + * Run a series of repair steps for common problems */ public function run() { - $this->emit('\OC\Repair', 'step', array('No repair steps configured at the moment')); + $steps = array(); + + // instantiate all classes, just to make + // sure they all exist before starting + foreach ($this->stepClasses as $className) { + $steps[] = new $className(); + } + + $self = $this; + // run each repair step + foreach ($steps as $step) { + $this->emit('\OC\Repair', 'step', array($step->getName())); + + $step->listen('\OC\Repair', 'error', function ($description) use ($self) { + $self->emit('\OC\Repair', 'error', array($description)); + }); + $step->listen('\OC\Repair', 'info', function ($description) use ($self) { + $self->emit('\OC\Repair', 'info', array($description)); + }); + $step->run(); + } + } + + /** + * Add repair step class + * + * @param string $className name of a repair step class + */ + public function addStep($className) { + $this->stepClasses[] = $className; } + } |