Fix verbose output of upgrade command - not progressbar in this case and the schema migration test has one progressbar now for all tables - before we had one progressbar for each table

This commit is contained in:
Thomas Müller 2016-04-04 16:20:53 +02:00
parent 1f7e02e4d4
commit 4b79fb10a2
3 changed files with 45 additions and 19 deletions

View file

@ -61,6 +61,11 @@ if (OC::checkUpgrade(false)) {
$eventSource->send('success', (string)$l->t('[%d / %d]: %s', [$event[0], $event[1], $event->getSubject()])); $eventSource->send('success', (string)$l->t('[%d / %d]: %s', [$event[0], $event[1], $event->getSubject()]));
} }
}); });
$dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($eventSource, $l) {
if ($event instanceof GenericEvent) {
$eventSource->send('success', (string)$l->t('[%d / %d]: Checking table %s', [$event[0], $event[1], $event->getSubject()]));
}
});
$updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($eventSource, $l) { $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($eventSource, $l) {
$eventSource->send('success', (string)$l->t('Turned on maintenance mode')); $eventSource->send('success', (string)$l->t('Turned on maintenance mode'));

View file

@ -139,26 +139,32 @@ class Upgrade extends Command {
$updater->setSkip3rdPartyAppsDisable($skip3rdPartyAppsDisable); $updater->setSkip3rdPartyAppsDisable($skip3rdPartyAppsDisable);
$dispatcher = \OC::$server->getEventDispatcher(); $dispatcher = \OC::$server->getEventDispatcher();
$progress = new ProgressBar($output); $progress = new ProgressBar($output);
$progress->setFormat("%message%\n %current%/%max% [%bar%] %percent:3s%%"); $progress->setFormat(" %message%\n %current%/%max% [%bar%] %percent:3s%%");
$dispatcher->addListener('\OC\DB\Migrator::executeSql', function($event) use ($progress, $output) { $listener = function($event) use ($progress, $output) {
if ($event instanceof GenericEvent) { if ($event instanceof GenericEvent) {
if ($event[0] === 1) {
$output->writeln('');
$progress->start($event[1]);
}
$message = $event->getSubject(); $message = $event->getSubject();
if (strlen($message) > 30) { if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) {
$message = substr($message, 0, 27) . '...'; $output->writeln(' Checking table ' . $message);
} } else {
$progress->setMessage($message); if (strlen($message) > 60) {
$progress->setProgress($event[0]); $message = substr($message, 0, 57) . '...';
$progress->display(); }
if ($event[0] === $event[1]) { $progress->setMessage($message);
$progress->finish(); if ($event[0] === 1) {
$output->writeln(''); $output->writeln('');
$progress->start($event[1]);
}
$progress->setProgress($event[0]);
if ($event[0] === $event[1]) {
$progress->setMessage('Done');
$progress->finish();
$output->writeln('');
}
} }
} }
}); };
$dispatcher->addListener('\OC\DB\Migrator::executeSql', $listener);
$dispatcher->addListener('\OC\DB\Migrator::checkTable', $listener);
$updater->listen('\OC\Updater', 'maintenanceEnabled', function () use($output) { $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use($output) {
$output->writeln('<info>Turned on maintenance mode</info>'); $output->writeln('<info>Turned on maintenance mode</info>');

View file

@ -56,6 +56,9 @@ class Migrator {
/** @var EventDispatcher */ /** @var EventDispatcher */
private $dispatcher; private $dispatcher;
/** @var bool */
private $noEmit = false;
/** /**
* @param \Doctrine\DBAL\Connection|Connection $connection * @param \Doctrine\DBAL\Connection|Connection $connection
* @param ISecureRandom $random * @param ISecureRandom $random
@ -76,6 +79,7 @@ class Migrator {
* @param \Doctrine\DBAL\Schema\Schema $targetSchema * @param \Doctrine\DBAL\Schema\Schema $targetSchema
*/ */
public function migrate(Schema $targetSchema) { public function migrate(Schema $targetSchema) {
$this->noEmit = true;
$this->applySchema($targetSchema); $this->applySchema($targetSchema);
} }
@ -100,21 +104,22 @@ class Migrator {
* @throws \OC\DB\MigrationException * @throws \OC\DB\MigrationException
*/ */
public function checkMigrate(Schema $targetSchema) { public function checkMigrate(Schema $targetSchema) {
/** $this->noEmit = true;
* @var \Doctrine\DBAL\Schema\Table[] $tables /**@var \Doctrine\DBAL\Schema\Table[] $tables */
*/
$tables = $targetSchema->getTables(); $tables = $targetSchema->getTables();
$filterExpression = $this->getFilterExpression(); $filterExpression = $this->getFilterExpression();
$this->connection->getConfiguration()-> $this->connection->getConfiguration()->
setFilterSchemaAssetsExpression($filterExpression); setFilterSchemaAssetsExpression($filterExpression);
$existingTables = $this->connection->getSchemaManager()->listTableNames(); $existingTables = $this->connection->getSchemaManager()->listTableNames();
$step = 0;
foreach ($tables as $table) { foreach ($tables as $table) {
if (strpos($table->getName(), '.')) { if (strpos($table->getName(), '.')) {
list(, $tableName) = explode('.', $table->getName()); list(, $tableName) = explode('.', $table->getName());
} else { } else {
$tableName = $table->getName(); $tableName = $table->getName();
} }
$this->emitCheckStep($tableName, $step++, count($tables));
// don't need to check for new tables // don't need to check for new tables
if (array_search($tableName, $existingTables) !== false) { if (array_search($tableName, $existingTables) !== false) {
$this->checkTableMigrate($table); $this->checkTableMigrate($table);
@ -269,9 +274,19 @@ class Migrator {
} }
protected function emit($sql, $step, $max) { protected function emit($sql, $step, $max) {
if ($this->noEmit) {
return;
}
if(is_null($this->dispatcher)) { if(is_null($this->dispatcher)) {
return; return;
} }
$this->dispatcher->dispatch('\OC\DB\Migrator::executeSql', new GenericEvent($sql, [$step+1, $max])); $this->dispatcher->dispatch('\OC\DB\Migrator::executeSql', new GenericEvent($sql, [$step+1, $max]));
} }
private function emitCheckStep($tableName, $step, $max) {
if(is_null($this->dispatcher)) {
return;
}
$this->dispatcher->dispatch('\OC\DB\Migrator::checkTable', new GenericEvent($tableName, [$step+1, $max]));
}
} }