Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Switch to string keys for argument of GenericEvent for OC\DB\Migrator
It seems checkTable is actually never dispatched?

Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc committed Aug 25, 2022
commit 4ba30d40cfc892bee0ea28486e63c479e1aadd20
8 changes: 4 additions & 4 deletions core/Command/Upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$message = substr($message, 0, 57) . '...';
}
$progress->setMessage($message);
if ($event[0] === 1) {
if ($event['step'] === 1) {
$output->writeln('');
$progress->start($event[1]);
$progress->start($event['max']);
}
$progress->setProgress($event[0]);
if ($event[0] === $event[1]) {
$progress->setProgress($event['step']);
if ($event['step'] === $event['max']) {
$progress->setMessage('Done');
$progress->finish();
$output->writeln('');
Expand Down
4 changes: 2 additions & 2 deletions core/ajax/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ public function handleRepairFeedback($event) {
$dispatcher = \OC::$server->getEventDispatcher();
$dispatcher->addListener('\OC\DB\Migrator::executeSql', function ($event) use ($eventSource, $l) {
if ($event instanceof GenericEvent) {
$eventSource->send('success', $l->t('[%d / %d]: %s', [$event[0], $event[1], $event->getSubject()]));
$eventSource->send('success', $l->t('[%d / %d]: %s', [$event['step'], $event['max'], $event->getSubject()]));
}
});
$dispatcher->addListener('\OC\DB\Migrator::checkTable', function ($event) use ($eventSource, $l) {
if ($event instanceof GenericEvent) {
$eventSource->send('success', $l->t('[%d / %d]: Checking table %s', [$event[0], $event[1], $event->getSubject()]));
$eventSource->send('success', $l->t('[%d / %d]: Checking table %s', [$event['step'], $event['max'], $event->getSubject()]));
}
});
$feedBack = new FeedBackHandler($eventSource, $l);
Expand Down
31 changes: 10 additions & 21 deletions lib/private/DB/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
*/
namespace OC\DB;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\Schema\AbstractAsset;
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\SchemaDiff;
use Doctrine\DBAL\Types\StringType;
use Doctrine\DBAL\Types\Type;
use OCP\IConfig;
Expand All @@ -41,34 +43,27 @@

class Migrator {

/** @var \Doctrine\DBAL\Connection */
/** @var Connection */
protected $connection;

/** @var IConfig */
protected $config;

/** @var EventDispatcherInterface */
/** @var ?EventDispatcherInterface */
private $dispatcher;

/** @var bool */
private $noEmit = false;

/**
* @param \Doctrine\DBAL\Connection $connection
* @param IConfig $config
* @param EventDispatcherInterface $dispatcher
*/
public function __construct(\Doctrine\DBAL\Connection $connection,
public function __construct(Connection $connection,
IConfig $config,
EventDispatcherInterface $dispatcher = null) {
?EventDispatcherInterface $dispatcher = null) {
$this->connection = $connection;
$this->config = $config;
$this->dispatcher = $dispatcher;
}

/**
* @param \Doctrine\DBAL\Schema\Schema $targetSchema
*
* @throws Exception
*/
public function migrate(Schema $targetSchema) {
Expand All @@ -77,7 +72,6 @@ public function migrate(Schema $targetSchema) {
}

/**
* @param \Doctrine\DBAL\Schema\Schema $targetSchema
* @return string
*/
public function generateChangeScript(Schema $targetSchema) {
Expand Down Expand Up @@ -108,11 +102,9 @@ public function createSchema() {
}

/**
* @param Schema $targetSchema
* @param \Doctrine\DBAL\Connection $connection
* @return \Doctrine\DBAL\Schema\SchemaDiff
* @return SchemaDiff
*/
protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) {
protected function getDiff(Schema $targetSchema, Connection $connection) {
// adjust varchar columns with a length higher then getVarcharMaxLength to clob
foreach ($targetSchema->getTables() as $table) {
foreach ($table->getColumns() as $column) {
Expand Down Expand Up @@ -153,12 +145,9 @@ protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $conn
}

/**
* @param \Doctrine\DBAL\Schema\Schema $targetSchema
* @param \Doctrine\DBAL\Connection $connection
*
* @throws Exception
*/
protected function applySchema(Schema $targetSchema, \Doctrine\DBAL\Connection $connection = null) {
protected function applySchema(Schema $targetSchema, Connection $connection = null) {
if (is_null($connection)) {
$connection = $this->connection;
}
Expand Down Expand Up @@ -201,6 +190,6 @@ protected function emit($sql, $step, $max) {
if (is_null($this->dispatcher)) {
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' => $step + 1, 'max' => $max]));
}
}
4 changes: 2 additions & 2 deletions lib/private/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,13 +467,13 @@ private function logAllEvents(): void {
if (!$event instanceof GenericEvent) {
return;
}
$log->info('\OC\DB\Migrator::executeSql: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']);
$log->info('\OC\DB\Migrator::executeSql: ' . $event->getSubject() . ' (' . $event->getArgument('step') . ' of ' . $event->getArgument('max') . ')', ['app' => 'updater']);
});
$dispatcher->addListener('\OC\DB\Migrator::checkTable', function ($event) use ($log) {
if (!$event instanceof GenericEvent) {
return;
}
$log->info('\OC\DB\Migrator::checkTable: ' . $event->getSubject() . ' (' . $event->getArgument(0) . ' of ' . $event->getArgument(1) . ')', ['app' => 'updater']);
$log->info('\OC\DB\Migrator::checkTable: ' . $event->getSubject() . ' (' . $event->getArgument('step') . ' of ' . $event->getArgument('max') . ')', ['app' => 'updater']);
});

$repairListener = function ($event) use ($log) {
Expand Down