Project

General

Profile

Actions

Bug #98456

closed

Slug generation for language ID -1

Added by Florian Leimer almost 2 years ago. Updated 8 days ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
DataHandler aka TCEmain
Start date:
2022-09-28
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
10
PHP Version:
7.4
Tags:
slug
Complexity:
easy
Is Regression:
Sprint Focus:

Description

When creating an unique slug the language id is considered. At the moment there isn't any logic for the language id "-1" (all languages) and it is treated like any other language. This is a problem because it is possible that a record with a specific language and one with "all languages" can have the same slug.
I encountered this problem with EXT:news, where the routing wasn't able to get the correct uid.

My fix in \TYPO3\CMS\Core\DataHandling\SlugHelper:

/**
 * @param QueryBuilder $queryBuilder
 * @param int $languageId
 */
protected function applyLanguageConstraint(QueryBuilder $queryBuilder, int $languageId)
{
    $languageFieldName = $GLOBALS['TCA'][$this->tableName]['ctrl']['languageField'] ?? null;
    if (!is_string($languageFieldName)) {
        return;
    }

    if ($languageId === -1) {
        return;
    }

    // Only check records of the given language
    $queryBuilder->andWhere(
        $queryBuilder->expr()->orX(
            $queryBuilder->expr()->eq(
                $languageFieldName,
                $queryBuilder->createNamedParameter($languageId, \PDO::PARAM_INT)
            ),
            $queryBuilder->expr()->eq(
                $languageFieldName,
                $queryBuilder->createNamedParameter(-1, \PDO::PARAM_INT)
            )
        )
    );
}


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Bug #99529: Duplicate slugs with collisions using TCA type "slug" and records with sys_language_uid = -1Closed2023-01-12

Actions
Actions #1

Updated by Florian Leimer almost 2 years ago

  • Category set to DataHandler aka TCEmain
  • Target version set to Candidate for patchlevel
Actions #2

Updated by Florian Leimer almost 2 years ago

  • Description updated (diff)
Actions #3

Updated by Stefan Bürk almost 2 years ago

Don't get this ... if $languageId is -1 it will early return ... and below the querybuild makes an or query ? Will not hit if $languageId is -1. Beside this, if $languageId is -1, and the early return would not be there .... it will also select the -1 language record $ith the $languageId query (if it exists).

Not sure .. will the query not return than all langauge records ?

In the end . that may not be the end result. For example, if you have a a news translated into 2 or 3 languages with slug "my-news", than another news record with language -1 and slug "my-news" ... even if this gets properly changed to "my-news-1" to be "unique" ... this already should checked against all languages.

On the other hand, other language should check -1 records too - ah that's the or query part then.

This should be covered by kind some tests then ....

Actions #4

Updated by Florian Leimer almost 2 years ago

If the language of the current record (for which the slug should be generated) is -1 then every slug of every record no matter which language should be checked. That's what the early return is for.
If the language is something else then every slug of every record in this language and in the language -1 should be checked. That's the OR part in the query.

We currently have this active on a production site and it works without any problems.

Actions #5

Updated by Georg Ringer 12 days ago

  • Status changed from New to Resolved

resolved with #99529

Actions #6

Updated by Georg Ringer 12 days ago

  • Related to Bug #99529: Duplicate slugs with collisions using TCA type "slug" and records with sys_language_uid = -1 added
Actions #7

Updated by Benni Mack 8 days ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF