From e4550b342006b8e12ce8ffedde7b9ece57a2a647 Mon Sep 17 00:00:00 2001 From: Mathias Brodala Date: Fri, 10 Jan 2025 12:56:41 +0100 Subject: [PATCH] [TASK] Add update wizard to update the page of form log entries --- Classes/Updates/FormLogEntryPageUpdate.php | 73 ++++++++++++++++++++++ Configuration/Services.yaml | 3 + ext_localconf.php | 3 + 3 files changed, 79 insertions(+) create mode 100644 Classes/Updates/FormLogEntryPageUpdate.php diff --git a/Classes/Updates/FormLogEntryPageUpdate.php b/Classes/Updates/FormLogEntryPageUpdate.php new file mode 100644 index 0000000..86e938e --- /dev/null +++ b/Classes/Updates/FormLogEntryPageUpdate.php @@ -0,0 +1,73 @@ +connectionPool = $connectionPool; + } + + public function getIdentifier(): string + { + return self::class; + } + + public function getTitle(): string + { + return 'Form Log Entry Page Update'; + } + + public function getDescription(): string + { + return 'Move page info of form log entries to a dedicated field'; + } + + public function executeUpdate(): bool + { + $queryBuilder = $this->connectionPool->getQueryBuilderForTable('tx_formlog_entries'); + + $affectedRowCount = $queryBuilder + ->update('tx_formlog_entries') + ->set('page', $queryBuilder->quoteIdentifier('pid'), false) + ->set('pid', 0) + ->where($queryBuilder->expr()->eq('page', 0)) + ->executeStatement(); + + return $affectedRowCount > 0; + } + + public function updateNecessary(): bool + { + $queryBuilder = $this->connectionPool->getQueryBuilderForTable('tx_formlog_entries'); + + $entriesWithoutPageCount = $queryBuilder + ->count('*') + ->from('tx_formlog_entries') + ->where($queryBuilder->expr()->eq('page', 0)) + ->executeQuery() + ->fetchOne(); + + return $entriesWithoutPageCount > 0; + } + + public function getPrerequisites(): array + { + return [ + DatabaseUpdatedPrerequisite::class, + ]; + } +} diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index 3052ef1..c095b6f 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -9,3 +9,6 @@ services: Pagemachine\Formlog\Controller\Backend\FormLogSuggestController: public: true + + Pagemachine\Formlog\Updates\FormLogEntryPageUpdate: + public: true diff --git a/ext_localconf.php b/ext_localconf.php index 8dc9822..34fda2e 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -1,6 +1,7 @@ 'tstamp', 'expirePeriod' => 180,