diff --git a/appinfo/info.xml b/appinfo/info.xml index c4148e730a..51242c1aa6 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -32,6 +32,11 @@ OCA\Polls\Cron\JanitorCron OCA\Polls\Cron\AutoReminderCron + + + OCA\Polls\Migration\RepairSteps\UpdateHashes + + OCA\Polls\Command\Db\CleanMigrations OCA\Polls\Command\Db\CreateIndices diff --git a/lib/Command/Db/CleanMigrations.php b/lib/Command/Db/CleanMigrations.php index f0daf9d85c..0c7d5aea86 100644 --- a/lib/Command/Db/CleanMigrations.php +++ b/lib/Command/Db/CleanMigrations.php @@ -10,7 +10,7 @@ use Doctrine\DBAL\Schema\Schema; use OCA\Polls\Command\Command; -use OCA\Polls\Db\V3\TableManager; +use OCA\Polls\Db\V4\TableManager; use OCP\IDBConnection; /** diff --git a/lib/Command/Db/CreateIndices.php b/lib/Command/Db/CreateIndices.php index c781664a58..e4272dcc55 100644 --- a/lib/Command/Db/CreateIndices.php +++ b/lib/Command/Db/CreateIndices.php @@ -10,7 +10,7 @@ use Doctrine\DBAL\Schema\Schema; use OCA\Polls\Command\Command; -use OCA\Polls\Db\V3\IndexManager; +use OCA\Polls\Db\V4\IndexManager; use OCP\IDBConnection; /** diff --git a/lib/Command/Db/FixDB.php b/lib/Command/Db/FixDB.php index 04664eb288..2c4537cf4e 100644 --- a/lib/Command/Db/FixDB.php +++ b/lib/Command/Db/FixDB.php @@ -10,7 +10,7 @@ use Doctrine\DBAL\Schema\Schema; use OCA\Polls\Command\Command; -use OCA\Polls\Db\V3\TableManager; +use OCA\Polls\Db\V4\TableManager; use OCP\IDBConnection; /** diff --git a/lib/Command/Db/Purge.php b/lib/Command/Db/Purge.php index d225378c52..af747659f5 100644 --- a/lib/Command/Db/Purge.php +++ b/lib/Command/Db/Purge.php @@ -9,7 +9,7 @@ namespace OCA\Polls\Command\Db; use OCA\Polls\Command\Command; -use OCA\Polls\Db\V3\TableManager; +use OCA\Polls\Db\V4\TableManager; use OCP\IDBConnection; /** diff --git a/lib/Command/Db/Rebuild.php b/lib/Command/Db/Rebuild.php index bc1a84b7aa..f6dae27155 100644 --- a/lib/Command/Db/Rebuild.php +++ b/lib/Command/Db/Rebuild.php @@ -9,8 +9,8 @@ namespace OCA\Polls\Command\Db; use Doctrine\DBAL\Schema\Schema; -use OCA\Polls\Db\V3\TableManager; -use OCA\Polls\Db\V3\IndexManager; +use OCA\Polls\Db\V4\TableManager; +use OCA\Polls\Db\V4\IndexManager; use OCA\Polls\Command\Command; use OCP\IDBConnection; @@ -68,7 +68,7 @@ protected function runCommands(): int { $this->printComment('Step 5. Validate and fix records'); $this->removeOrphaned(); - $this->migrateOptionsToHash(); + $this->updateHashes(); $this->deleteAllDuplicates(); $this->setLastInteraction(); @@ -123,9 +123,9 @@ private function createOrUpdateSchema(): void { /** * Add or update hash for votes and options */ - private function migrateOptionsToHash(): void { + private function updateHashes(): void { $this->printComment(' - Add or update hashes'); - $messages = $this->tableManager->migrateOptionsToHash(); + $messages = $this->tableManager->updateHashes(); $this->printInfo($messages, ' '); } diff --git a/lib/Command/Db/RemoveFKConstraints.php b/lib/Command/Db/RemoveFKConstraints.php index b1aee31b19..52bdbf97e4 100644 --- a/lib/Command/Db/RemoveFKConstraints.php +++ b/lib/Command/Db/RemoveFKConstraints.php @@ -10,7 +10,7 @@ use Doctrine\DBAL\Schema\Schema; use OCA\Polls\Command\Command; -use OCA\Polls\Db\V3\IndexManager; +use OCA\Polls\Db\V4\IndexManager; use OCP\IDBConnection; /** diff --git a/lib/Command/Db/RemoveOptionalIndices.php b/lib/Command/Db/RemoveOptionalIndices.php index e947710092..61f0e23ee5 100644 --- a/lib/Command/Db/RemoveOptionalIndices.php +++ b/lib/Command/Db/RemoveOptionalIndices.php @@ -10,7 +10,7 @@ use Doctrine\DBAL\Schema\Schema; use OCA\Polls\Command\Command; -use OCA\Polls\Db\V3\IndexManager; +use OCA\Polls\Db\V4\IndexManager; use OCP\IDBConnection; /** diff --git a/lib/Command/Db/RemoveUniqueIndices.php b/lib/Command/Db/RemoveUniqueIndices.php index e741dce416..8efc8e2667 100644 --- a/lib/Command/Db/RemoveUniqueIndices.php +++ b/lib/Command/Db/RemoveUniqueIndices.php @@ -10,7 +10,7 @@ use Doctrine\DBAL\Schema\Schema; use OCA\Polls\Command\Command; -use OCA\Polls\Db\V3\IndexManager; +use OCA\Polls\Db\V4\IndexManager; use OCP\IDBConnection; /** diff --git a/lib/Command/Db/ResetWatch.php b/lib/Command/Db/ResetWatch.php index 1637ca5561..407a21a4fb 100644 --- a/lib/Command/Db/ResetWatch.php +++ b/lib/Command/Db/ResetWatch.php @@ -10,10 +10,10 @@ use Doctrine\DBAL\Schema\Schema; use OCA\Polls\Command\Command; -use OCA\Polls\Db\V3\IndexManager; -use OCA\Polls\Db\V3\TableManager; +use OCA\Polls\Db\V4\IndexManager; +use OCA\Polls\Db\V4\TableManager; use OCA\Polls\Db\Watch; -use OCA\Polls\Migration\V3\TableSchema; +use OCA\Polls\Migration\V4\TableSchema; use OCP\IDBConnection; /** diff --git a/lib/Cron/JanitorCron.php b/lib/Cron/JanitorCron.php index 59bbe16d11..587df1e9bd 100644 --- a/lib/Cron/JanitorCron.php +++ b/lib/Cron/JanitorCron.php @@ -15,7 +15,7 @@ use OCA\Polls\Db\OptionMapper; use OCA\Polls\Db\PollMapper; use OCA\Polls\Db\ShareMapper; -use OCA\Polls\Db\V3\TableManager; +use OCA\Polls\Db\V4\TableManager; use OCA\Polls\Db\VoteMapper; use OCA\Polls\Helper\Container; use OCA\Polls\Model\Settings\AppSettings; @@ -65,6 +65,9 @@ protected function run($argument) { // delete entries older than 1 day $this->tableManager->tidyWatchTable(time() - 86400); + // first make sure all options and votes have a correct hash + $this->tableManager->updateHashes(); + // purge entries virtually deleted more than 12 hours ago $deleted['comments'] = $this->commentMapper->purgeDeletedComments(time() - 4320); $deleted['options'] = $this->optionMapper->purgeDeletedOptions(time() - 4320); diff --git a/lib/Db/Option.php b/lib/Db/Option.php index 379fcd6810..0f97a428c8 100644 --- a/lib/Db/Option.php +++ b/lib/Db/Option.php @@ -200,8 +200,8 @@ public function shiftOption(DateTimeZone $timeZone, int $step, string $unit): vo } /** - * Syncs pollOptionText and order according to timestamp and duration if timestamp > 0 - * Updates hash + * Syncs pollOptionText and order according to timestamp and duration if timestamp > 0 and + * updates hash based on synced pollId and pollOptionText */ public function syncOption(): void { // make sure, pollOptionText matches timestamp and duration diff --git a/lib/Db/V3/DbManager.php b/lib/Db/V4/DbManager.php similarity index 99% rename from lib/Db/V3/DbManager.php rename to lib/Db/V4/DbManager.php index 0ba6b20c43..9bb1e31f4c 100644 --- a/lib/Db/V3/DbManager.php +++ b/lib/Db/V4/DbManager.php @@ -6,7 +6,7 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -namespace OCA\Polls\Db\V3; +namespace OCA\Polls\Db\V4; use Doctrine\DBAL\Schema\Schema; use Exception; diff --git a/lib/Db/V3/IndexManager.php b/lib/Db/V4/IndexManager.php similarity index 97% rename from lib/Db/V3/IndexManager.php rename to lib/Db/V4/IndexManager.php index 21f6cce73b..29f3a92e73 100644 --- a/lib/Db/V3/IndexManager.php +++ b/lib/Db/V4/IndexManager.php @@ -6,12 +6,12 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -namespace OCA\Polls\Db\V3; +namespace OCA\Polls\Db\V4; use Doctrine\DBAL\Schema\Exception\IndexDoesNotExist; use Doctrine\DBAL\Schema\Schema; use Exception; -use OCA\Polls\Migration\V3\TableSchema; +use OCA\Polls\Migration\V4\TableSchema; use OCP\DB\ISchemaWrapper; use OCP\IConfig; use OCP\IDBConnection; @@ -104,7 +104,12 @@ public function createForeignKeyConstraint(string $parentTableName, string $chil return 'Added ' . $parentTableName . '[' . $constraintColumn . '] <- ' . $childTableName . '[id]'; } - public function listExistingIndices() { + /** + * @return string[] + * + * @psalm-return list{0?: string,...} + */ + public function listExistingIndices(): array { $this->needsSchema(); $messages = []; diff --git a/lib/Db/V3/TableManager.php b/lib/Db/V4/TableManager.php similarity index 87% rename from lib/Db/V3/TableManager.php rename to lib/Db/V4/TableManager.php index abd47eb623..a63c163927 100644 --- a/lib/Db/V3/TableManager.php +++ b/lib/Db/V4/TableManager.php @@ -6,8 +6,9 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -namespace OCA\Polls\Db\V3; +namespace OCA\Polls\Db\V4; +use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Types\Type; use Exception; use OCA\Polls\AppConstants; @@ -19,7 +20,7 @@ use OCA\Polls\Db\VoteMapper; use OCA\Polls\Db\Watch; use OCA\Polls\Helper\Hash; -use OCA\Polls\Migration\V3\TableSchema; +use OCA\Polls\Migration\V4\TableSchema; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IConfig; use OCP\IDBConnection; @@ -540,59 +541,130 @@ public function setLastInteraction(?int $timestamp = null): string { } - public function migrateOptionsToHash(): array { - $schema = $this->connection->createSchema(); + /** + * @return string[] + * + * @psalm-return list{0?: string,...} + */ + private function updateVoteHashes(Schema &$schema): array { $messages = []; - - if ($schema->hasTable($this->dbPrefix . OptionMapper::TABLE)) { - $table = $schema->getTable($this->dbPrefix . OptionMapper::TABLE); + if ($schema->hasTable($this->dbPrefix . VoteMapper::TABLE)) { + $table = $schema->getTable($this->dbPrefix . VoteMapper::TABLE); $count = 0; - if ($table->hasColumn('poll_option_hash')) { - foreach ($this->optionMapper->getAll(includeNull: true) as $option) { + $updated = 0; + if ($table->hasColumn('vote_option_hash')) { + foreach ($this->voteMapper->getAll(includeNull: true) as $vote) { try { - $option->syncOption(); - $this->optionMapper->update($option); + // if the hash of the vote differs from calculated hash update the vote hash + if ($vote->getVoteOptionHash() !== Hash::getOptionHash($vote->getPollId(), $vote->getVoteOptionText())) { + $vote->setVoteOptionHash(Hash::getOptionHash($vote->getPollId(), $vote->getVoteOptionText())); + $vote = $this->voteMapper->update($vote); + $updated++; + } + $count++; + } catch (Exception $e) { - $messages[] = 'Skip hash update - Error updating option hash for optionId ' . $option->getId(); - $this->logger->error('Error updating option hash for optionId {id}', ['id' => $option->getId(), 'message' => $e->getMessage()]); + $messages[] = 'Skip hash update - Error updating option hash for voteId ' . $vote->getId(); + $this->logger->error('Error updating option hash for voteId {id}', [ + 'id' => $vote->getId(), + 'message' => $e->getMessage() + ]); } } - $this->logger->info('Updated {number} hashes in {db}', ['number' => $count,'db' => $this->dbPrefix . OptionMapper::TABLE]); - $messages[] = 'Updated ' . $count . ' option hashes'; + if ($updated === 0) { + $this->logger->info('Verified {count} vote hashes in {db}', [ + 'count' => $count, + 'db' => $this->dbPrefix . VoteMapper::TABLE + ]); + $messages[] = 'No vote hashes to update'; + + } else { + $this->logger->info('Updated {updated} hashes of {count} votes in {db}', [ + 'updated' => $updated, + 'count' => $count, + 'db' => $this->dbPrefix . VoteMapper::TABLE + ]); + $messages[] = 'Updated ' . $updated . ' vote hashes'; + + } } else { - $this->logger->error('{db} is missing column \'poll_option_hash\' - aborted recalculating hashes', [ 'db' => $this->dbPrefix . OptionMapper::TABLE]); + $this->logger->error('{db} is missing column \'poll_option_hash\' - aborted recalculating hashes', [ + 'db' => $this->dbPrefix . VoteMapper::TABLE + ]); } } else { - $this->logger->error('{db} is missing - aborted recalculating hashes', [ 'db' => $this->dbPrefix . OptionMapper::TABLE]); + $this->logger->error('{db} is missing- aborted recalculating hashes', [ + 'db' => $this->dbPrefix . VoteMapper::TABLE + ]); } + return $messages; + } - if ($schema->hasTable($this->dbPrefix . VoteMapper::TABLE)) { - $table = $schema->getTable($this->dbPrefix . VoteMapper::TABLE); + /** + * @return string[] + * + * @psalm-return list{0?: string,...} + */ + private function updateOptionHashes(Schema &$schema): array { + $messages = []; + + if ($schema->hasTable($this->dbPrefix . OptionMapper::TABLE)) { + $table = $schema->getTable($this->dbPrefix . OptionMapper::TABLE); $count = 0; - if ($table->hasColumn('vote_option_hash')) { - foreach ($this->voteMapper->getAll(includeNull: true) as $vote) { + $updated = 0; + + if ($table->hasColumn('poll_option_hash')) { + foreach ($this->optionMapper->getAll(includeNull: true) as $option) { try { - $vote->setVoteOptionHash(Hash::getOptionHash($vote->getPollId(), $vote->getVoteOptionText())); - $this->voteMapper->update($vote); + // if the option's hash differs from $actualHash update the option + if ($option->getPollOptionHash() !== Hash::getOptionHash($option->getPollId(), $option->getPollOptionText())) { + $option->setPollOptionHash(Hash::getOptionHash($option->getPollId(), $option->getPollOptionText())); + $option = $this->optionMapper->update($option); + $updated++; + } + $count++; + } catch (Exception $e) { - $messages[] = 'Skip hash update - Error updating option hash for voteId ' . $vote->getId(); - $this->logger->error('Error updating option hash for voteId {id}', ['id' => $vote->getId(), 'message' => $e->getMessage()]); + $messages[] = 'Skip hash update - Error updating option hash for optionId ' . $option->getId(); + $this->logger->error('Error updating option hash for optionId {id}', ['id' => $option->getId(), 'message' => $e->getMessage()]); } } - $this->logger->info('Updated {number} hashes in {db}', ['number' => $count, 'db' => $this->dbPrefix . VoteMapper::TABLE]); - $messages[] = 'Updated ' . $count . ' vote hashes'; + if ($updated === 0) { + $this->logger->info('Verified {count} option hashes in {db}', [ + 'count' => $count, + 'db' => $this->dbPrefix . OptionMapper::TABLE + ]); + $messages[] = 'No option hashes to update'; + + } else { + $this->logger->info('Updated {updated} hashes of {count} options in {db}', [ + 'updated' => $updated, + 'count' => $count, + 'db' => $this->dbPrefix . OptionMapper::TABLE + ]); + $messages[] = 'Updated ' . $updated . ' option hashes'; + + } } else { - $this->logger->error('{db} is missing column \'poll_option_hash\' - aborted recalculating hashes', ['db' => $this->dbPrefix . VoteMapper::TABLE]); + $this->logger->error('{db} is missing column \'poll_option_hash\' - aborted recalculating hashes', [ 'db' => $this->dbPrefix . OptionMapper::TABLE]); } + } else { - $this->logger->error('{db} is missing- aborted recalculating hashes', ['db' => $this->dbPrefix . VoteMapper::TABLE]); + $this->logger->error('{db} is missing - aborted recalculating hashes', [ 'db' => $this->dbPrefix . OptionMapper::TABLE]); } return $messages; } + + public function updateHashes(): array { + $schema = $this->connection->createSchema(); + $messages = $this->updateOptionHashes($schema); + $messages = array_merge($messages, $this->updateVoteHashes($schema)); + return $messages; + } } diff --git a/lib/Listener/AddMissingIndicesListener.php b/lib/Listener/AddMissingIndicesListener.php index 2b1a1022e3..e55d824846 100644 --- a/lib/Listener/AddMissingIndicesListener.php +++ b/lib/Listener/AddMissingIndicesListener.php @@ -8,7 +8,7 @@ namespace OCA\Polls\Listener; -use OCA\Polls\Migration\V3\TableSchema; +use OCA\Polls\Migration\V4\TableSchema; use OCP\DB\Events\AddMissingIndicesEvent; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; diff --git a/lib/Migration/FixVotes.php b/lib/Migration/FixVotes.php index 6c81ba501f..7255e2bb19 100644 --- a/lib/Migration/FixVotes.php +++ b/lib/Migration/FixVotes.php @@ -10,7 +10,7 @@ namespace OCA\Polls\Migration; use Doctrine\DBAL\Schema\Schema; -use OCA\Polls\Db\V3\TableManager; +use OCA\Polls\Db\V4\TableManager; use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; diff --git a/lib/Migration/RepairSteps/CleanTables.php b/lib/Migration/RepairSteps/CleanTables.php index 8bf5c4a5fa..e0c9f40b2f 100644 --- a/lib/Migration/RepairSteps/CleanTables.php +++ b/lib/Migration/RepairSteps/CleanTables.php @@ -12,7 +12,7 @@ use Doctrine\DBAL\Schema\Schema; use Exception; use OCA\Polls\Db\Poll; -use OCA\Polls\Db\V3\TableManager; +use OCA\Polls\Db\V4\TableManager; use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; @@ -36,7 +36,7 @@ public function getName():string { public function run(IOutput $output):void { if ($this->connection->tableExists(Poll::TABLE)) { try { - $this->tableManager->migrateOptionsToHash(); + $this->tableManager->updateHashes(); $this->tableManager->removeOrphaned(); $this->tableManager->deleteAllDuplicates(); $this->tableManager->tidyWatchTable(time()); diff --git a/lib/Migration/RepairSteps/CreateIndices.php b/lib/Migration/RepairSteps/CreateIndices.php index ac1f88744e..940da78e22 100644 --- a/lib/Migration/RepairSteps/CreateIndices.php +++ b/lib/Migration/RepairSteps/CreateIndices.php @@ -11,7 +11,7 @@ use Doctrine\DBAL\Schema\Schema; use OCA\Polls\Db\Share; -use OCA\Polls\Db\V3\IndexManager; +use OCA\Polls\Db\V4\IndexManager; use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; diff --git a/lib/Migration/RepairSteps/CreateTables.php b/lib/Migration/RepairSteps/CreateTables.php index 22c789ebce..3f7d941ab3 100644 --- a/lib/Migration/RepairSteps/CreateTables.php +++ b/lib/Migration/RepairSteps/CreateTables.php @@ -10,7 +10,7 @@ namespace OCA\Polls\Migration\RepairSteps; use Doctrine\DBAL\Schema\Schema; -use OCA\Polls\Db\V3\TableManager; +use OCA\Polls\Db\V4\TableManager; use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; diff --git a/lib/Migration/RepairSteps/DropOrphanedColumns.php b/lib/Migration/RepairSteps/DropOrphanedColumns.php index c2d65e8999..835ac9843f 100644 --- a/lib/Migration/RepairSteps/DropOrphanedColumns.php +++ b/lib/Migration/RepairSteps/DropOrphanedColumns.php @@ -10,7 +10,7 @@ namespace OCA\Polls\Migration\RepairSteps; use Doctrine\DBAL\Schema\Schema; -use OCA\Polls\Db\V3\TableManager; +use OCA\Polls\Db\V4\TableManager; use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; diff --git a/lib/Migration/RepairSteps/DropOrphanedTables.php b/lib/Migration/RepairSteps/DropOrphanedTables.php index e44fd26d9f..a21b58b320 100644 --- a/lib/Migration/RepairSteps/DropOrphanedTables.php +++ b/lib/Migration/RepairSteps/DropOrphanedTables.php @@ -10,7 +10,7 @@ namespace OCA\Polls\Migration\RepairSteps; use Doctrine\DBAL\Schema\Schema; -use OCA\Polls\Db\V3\TableManager; +use OCA\Polls\Db\V4\TableManager; use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; diff --git a/lib/Migration/RepairSteps/FixNullish.php b/lib/Migration/RepairSteps/FixNullish.php index 2622811603..48ffa86384 100644 --- a/lib/Migration/RepairSteps/FixNullish.php +++ b/lib/Migration/RepairSteps/FixNullish.php @@ -9,7 +9,7 @@ namespace OCA\Polls\Migration\RepairSteps; -use OCA\Polls\Db\V3\TableManager; +use OCA\Polls\Db\V4\TableManager; use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; diff --git a/lib/Migration/RepairSteps/Install.php b/lib/Migration/RepairSteps/Install.php index d10acc6598..1df0ca8149 100644 --- a/lib/Migration/RepairSteps/Install.php +++ b/lib/Migration/RepairSteps/Install.php @@ -10,7 +10,7 @@ namespace OCA\Polls\Migration\RepairSteps; use Doctrine\DBAL\Schema\Schema; -use OCA\Polls\Db\V3\IndexManager; +use OCA\Polls\Db\V4\IndexManager; use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; diff --git a/lib/Migration/RepairSteps/RemoveIndices.php b/lib/Migration/RepairSteps/RemoveIndices.php index 6a33e5633a..9fa4de9ea5 100644 --- a/lib/Migration/RepairSteps/RemoveIndices.php +++ b/lib/Migration/RepairSteps/RemoveIndices.php @@ -9,7 +9,7 @@ namespace OCA\Polls\Migration\RepairSteps; use Doctrine\DBAL\Schema\Schema; -use OCA\Polls\Db\V3\IndexManager; +use OCA\Polls\Db\V4\IndexManager; use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; diff --git a/lib/Migration/RepairSteps/RemoveObsoleteMigrations.php b/lib/Migration/RepairSteps/RemoveObsoleteMigrations.php index 5b7409a408..61c1ec9ed3 100644 --- a/lib/Migration/RepairSteps/RemoveObsoleteMigrations.php +++ b/lib/Migration/RepairSteps/RemoveObsoleteMigrations.php @@ -9,7 +9,7 @@ namespace OCA\Polls\Migration\RepairSteps; use Doctrine\DBAL\Schema\Schema; -use OCA\Polls\Db\V3\TableManager; +use OCA\Polls\Db\V4\TableManager; use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; diff --git a/lib/Migration/RepairSteps/SetLastInteraction.php b/lib/Migration/RepairSteps/SetLastInteraction.php index db6a3b0e0e..0ef6283431 100644 --- a/lib/Migration/RepairSteps/SetLastInteraction.php +++ b/lib/Migration/RepairSteps/SetLastInteraction.php @@ -9,7 +9,7 @@ namespace OCA\Polls\Migration\RepairSteps; -use OCA\Polls\Db\V3\TableManager; +use OCA\Polls\Db\V4\TableManager; use OCA\Polls\Db\WatchMapper; use OCP\IDBConnection; use OCP\Migration\IOutput; diff --git a/lib/Migration/RepairSteps/UpdateHashes.php b/lib/Migration/RepairSteps/UpdateHashes.php index 82e6170073..6178276a35 100644 --- a/lib/Migration/RepairSteps/UpdateHashes.php +++ b/lib/Migration/RepairSteps/UpdateHashes.php @@ -9,7 +9,7 @@ namespace OCA\Polls\Migration\RepairSteps; -use OCA\Polls\Db\V3\TableManager; +use OCA\Polls\Db\V4\TableManager; use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; @@ -22,13 +22,13 @@ public function __construct( } public function getName() { - return 'Polls - Create hashes for votes and options'; + return 'Polls - Update or create hashes for votes and options'; } public function run(IOutput $output): void { $this->tableManager->setConnection($this->connection); - $messages = $this->tableManager->migrateOptionsToHash(); + $messages = $this->tableManager->updateHashes(); foreach ($messages as $message) { $output->info($message); } diff --git a/lib/Migration/RepairSteps/UpdateInteraction.php b/lib/Migration/RepairSteps/UpdateInteraction.php index 52d70de646..0849a74269 100644 --- a/lib/Migration/RepairSteps/UpdateInteraction.php +++ b/lib/Migration/RepairSteps/UpdateInteraction.php @@ -9,7 +9,7 @@ namespace OCA\Polls\Migration\RepairSteps; -use OCA\Polls\Db\V3\TableManager; +use OCA\Polls\Db\V4\TableManager; use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; diff --git a/lib/Migration/V3/TableSchema.php b/lib/Migration/V4/TableSchema.php similarity index 99% rename from lib/Migration/V3/TableSchema.php rename to lib/Migration/V4/TableSchema.php index 1881334dc5..b7f07ca345 100644 --- a/lib/Migration/V3/TableSchema.php +++ b/lib/Migration/V4/TableSchema.php @@ -6,7 +6,7 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -namespace OCA\Polls\Migration\V3; +namespace OCA\Polls\Migration\V4; use OCA\Polls\Db\Comment; use OCA\Polls\Db\Log; diff --git a/lib/Migration/Version080300Date20250812231603.php b/lib/Migration/Version080300Date20250812231603.php new file mode 100644 index 0000000000..34ec04e0a1 --- /dev/null +++ b/lib/Migration/Version080300Date20250812231603.php @@ -0,0 +1,47 @@ +logInfo($message, 'postMigration: '); // ensure correct option hashes in options and votes - $message = $this->tableManager->migrateOptionsToHash(); + $message = $this->tableManager->updateHashes(); $this->logInfo($message, 'postMigration: '); // remove all duplicate records which have to be unique