Skip to content

Commit

Permalink
[BUGFIX] Exclude current record when checking slug's uniqueness
Browse files Browse the repository at this point in the history
The current record constraint was forgotten in the
implementation of uniqueInTable and is now added.

Resolves: #91378
Related: #91235
Releases: master, 9.5
Change-Id: Ie7862b22a06996a9d7ca484a01d7a1859c8f7276
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/64482
Tested-by: Helmut Hummel <typo3@helhum.io>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Helmut Hummel <typo3@helhum.io>
Reviewed-by: Susanne Moog <look@susi.dev>
Reviewed-by: Benni Mack <benni@typo3.org>
  • Loading branch information
xperseguers authored and bmack committed May 14, 2020
1 parent 5c48857 commit dab027b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
2 changes: 2 additions & 0 deletions typo3/sysext/core/Classes/DataHandling/SlugHelper.php
Expand Up @@ -335,10 +335,12 @@ public function isUniqueInSite(string $slug, RecordState $state): bool
*/
public function isUniqueInTable(string $slug, RecordState $state): bool
{
$recordId = $state->getSubject()->getIdentifier();
$languageId = $state->getContext()->getLanguageId();

$queryBuilder = $this->createPreparedQueryBuilder();
$this->applySlugConstraint($queryBuilder, $slug);
$this->applyRecordConstraint($queryBuilder, $recordId);
$this->applyLanguageConstraint($queryBuilder, $languageId);
$this->applyWorkspaceConstraint($queryBuilder, $state);
$statement = $queryBuilder->execute();
Expand Down
@@ -0,0 +1,6 @@
"pages",,,,
,"uid","pid","title","slug"
,1,0,"root","/"
,2,1,"Page One","/page-one"
,3,1,"Page Two","/page-two"
,4,1,"Page Two","/page-two-1"
@@ -0,0 +1,5 @@
"pages",,,,
,"uid","pid","title","slug"
,1,0,"root","/"
,2,1,"Page One","/page-one"
,3,1,"Page One","/page-one-1"
Expand Up @@ -30,7 +30,6 @@ protected function setUp(): void
{
parent::setUp();
$this->setUpFrontendSite(1);
$this->importCSVDataSet(__DIR__ . '/DataSet/TestSlugUniqueBase.csv');
}

/**
Expand All @@ -51,8 +50,9 @@ public function getEvalSettingDataProvider(): array
* @test
* @param string $uniqueSetting
*/
public function differentUniqueEvalSettingsDeDuplicateSlug(string $uniqueSetting)
public function differentUniqueEvalSettingsDeDuplicateSlug(string $uniqueSetting): void
{
$this->importCSVDataSet(__DIR__ . '/DataSet/TestSlugUniqueBase.csv');
$GLOBALS['TCA']['pages']['columns']['slug']['config']['eval'] = $uniqueSetting;
$dataHandler = GeneralUtility::makeInstance(DataHandler::class);
$dataHandler->enableLogging = false;
Expand All @@ -68,7 +68,60 @@ public function differentUniqueEvalSettingsDeDuplicateSlug(string $uniqueSetting
[]
);
$dataHandler->process_datamap();
$this->assertCSVDataSet('typo3/sysext/core/Tests/Functional/DataHandling/DataHandler/DataSet/TestSlugUniqueResult.csv');
}

/**
* @dataProvider getEvalSettingDataProvider
* @test
* @param string $uniqueSetting
*/
public function currentRecordIsExcludedWhenDeDuplicateSlug(string $uniqueSetting): void
{
$this->importCSVDataSet(__DIR__ . '/DataSet/TestSlugUniqueWithDeduplicatedSlugBase.csv');
$GLOBALS['TCA']['pages']['columns']['slug']['config']['eval'] = $uniqueSetting;
$dataHandler = GeneralUtility::makeInstance(DataHandler::class);
$dataHandler->enableLogging = false;
$dataHandler->start(
[
'pages' => [
3 => [
'slug' => 'page-one-1',
],
],
],
[]
);
$dataHandler->process_datamap();

$this->assertCSVDataSet('typo3/sysext/core/Tests/Functional/DataHandling/DataHandler/DataSet/TestSlugUniqueResult.csv');
}

/**
* @dataProvider getEvalSettingDataProvider
* @test
* @param string $uniqueSetting
*/
public function differentUniqueEvalSettingsDeDuplicateSlugWhenCreatingNewRecords(string $uniqueSetting): void
{
$this->importCSVDataSet(__DIR__ . '/DataSet/TestSlugUniqueBase.csv');
$GLOBALS['TCA']['pages']['columns']['slug']['config']['eval'] = $uniqueSetting;
$dataHandler = GeneralUtility::makeInstance(DataHandler::class);
$dataHandler->enableLogging = false;
$dataHandler->start(
[
'pages' => [
'NEW-1' => [
'pid' => 1,
'title' => 'Page Two',
'slug' => '',
],
],
],
[]
);
$dataHandler->process_datamap();

$this->assertCSVDataSet('typo3/sysext/core/Tests/Functional/DataHandling/DataHandler/DataSet/TestSlugUniqueNewRecordResult.csv');
}
}

0 comments on commit dab027b

Please sign in to comment.