Skip to content

Commit

Permalink
Merge pull request #816 from devmes/bugfix/809
Browse files Browse the repository at this point in the history
fix: pregenerate the slug entries incl. the counter
  • Loading branch information
lochmueller authored Oct 29, 2024
2 parents 3a5215f + 577076d commit 3e3d311
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion Classes/Service/IndexerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,16 @@ protected function insertAndUpdateNeededItems(
*/
protected function generateSlugAndInsert(array $neededItems, int $workspace = 0): void
{
$i = 0;
foreach ($neededItems as $item) {
if ($workspace) {
$item['t3ver_oid'] = 0;
}

$item['slug'] = $this->slugService->makeSlugUnique($item);
$item['slug'] = $this->slugService->makeSlugUnique($item, $i);
// We need to insert after each index, so subsequent indices do not get the same slug
$this->rawIndexRepository->insert($item);
$i++;
}
}

Expand Down
6 changes: 3 additions & 3 deletions Classes/Service/Url/SlugService.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ protected function generateSlugSuffix(string $uniqueRegisterKey, string $base, a
* Process the record and make the slug unique in the table, e.g. adds a suffix on duplicate.
*
* @param array $recordData
*
* @param int|null $counter
* @return string
*/
public function makeSlugUnique(array $recordData): string
public function makeSlugUnique(array $recordData, ?int $counter = null): string
{
// Create RecordState and generate slug
$state = $this->stateFactory->fromArray(
Expand All @@ -149,7 +149,7 @@ public function makeSlugUnique(array $recordData): string

/* @noinspection PhpUnhandledExceptionInspection */
return $this->getSlugHelper($recordData['t3ver_wsid'] ?? 0)
->buildSlugForUniqueInTable($recordData['slug'], $state);
->buildSlugForUniqueInTable($recordData['slug'] . ($counter ? '-' . $counter : ''), $state);
}

protected function getSlugHelper(int $workspaceId = 0): SlugHelper
Expand Down

0 comments on commit 3e3d311

Please sign in to comment.