Bug #89964

PopulatePageSlugs.php should use order in query of getSuggestedSlugs

Added by Herman Kremer 2 months ago. Updated about 2 months ago.

Status:
Resolved
Priority:
Should have
Assignee:
-
Category:
Install Tool
Target version:
Start date:
2019-12-16
Due date:
% Done:

100%

TYPO3 Version:
9
PHP Version:
7.2
Tags:
Complexity:
easy
Is Regression:
Sprint Focus:

Description

The populate page slugs functionality in de upgrade wizard does not work correct for pages with multiple titel adjustments.
Realurl keeps for every page titel change a record in tx_realurl_pathdata.
In order to get the latest change a order should be added to the query in getSuggestedSlugs:

Add ->orderBy('expire', 'DESC')

   /**
     * Resolve prepared realurl "pagepath" for pages
     *
     * @param string $tableName
     * @return array with pageID (default language) and language ID as two-dimensional array containing the page path
     */
    protected function getSuggestedSlugs(string $tableName): array
    {
        $context = GeneralUtility::makeInstance(Context::class);
        $currentTimestamp = $context->getPropertyFromAspect('date', 'timestamp');

        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($tableName);
        $statement = $queryBuilder
            ->select('*')
            ->from($tableName)
            ->where(
                $queryBuilder->expr()->eq('mpvar', $queryBuilder->createNamedParameter('')),
                $queryBuilder->expr()->orX(
                    $queryBuilder->expr()->eq('expire', $queryBuilder->createNamedParameter(0)),
                    $queryBuilder->expr()->gt('expire', $queryBuilder->createNamedParameter($currentTimestamp))
                )
            )
 ++         ->orderBy('expire', 'DESC')
            ->execute();
        $suggestedSlugs = [];
        while ($row = $statement->fetch()) {
            // rawurldecode ensures that non-ASCII arguments are also migrated
            $pagePath = rawurldecode($row['pagepath']);
            if (!isset($suggestedSlugs[(int)$row['page_id']][(int)$row['language_id']])) { // keep only first result
                $suggestedSlugs[(int)$row['page_id']][(int)$row['language_id']] = '/' . trim($pagePath, '/');
            }
        }
        return $suggestedSlugs;
    }

Schermafbeelding 2019-12-16 om 14.30.57.png View (96.1 KB) Herman Kremer, 2019-12-16 14:31


Related issues

Related to TYPO3 Core - Task #89194: Upgrade wizard for slugs optimizations Resolved 2019-09-18

Associated revisions

Revision a28c475e (diff)
Added by Herman Kremer about 2 months ago

[BUGFIX] PopulatePageSlugs return the most recent slug

The populate page slugs functionality in de upgrade wizard does not
work correct for pages with multiple title adjustments.

Realurl keeps for every page title change a record in
tx_realurl_pathdata.

In order to get the latest change a order should be added to the
query in getSuggestedSlugs.

Resolves: #89964
Releases: master, 9.5
Change-Id: I4b7fad14fc559e6c9e8a4fb6f6a2a112a290d7e2
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62754
Tested-by: TYPO3com <>
Tested-by: Guido Schmechel <>
Tested-by: Benni Mack <>
Reviewed-by: Guido Schmechel <>
Reviewed-by: Daniel Haupt <>
Reviewed-by: Benni Mack <>

Revision f13f60ea (diff)
Added by Herman Kremer about 2 months ago

[BUGFIX] PopulatePageSlugs return the most recent slug

The populate page slugs functionality in de upgrade wizard does not
work correct for pages with multiple title adjustments.

Realurl keeps for every page title change a record in
tx_realurl_pathdata.

In order to get the latest change a order should be added to the
query in getSuggestedSlugs.

Resolves: #89964
Releases: master, 9.5
Change-Id: I4b7fad14fc559e6c9e8a4fb6f6a2a112a290d7e2
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62795
Tested-by: TYPO3com <>
Tested-by: Benni Mack <>
Reviewed-by: Benni Mack <>

Revision 0311f671 (diff)
Added by Sybille Peters about 1 month ago

[BUGFIX] Use latest slug in PopulatePageSlug

PopulatePageSlug is an upgrade wizard which migrates existing slugs
from realurl tables to the table pages.slug.

In realurl, when the page title changed, the realurl slug changed
(if not fixed). Realurl handled this by adding temporary entries to
its tables which would be used to redirect the URL to its new location.
These entries had a fixed expiration date (expire > 0). The final
slug had no expiration date (expire = 0)

The previous behaviour in PopulatePageSlug preferred entries from
tx_realurl_pathdata with an expiration date (expire > 0) over
entries without (expire = 0). This would prefer (temporary) entries
that were only used for the redirects over the final slug.

This patch uses the 'uid' for sorting in descending order, which
will always use the latest entry for a specific page / language
combinations.

Resolves: #89194
Related: #89964
Releases: master, 9.5
Change-Id: Ica18bf5c6df9d101ccfce7712eae9c979e558a11
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/61719
Tested-by: TYPO3com <>
Tested-by: Albrecht Koehnlein <>
Tested-by: Sascha Rademacher <>
Tested-by: Frank Nägler <>
Reviewed-by: Albrecht Koehnlein <>
Reviewed-by: Sascha Rademacher <>
Reviewed-by: Frank Nägler <>

Revision 8758e9e6 (diff)
Added by Sybille Peters about 1 month ago

[BUGFIX] Use latest slug in PopulatePageSlug

PopulatePageSlug is an upgrade wizard which migrates existing slugs
from realurl tables to the table pages.slug.

In realurl, when the page title changed, the realurl slug changed
(if not fixed). Realurl handled this by adding temporary entries to
its tables which would be used to redirect the URL to its new location.
These entries had a fixed expiration date (expire > 0). The final
slug had no expiration date (expire = 0)

The previous behaviour in PopulatePageSlug preferred entries from
tx_realurl_pathdata with an expiration date (expire > 0) over
entries without (expire = 0). This would prefer (temporary) entries
that were only used for the redirects over the final slug.

This patch uses the 'uid' for sorting in descending order, which
will always use the latest entry for a specific page / language
combinations.

Resolves: #89194
Related: #89964
Releases: master, 9.5
Change-Id: Ica18bf5c6df9d101ccfce7712eae9c979e558a11
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62942
Tested-by: TYPO3com <>
Tested-by: Frank Nägler <>
Reviewed-by: Frank Nägler <>

History

#2 Updated by Guido Schmechel 2 months ago

Hello Herman, maybe you want to contribute this change? You find further information at https://docs.typo3.org/m/typo3/guide-contributionworkflow/master/en-us/

#3 Updated by Gerrit Code Review 2 months ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/62754

#4 Updated by Gerrit Code Review 2 months ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/62754

#5 Updated by Gerrit Code Review about 2 months ago

Patch set 1 for branch 9.5 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/62795

#6 Updated by Herman Kremer about 2 months ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

#7 Updated by Benni Mack about 1 month ago

  • Related to Task #89194: Upgrade wizard for slugs optimizations added

Also available in: Atom PDF