summaryrefslogtreecommitdiffstats
path: root/core/Command
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2023-07-17 11:26:00 +0200
committerGitHub <noreply@github.com>2023-07-17 11:26:00 +0200
commit83f7ea01cd1bd30b2bba5d304ae6c2279f68d6f8 (patch)
tree0e815d5b40fa445e628aa39645e794cfab29e2d9 /core/Command
parent31f07f31926a061268c28055dbde74f9dc058b6d (diff)
parent18db96c304c2b2d93c3effc2c1d5b9320fe78ce1 (diff)
downloadnextcloud-server-83f7ea01cd1bd30b2bba5d304ae6c2279f68d6f8.tar.gz
nextcloud-server-83f7ea01cd1bd30b2bba5d304ae6c2279f68d6f8.zip
Merge pull request #39396 from nextcloud/backport/39389/stable27
Diffstat (limited to 'core/Command')
-rw-r--r--core/Command/Db/AddMissingIndices.php34
1 files changed, 32 insertions, 2 deletions
diff --git a/core/Command/Db/AddMissingIndices.php b/core/Command/Db/AddMissingIndices.php
index f0b4c14e15c..1044cea5547 100644
--- a/core/Command/Db/AddMissingIndices.php
+++ b/core/Command/Db/AddMissingIndices.php
@@ -36,6 +36,8 @@ namespace OC\Core\Command\Db;
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
use OC\DB\Connection;
use OC\DB\SchemaWrapper;
+use OCP\DB\Events\AddMissingIndicesEvent;
+use OCP\EventDispatcher\IEventDispatcher;
use OCP\IDBConnection;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputOption;
@@ -54,12 +56,14 @@ use Symfony\Component\EventDispatcher\GenericEvent;
*/
class AddMissingIndices extends Command {
private Connection $connection;
+ private IEventDispatcher $eventDispatcher;
private EventDispatcherInterface $dispatcher;
- public function __construct(Connection $connection, EventDispatcherInterface $dispatcher) {
+ public function __construct(Connection $connection, IEventDispatcher $eventDispatcher, EventDispatcherInterface $dispatcher) {
parent::__construct();
$this->connection = $connection;
+ $this->eventDispatcher = $eventDispatcher;
$this->dispatcher = $dispatcher;
}
@@ -71,11 +75,37 @@ class AddMissingIndices extends Command {
}
protected function execute(InputInterface $input, OutputInterface $output): int {
- $this->addCoreIndexes($output, $input->getOption('dry-run'));
+ $dryRun = $input->getOption('dry-run');
+
+ $this->addCoreIndexes($output, $dryRun);
// Dispatch event so apps can also update indexes if needed
$event = new GenericEvent($output);
$this->dispatcher->dispatch(IDBConnection::ADD_MISSING_INDEXES_EVENT, $event);
+
+ $event = new AddMissingIndicesEvent();
+ $this->eventDispatcher->dispatchTyped($event);
+
+ $missingIndices = $event->getMissingIndices();
+ if ($missingIndices !== []) {
+ $schema = new SchemaWrapper($this->connection);
+
+ foreach ($missingIndices as $missingIndex) {
+ if ($schema->hasTable($missingIndex['tableName'])) {
+ $table = $schema->getTable($missingIndex['tableName']);
+ if (!$table->hasIndex($missingIndex['indexName'])) {
+ $output->writeln('<info>Adding additional ' . $missingIndex['indexName'] . ' index to the ' . $table->getName() . ' table, this can take some time...</info>');
+ $table->addIndex($missingIndex['columns'], $missingIndex['indexName']);
+ $sqlQueries = $this->connection->migrateToSchema($schema->getWrappedSchema(), $dryRun);
+ if ($dryRun && $sqlQueries !== null) {
+ $output->writeln($sqlQueries);
+ }
+ $output->writeln('<info>' . $table->getName() . ' table updated successfully.</info>');
+ }
+ }
+ }
+ }
+
return 0;
}