Skip to content

Commit

Permalink
Merge pull request #36 from cron-eu/fix-wizard
Browse files Browse the repository at this point in the history
[BUGFIX] Upgrade wizard SQL error when there is nothing to migrate
  • Loading branch information
o-ba authored Nov 29, 2023
2 parents da62860 + fe7ba57 commit a7c283d
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions Classes/Updates/MigrateRealUrlExcludeField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand All @@ -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');
Expand All @@ -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 [
Expand Down

0 comments on commit a7c283d

Please sign in to comment.