diff --git a/lib/Command/Db/Rebuild.php b/lib/Command/Db/Rebuild.php index d8448a1461..15e289e742 100644 --- a/lib/Command/Db/Rebuild.php +++ b/lib/Command/Db/Rebuild.php @@ -68,10 +68,11 @@ protected function runCommands(): int { $this->connection->migrateToSchema($this->schema); $this->printComment('Step 5. Validate and fix records'); - $this->removeOrphaned(); $this->updateHashes(); + $this->removeOrphaned(); $this->deleteAllDuplicates(); $this->setLastInteraction(); + $this->migrateAccess(); $this->printComment('Step 6. Recreate unique indices and foreign key constraints'); $this->addForeignKeyConstraints(); @@ -155,10 +156,20 @@ private function dropObsoleteTables(): void { * Initialize last poll interactions timestamps */ public function setLastInteraction(): void { + $this->printComment(' - Set last interaction'); $messages = $this->tableManager->setLastInteraction(); $this->printInfo($messages, ' '); } + /** + * Initialize last poll interactions timestamps + */ + public function migrateAccess(): void { + $this->printComment(' - Migrate access'); + $messages = $this->tableManager->migratePublicToOpen(); + $this->printInfo($messages, ' '); + } + /** * Remove obsolete tables if they still exist */ diff --git a/lib/Db/V4/TableManager.php b/lib/Db/V4/TableManager.php index 614ab5f327..9cbfb639a4 100644 --- a/lib/Db/V4/TableManager.php +++ b/lib/Db/V4/TableManager.php @@ -259,6 +259,7 @@ public function removeObsoleteColumns(): array { */ public function removeOrphaned(): array { $orphanedCount = []; + // collects all pollIds $subqueryPolls = $this->connection->getQueryBuilder(); $subqueryPolls->selectDistinct('id')->from(Poll::TABLE); @@ -326,13 +327,17 @@ public function removeOrphaned(): array { $query->delete(Poll::TABLE) ->where($query->expr()->isNull('id')); $orphanedCount[Poll::TABLE] = $query->executeStatement(); + $messages = []; foreach ($orphanedCount as $tableName => $count) { if ($count > 0) { $this->logger->info( - 'Purged {count} orphaned record(s) from {tableName}', - ['count' => $count, 'tableName' => $tableName] + 'Removed {count} orphaned record(s) from {tableName}', + ['count' => $count, 'tableName' => $this->dbPrefix . $tableName] ); + $messages[] = 'Removed ' . $count . ' orphaned record(s) from ' . $this->dbPrefix . $tableName; + } else { + $messages[] = 'No orphaned records found in ' . $this->dbPrefix . $tableName; } } @@ -743,8 +748,8 @@ public function migrateShareLabels(): array { $qb->update($tableName) ->set('display_name', $affectedColumn) - ->andWhere($qb->expr()->isNotNull($tableName . '.' . $affectedColumn)) - ->andWhere($qb->expr()->eq($tableName . '.' . $affectedColumn, $qb->expr()->literal(''))); + ->andWhere($qb->expr()->isNotNull($prefixedTableName . '.' . $affectedColumn)) + ->andWhere($qb->expr()->eq($prefixedTableName . '.' . $affectedColumn, $qb->expr()->literal(''))); $updated = $qb->executeStatement(); if ($updated === 0) { @@ -788,21 +793,21 @@ public function migratePublicToOpen(): array { $qb->update($tableName) ->set('access', $qb->expr()->literal(Poll::ACCESS_OPEN)) - ->where($qb->expr()->eq($tableName . '.' . $affectedColumn, $qb->expr()->literal(Poll::ACCESS_PUBLIC))); + ->where($qb->expr()->eq($prefixedTableName . '.' . $affectedColumn, $qb->expr()->literal(Poll::ACCESS_PUBLIC))); $updated = $qb->executeStatement(); if ($updated === 0) { $this->logger->info('Verified poll access to be \'open\' instead of \'public\' in {db}', [ 'db' => $prefixedTableName ]); - $messages[] = 'No poll access to update'; + $messages[] = 'No poll access values to update'; } else { - $this->logger->info('Updated {updated} access in {db}', [ + $this->logger->info('Updated {updated} access values in {db}', [ 'updated' => $updated, 'db' => $prefixedTableName ]); - $messages[] = 'Updated ' . $updated . ' poll accesses'; + $messages[] = 'Updated ' . $updated . ' poll access value'; } diff --git a/lib/Migration/RepairSteps/MigratePublicToOpen.php b/lib/Migration/RepairSteps/MigratePublicToOpen.php index 670bfbb617..3fcb72486a 100644 --- a/lib/Migration/RepairSteps/MigratePublicToOpen.php +++ b/lib/Migration/RepairSteps/MigratePublicToOpen.php @@ -22,7 +22,7 @@ public function __construct( } public function getName() { - return 'Polls - Update or create hashes for votes and options'; + return 'Polls - Migrate access values from public to open'; } public function run(IOutput $output): void { diff --git a/lib/Migration/Version080307Date20250826231102.php b/lib/Migration/Version080307Date20250826231102.php index ce7561de4b..9abfb24ab0 100644 --- a/lib/Migration/Version080307Date20250826231102.php +++ b/lib/Migration/Version080307Date20250826231102.php @@ -118,10 +118,6 @@ public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array // Clean up tables before creating indices and foreign keys - // remove all orphaned records - $message = $this->tableManager->removeOrphaned(); - $this->logInfo($message, 'postMigration: '); - // ensure correct option hashes in options and votes $message = $this->tableManager->updateHashes(); $this->logInfo($message, 'postMigration: '); @@ -130,6 +126,10 @@ public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $message = $this->tableManager->deleteAllDuplicates(); $this->logInfo($message, 'postMigration: '); + // remove all orphaned records + $message = $this->tableManager->removeOrphaned(); + $this->logInfo($message, 'postMigration: '); + // remove obsolete tables and columns $message = $this->tableManager->removeObsoleteTables(); $this->logInfo($message, 'postMigration: ');