Adding progress to occ maintenance:repair

This commit is contained in:
Thomas Müller 2016-04-26 16:24:50 +02:00
parent ba0099f73a
commit cdcd49b473
No known key found for this signature in database
GPG Key ID: A943788A3BBEC44C
3 changed files with 61 additions and 17 deletions

View File

@ -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;
}
}
}

View File

@ -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()));

View File

@ -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();
}
/**