Unverified Commit cdcd49b4 authored by Thomas Müller's avatar Thomas Müller
Browse files

Adding progress to occ maintenance:repair

parent ba0099f7
......@@ -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;
}
}
}
......@@ -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()));
......
......@@ -55,12 +55,15 @@ class DropOldTables implements IRepairStep {
* @throws \Exception in case of failure
*/
public function run(IOutput $output) {
$tables = $this->oldDatabaseTables();
$output->startProgress(count($tables));
foreach ($this->oldDatabaseTables() as $tableName) {
if ($this->connection->tableExists($tableName)){
$output->info(sprintf('Table %s has been deleted', $tableName));
$this->connection->dropTable($tableName);
}
$output->advance();
}
$output->finishProgress();
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment