2013-11-26 17:12:48 +04:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OC;
|
|
|
|
|
|
|
|
use OC\Hooks\BasicEmitter;
|
|
|
|
|
|
|
|
class Repair extends BasicEmitter {
|
2014-03-25 15:51:16 +04:00
|
|
|
private $stepClasses;
|
|
|
|
|
2013-11-26 17:12:48 +04:00
|
|
|
/**
|
2014-03-25 15:51:16 +04:00
|
|
|
* 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
|
2013-11-26 17:12:48 +04:00
|
|
|
*/
|
|
|
|
public function run() {
|
2014-03-25 15:51:16 +04:00
|
|
|
$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;
|
2013-11-26 17:12:48 +04:00
|
|
|
}
|
2014-03-25 15:51:16 +04:00
|
|
|
|
2013-11-26 17:12:48 +04:00
|
|
|
}
|