Skip to content

Commit

Permalink
[FEATURE] Provide migration for old Fluidpages backend layout selection
Browse files Browse the repository at this point in the history
Provides a migration as extension upgrade script for page
records which had Fluidpages-specific selection values
in either "backend_layout" or "backend_layout_next_level".

Only available if Fluidpages has been uninstalled first.

Thanks to @typoworx-de for the initial SQL query.

References: #1779
References: #1753
  • Loading branch information
NamelessCoder committed May 21, 2020
1 parent e70576d commit 89f1dbf
Showing 1 changed file with 62 additions and 2 deletions.
64 changes: 62 additions & 2 deletions class.ext_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class ext_update
*/
public function access()
{
return $this->validatePresenceOfLegacyFieldsInDatabaseSchema();
return $this->validatePresenceOfLegacyFieldsInDatabaseSchema()
|| !empty($this->detectFluidPagesNotInstalledAndBackendLayoutFieldsReferenceFluidpages());
}

/**
Expand Down Expand Up @@ -92,6 +93,11 @@ public function main()
}

if ($performMigration) {
$migratedPageRecords = $this->detectFluidPagesNotInstalledAndBackendLayoutFieldsReferenceFluidpages();
if (!empty($migratedPageRecords)) {
$this->updateBackendLayoutSelection();
}

// Integrity check and data gathering loop. Verify that all records which have a Provider which returns a Grid,
// are able to load the template that is associated with it. Failure to load the template gets analysed and the
// reason gets reported; if the reason is "required argument colPos not used on flux:grid.column" the failure
Expand Down Expand Up @@ -177,13 +183,55 @@ public function main()
'templatesWithErrors' => $this->removeBasePathFromKeys($templateFilesWithErrors),
'templateFilesRequiringMigration' => $this->removeBasePathFromKeys($templateFilesRequiringMigration),
'migratedChildContent' => $migratedChildContent,
'migratedPageRecords' => $migratedPageRecords,
'notMigratedChildContentUids' => $notMigratedChildContentUids,
]
);

return $view->render();
}

protected function detectFluidPagesNotInstalledAndBackendLayoutFieldsReferenceFluidpages(): array
{
if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('fluidpages')) {
return false;
}
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
$queryBuilder->getRestrictions()->removeAll();
$queryBuilder->select('uid')->from('pages')->where(
$queryBuilder->expr()->orX(
$queryBuilder->expr()->eq('backend_layout', $queryBuilder->createNamedParameter('fluidpages__fluidpages', \PDO::PARAM_STR)),
$queryBuilder->expr()->eq('backend_layout_next_level', $queryBuilder->createNamedParameter('fluidpages__fluidpages', \PDO::PARAM_STR)),
$queryBuilder->expr()->eq('backend_layout', $queryBuilder->createNamedParameter('fluidpages__grid', \PDO::PARAM_STR)),
$queryBuilder->expr()->eq('backend_layout_next_level', $queryBuilder->createNamedParameter('fluidpages__grid', \PDO::PARAM_STR)),
)
);
return $queryBuilder->execute()->fetchAll();
}

protected function updateBackendLayoutSelection(): void
{
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
$queryBuilder->getRestrictions()->removeAll();
$queryBuilder->update('pages');
$q1 = clone $queryBuilder;
$q2 = clone $queryBuilder;
$q1->set('backend_layout', 'flux__grid')
->where(
$q1->expr()->orX(
$q1->expr()->eq('backend_layout', $q1->createNamedParameter('fluidpages__fluidpages', \PDO::PARAM_STR)),
$q1->expr()->eq('backend_layout_next_level', $q1->createNamedParameter('fluidpages__grid', \PDO::PARAM_STR))
)
)->execute();
$q2->set('backend_layout_next_level', 'flux__grid')
->where(
$q2->expr()->orX(
$q2->expr()->eq('backend_layout_next_level', $q2->createNamedParameter('fluidpages__fluidpages', \PDO::PARAM_STR)),
$q2->expr()->eq('backend_layout_next_level', $q2->createNamedParameter('fluidpages__grid', \PDO::PARAM_STR))
)
)->execute();
}

protected function removeBasePathFromKeys(array $values)
{
$basePath = GeneralUtility::getIndpEnv('TYPO3_DOCUMENT_ROOT');
Expand Down Expand Up @@ -313,6 +361,18 @@ protected function getFluidTemplateSource(): string
<f:if condition="{performMigration}">
<h3>Migration results</h3>
<f:if condition="{migratedPageRecords -> f:count()}">
<f:then>
<ul>
<f:for each="{migratedPageRecords}" as="migratedRecord">
<li>pages:{migratedRecord.uid} has new backend layout selection "flux__grid" where either "fluidpages__grid" or "fluidpages__fluidpages" was selected.</li>
</f:for>
</ul>
</f:then>
<f:else>
<p>No content records were migrated</p>
</f:else>
</f:if>
<f:if condition="{migratedChildContent -> f:count()}">
<f:then>
<ul>
Expand All @@ -322,7 +382,7 @@ protected function getFluidTemplateSource(): string
</ul>
</f:then>
<f:else>
<p>No records were migrated</p>
<p>No content records were migrated</p>
</f:else>
</f:if>
Expand Down

0 comments on commit 89f1dbf

Please sign in to comment.