]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add support for repair step classes
authorVincent Petry <pvince81@owncloud.com>
Tue, 25 Mar 2014 11:51:16 +0000 (12:51 +0100)
committerVincent Petry <pvince81@owncloud.com>
Thu, 12 Jun 2014 15:38:26 +0000 (17:38 +0200)
This also makes it possible to unit test each repair step class
individually

core/command/maintenance/repair.php
lib/private/repair.php

index 310c01fbe2a36da13dcfbe075bfd2c87e02219a7..43ae6479eb035932c827a1b770108363bf6a9929 100644 (file)
@@ -33,9 +33,22 @@ class Repair extends Command {
        }
 
        protected function execute(InputInterface $input, OutputInterface $output) {
+               \OC_DB::enableCaching(false);
+               $maintenanceMode = \OC_Config::getValue('maintenance', false);
+               \OC_Config::setValue('maintenance', true);
+
                $this->repair->listen('\OC\Repair', 'step', function ($description) use ($output) {
                        $output->writeln(' - ' . $description);
                });
+               $this->repair->listen('\OC\Repair', 'info', function ($description) use ($output) {
+                       $output->writeln('     - ' . $description);
+               });
+               $this->repair->listen('\OC\Repair', 'error', function ($description) use ($output) {
+                       $output->writeln('     - ERROR: ' . $description);
+               });
+
                $this->repair->run();
+
+               \OC_Config::setValue('maintenance', $maintenanceMode);
        }
 }
index e9de3baa7ce94b54f7c348efde5e458adc3e8a4f..4a155c403a62c6edfdc9e40f5d62f90fba5841e1 100644 (file)
@@ -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;
        }
+
 }