aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/repair.php
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-06-10 11:47:27 +0200
committerVincent Petry <pvince81@owncloud.com>2014-06-12 17:38:26 +0200
commitca690c4d02d6c59e3fb9edb0f75ae640d744b612 (patch)
tree110d83d8c96d0b781155b42a6d9eead576fab6e7 /lib/private/repair.php
parent6fcd1af4db2d1bf8d61fa0c627c308e7257294b9 (diff)
downloadnextcloud-server-ca690c4d02d6c59e3fb9edb0f75ae640d744b612.tar.gz
nextcloud-server-ca690c4d02d6c59e3fb9edb0f75ae640d744b612.zip
Added RepairStep interface and default repair step lists
The updater is using "before update" repair steps and "regular" repair steps. The "regular" repair steps are also used by the CLI tool. Currently no steps exist but can be added later in the static methods in the \OC\Repair class. Added unit test to test messaging, error and exception cases.
Diffstat (limited to 'lib/private/repair.php')
-rw-r--r--lib/private/repair.php67
1 files changed, 44 insertions, 23 deletions
diff --git a/lib/private/repair.php b/lib/private/repair.php
index 4a155c403a6..8979d04808b 100644
--- a/lib/private/repair.php
+++ b/lib/private/repair.php
@@ -11,51 +11,72 @@ namespace OC;
use OC\Hooks\BasicEmitter;
class Repair extends BasicEmitter {
- private $stepClasses;
+ /**
+ * @var array
+ **/
+ private $repairSteps;
/**
* Creates a new repair step runner
*
- * @param array $stepClasses optional list of step classes
+ * @param array $repairSteps array of RepairStep instances
*/
- public function __construct($stepClasses = array()) {
- $this->stepClasses = $stepClasses;
+ public function __construct($repairSteps = array()) {
+ $this->repairSteps = $repairSteps;
}
/**
* Run a series of repair steps for common problems
*/
public function run() {
- $steps = array();
-
- // instantiate all classes, just to make
- // sure they all exist before starting
- foreach ($this->stepClasses as $className) {
- $steps[] = new $className();
- }
-
$self = $this;
+ if (count($this->repairSteps) === 0) {
+ $this->emit('\OC\Repair', 'info', array('No repair steps available'));
+ return;
+ }
// run each repair step
- foreach ($steps as $step) {
+ foreach ($this->repairSteps 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));
- });
+ if ($step instanceof BasicEmitter) {
+ $step->listen('\OC\Repair', 'warning', function ($description) use ($self) {
+ $self->emit('\OC\Repair', 'warning', array($description));
+ });
+ $step->listen('\OC\Repair', 'info', function ($description) use ($self) {
+ $self->emit('\OC\Repair', 'info', array($description));
+ });
+ }
+
$step->run();
}
}
/**
- * Add repair step class
+ * Add repair step
*
- * @param string $className name of a repair step class
+ * @param RepairStep $repairStep repair step
*/
- public function addStep($className) {
- $this->stepClasses[] = $className;
+ public function addStep($repairStep) {
+ $this->repairSteps[] = $repairStep;
}
+ /**
+ * Returns the default repair steps to be run on the
+ * command line or after an upgrade.
+ *
+ * @return array of RepairStep instances
+ */
+ public static function getRepairSteps() {
+ return array();
+ }
+
+ /**
+ * Returns the repair steps to be run before an
+ * upgrade.
+ *
+ * @return array of RepairStep instances
+ */
+ public static function getBeforeUpgradeRepairSteps() {
+ return array();
+ }
}