diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-04-26 16:24:50 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-04-28 13:52:01 +0200 |
commit | cdcd49b473dc7bad4ffb500977b2b8ea5d6f676e (patch) | |
tree | 3ea910a2853ecff486e922c4f16c4c90a923badf /core | |
parent | ba0099f73abc133cfc88ad2d7a25b86677d1c111 (diff) | |
download | nextcloud-server-cdcd49b473dc7bad4ffb500977b2b8ea5d6f676e.tar.gz nextcloud-server-cdcd49b473dc7bad4ffb500977b2b8ea5d6f676e.zip |
Adding progress to occ maintenance:repair
Diffstat (limited to 'core')
-rw-r--r-- | core/Command/Maintenance/Repair.php | 69 | ||||
-rw-r--r-- | core/register_command.php | 4 |
2 files changed, 57 insertions, 16 deletions
diff --git a/core/Command/Maintenance/Repair.php b/core/Command/Maintenance/Repair.php index 2da76143390..286df5fd7bb 100644 --- a/core/Command/Maintenance/Repair.php +++ b/core/Command/Maintenance/Repair.php @@ -25,24 +25,36 @@ namespace OC\Core\Command\Maintenance; use Exception; +use OCP\IConfig; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\GenericEvent; class Repair extends Command { /** @var \OC\Repair $repair */ protected $repair; - /** @var \OCP\IConfig */ + /** @var IConfig */ protected $config; + /** @var EventDispatcherInterface */ + private $dispatcher; + /** @var ProgressBar */ + private $progress; + /** @var OutputInterface */ + private $output; /** * @param \OC\Repair $repair - * @param \OCP\IConfig $config + * @param IConfig $config */ - public function __construct(\OC\Repair $repair, \OCP\IConfig $config) { + public function __construct(\OC\Repair $repair, IConfig $config, EventDispatcherInterface $dispatcher) { $this->repair = $repair; $this->config = $config; + $this->dispatcher = $dispatcher; parent::__construct(); } @@ -87,21 +99,48 @@ class Repair extends Command { $maintenanceMode = $this->config->getSystemValue('maintenance', false); $this->config->setSystemValue('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', 'warning', function ($description) use ($output) { - $output->writeln(' - WARNING: ' . $description); - }); - $this->repair->listen('\OC\Repair', 'error', function ($description) use ($output) { - $output->writeln(' - ERROR: ' . $description); - }); + $this->progress = new ProgressBar($output); + $this->output = $output; + $this->dispatcher->addListener('\OC\Repair::startProgress', [$this, 'handleRepairFeedBack']); + $this->dispatcher->addListener('\OC\Repair::advance', [$this, 'handleRepairFeedBack']); + $this->dispatcher->addListener('\OC\Repair::finishProgress', [$this, 'handleRepairFeedBack']); + $this->dispatcher->addListener('\OC\Repair::step', [$this, 'handleRepairFeedBack']); + $this->dispatcher->addListener('\OC\Repair::info', [$this, 'handleRepairFeedBack']); + $this->dispatcher->addListener('\OC\Repair::warning', [$this, 'handleRepairFeedBack']); + $this->dispatcher->addListener('\OC\Repair::error', [$this, 'handleRepairFeedBack']); $this->repair->run(); $this->config->setSystemValue('maintenance', $maintenanceMode); } + + public function handleRepairFeedBack($event) { + if (!$event instanceof GenericEvent) { + return; + } + switch ($event->getSubject()) { + case '\OC\Repair::startProgress': + $this->progress->start($event->getArgument(0)); + break; + case '\OC\Repair::advance': + $this->progress->advance($event->getArgument(0)); + break; + case '\OC\Repair::finishProgress': + $this->progress->finish(); + $this->output->writeln(''); + break; + case '\OC\Repair::step': + $this->output->writeln(' - ' . $event->getArgument(0)); + break; + case '\OC\Repair::info': + $this->output->writeln(' - ' . $event->getArgument(0)); + break; + case '\OC\Repair::warning': + $this->output->writeln(' - WARNING: ' . $event->getArgument(0)); + break; + case '\OC\Repair::error': + $this->output->writeln(' - ERROR: ' . $event->getArgument(0)); + break; + } + } } diff --git a/core/register_command.php b/core/register_command.php index 0b1a019f993..798497d97d2 100644 --- a/core/register_command.php +++ b/core/register_command.php @@ -112,7 +112,9 @@ if (\OC::$server->getConfig()->getSystemValue('installed', false)) { $application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateDB(\OC::$server->getMimeTypeDetector(), \OC::$server->getMimeTypeLoader())); $application->add(new OC\Core\Command\Maintenance\Mimetype\UpdateJS(\OC::$server->getMimeTypeDetector())); $application->add(new OC\Core\Command\Maintenance\Mode(\OC::$server->getConfig())); - $application->add(new OC\Core\Command\Maintenance\Repair(new \OC\Repair(\OC\Repair::getRepairSteps()), \OC::$server->getConfig())); + $application->add(new OC\Core\Command\Maintenance\Repair( + new \OC\Repair(\OC\Repair::getRepairSteps(), \OC::$server->getEventDispatcher()), \OC::$server->getConfig(), + \OC::$server->getEventDispatcher())); $application->add(new OC\Core\Command\Maintenance\SingleUser(\OC::$server->getConfig())); $application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->getLogger())); |