diff --git a/Classes/Updates/MigrateRealUrlExcludeField.php b/Classes/Updates/MigrateRealUrlExcludeField.php index 9b326ed..d36e586 100644 --- a/Classes/Updates/MigrateRealUrlExcludeField.php +++ b/Classes/Updates/MigrateRealUrlExcludeField.php @@ -38,10 +38,9 @@ public function getDescription(): string return 'Masi - Migrate RealUrl pages.tx_realurl_exclude field to Masi pages.exclude_slug_for_subpages'; } - public function executeUpdate(): bool + protected function getExistingExcludedPages(): array { $conn = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('pages'); - $queryBuilder = $conn->createQueryBuilder(); $queryBuilder->getRestrictions()->removeAll(); $existingRows = $queryBuilder @@ -55,8 +54,18 @@ public function executeUpdate(): bool ) ->execute() ->fetchAll(); + + return array_column($existingRows, 'uid'); + + } + + public function executeUpdate(): bool + { + $conn = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('pages'); + $queryBuilder = $conn->createQueryBuilder(); + $queryBuilder->getRestrictions()->removeAll(); - $existingPages = array_column($existingRows, 'uid'); + $existingPages = $this->getExistingExcludedPages(); $conn->createQueryBuilder() ->update('pages') @@ -77,7 +86,7 @@ public function executeUpdate(): bool return true; } - public function updateNecessary(): bool + protected function doesRealurlFieldExist(): bool { $conn = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('pages'); $columns = $conn->getSchemaManager()->listTableColumns('pages'); @@ -89,6 +98,15 @@ public function updateNecessary(): bool return false; } + /** + * Upgrade is necessary if the environment has the "tx_realurl_exclude" column and + * there is at least one page having this field set to "1", else skip the wizard + */ + public function updateNecessary(): bool + { + return $this->doesRealurlFieldExist() && count($this->getExistingExcludedPages()) > 0; + } + public function getPrerequisites(): array { return [