Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
13 changes: 12 additions & 1 deletion lib/Command/Db/Rebuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
*/
Expand Down
21 changes: 13 additions & 8 deletions lib/Db/V4/TableManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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';

}

Expand Down
2 changes: 1 addition & 1 deletion lib/Migration/RepairSteps/MigratePublicToOpen.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions lib/Migration/Version080307Date20250826231102.php
Original file line number Diff line number Diff line change
Expand Up @@ -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: ');
Expand All @@ -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: ');
Expand Down