mirror of
https://github.com/nextcloud/server.git
synced 2026-04-20 22:00:39 -04:00
fix(db): Move missing core columns to typed event
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
77c2b169a5
commit
f73f14207c
3 changed files with 15 additions and 53 deletions
|
|
@ -54,7 +54,9 @@ use OC\Metadata\FileEventListener;
|
|||
use OC\TagManager;
|
||||
use OCP\AppFramework\App;
|
||||
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
|
||||
use OCP\DB\Events\AddMissingColumnsEvent;
|
||||
use OCP\DB\Events\AddMissingPrimaryKeyEvent;
|
||||
use OCP\DB\Types;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\Files\Events\Node\NodeDeletedEvent;
|
||||
use OCP\Files\Events\Node\NodeWrittenEvent;
|
||||
|
|
@ -298,22 +300,17 @@ class Application extends App {
|
|||
);
|
||||
});
|
||||
|
||||
$oldEventDispatcher->addListener(IDBConnection::CHECK_MISSING_COLUMNS_EVENT,
|
||||
function (GenericEvent $event) use ($container) {
|
||||
/** @var MissingColumnInformation $subject */
|
||||
$subject = $event->getSubject();
|
||||
|
||||
$schema = new SchemaWrapper($container->query(Connection::class));
|
||||
|
||||
if ($schema->hasTable('comments')) {
|
||||
$table = $schema->getTable('comments');
|
||||
|
||||
if (!$table->hasColumn('reference_id')) {
|
||||
$subject->addHintForMissingColumn($table->getName(), 'reference_id');
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
$eventDispatcher->addListener(AddMissingColumnsEvent::class, function (AddMissingColumnsEvent $event) {
|
||||
$event->addMissingColumn(
|
||||
'comments',
|
||||
'reference_id',
|
||||
Types::STRING,
|
||||
[
|
||||
'notnull' => false,
|
||||
'length' => 64,
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
$eventDispatcher->addServiceListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class);
|
||||
$eventDispatcher->addServiceListener(RemoteWipeStarted::class, RemoteWipeActivityListener::class);
|
||||
|
|
|
|||
|
|
@ -66,8 +66,6 @@ class AddMissingColumns extends Command {
|
|||
protected function execute(InputInterface $input, OutputInterface $output): int {
|
||||
$dryRun = $input->getOption('dry-run');
|
||||
|
||||
$updated = $this->addCoreColumns($output, $dryRun);
|
||||
|
||||
// Dispatch event so apps can also update columns if needed
|
||||
$event = new GenericEvent($output);
|
||||
$this->legacyDispatcher->dispatch(IDBConnection::ADD_MISSING_COLUMNS_EVENT, $event);
|
||||
|
|
@ -75,6 +73,7 @@ class AddMissingColumns extends Command {
|
|||
$event = new AddMissingColumnsEvent();
|
||||
$this->dispatcher->dispatchTyped($event);
|
||||
$missingColumns = $event->getMissingColumns();
|
||||
$updated = false;
|
||||
|
||||
if (!empty($missingColumns)) {
|
||||
$schema = new SchemaWrapper($this->connection);
|
||||
|
|
@ -102,38 +101,4 @@ class AddMissingColumns extends Command {
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add missing column for core tables
|
||||
*
|
||||
* @param OutputInterface $output
|
||||
* @param bool $dryRun If true, will return the sql queries instead of running them.
|
||||
* @return bool True when the schema changed
|
||||
* @throws \Doctrine\DBAL\Schema\SchemaException
|
||||
*/
|
||||
private function addCoreColumns(OutputInterface $output, bool $dryRun): bool {
|
||||
$output->writeln('<info>Check columns of the comments table.</info>');
|
||||
|
||||
$schema = new SchemaWrapper($this->connection);
|
||||
$updated = false;
|
||||
|
||||
if ($schema->hasTable('comments')) {
|
||||
$table = $schema->getTable('comments');
|
||||
if (!$table->hasColumn('reference_id')) {
|
||||
$output->writeln('<info>Adding additional reference_id column to the comments table, this can take some time...</info>');
|
||||
$table->addColumn('reference_id', Types::STRING, [
|
||||
'notnull' => false,
|
||||
'length' => 64,
|
||||
]);
|
||||
$sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
|
||||
if ($dryRun && $sqlQueries !== null) {
|
||||
$output->writeln($sqlQueries);
|
||||
}
|
||||
$updated = true;
|
||||
$output->writeln('<info>Comments table updated successfully.</info>');
|
||||
}
|
||||
}
|
||||
|
||||
return $updated;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,9 +109,9 @@ if (\OC::$server->getConfig()->getSystemValue('installed', false)) {
|
|||
$application->add(new OC\Core\Command\Db\ConvertType(\OC::$server->getConfig(), new \OC\DB\ConnectionFactory(\OC::$server->getSystemConfig())));
|
||||
$application->add(new OC\Core\Command\Db\ConvertMysqlToMB4(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection(), \OC::$server->getURLGenerator(), \OC::$server->get(LoggerInterface::class)));
|
||||
$application->add(new OC\Core\Command\Db\ConvertFilecacheBigInt(\OC::$server->get(\OC\DB\Connection::class)));
|
||||
$application->add(\OCP\Server::get(\OC\Core\Command\Db\AddMissingColumns::class));
|
||||
$application->add(\OCP\Server::get(\OC\Core\Command\Db\AddMissingIndices::class));
|
||||
$application->add(\OCP\Server::get(\OC\Core\Command\Db\AddMissingPrimaryKeys::class));
|
||||
$application->add(new OC\Core\Command\Db\AddMissingColumns(\OC::$server->get(\OC\DB\Connection::class), \OC::$server->getEventDispatcher()));
|
||||
|
||||
if (\OC::$server->getConfig()->getSystemValueBool('debug', false)) {
|
||||
$application->add(new OC\Core\Command\Db\Migrations\StatusCommand(\OC::$server->get(\OC\DB\Connection::class)));
|
||||
|
|
|
|||
Loading…
Reference in a new issue