Skip to content

Commit

Permalink
[BUGFIX] Use default page id for fetching a site in SlugService
Browse files Browse the repository at this point in the history
The rebuildSlugsForSlugChange function of SlugService updates
slugs of sub pages and also creates redirects for them, after
changing the slug of their parent page. This process requires
to fetch the corresponding site configuration.

In cases like changing the slug of a localized root page
this throws a SiteNotFoundException, because the site is
always mapped to the default page id which can not be
determined for localized root pages because their pid is 0.

It's therefore necessary to always use the default page
id for fetching the site through SiteFinder.

Resolves: #92733
Releases: master, 10.4
Change-Id: I8b41647d63d444982b2d2d6f209dea4278034488
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/66341
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
  • Loading branch information
o-ba authored and andreaskienast committed Oct 30, 2020
1 parent ffca74d commit 8b191e5
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 1 deletion.
3 changes: 2 additions & 1 deletion typo3/sysext/redirects/Classes/Service/SlugService.php
Expand Up @@ -121,7 +121,8 @@ public function rebuildSlugsForSlugChange(int $pageId, string $currentSlug, stri
if ($currentPageRecord === null) {
return;
}
$this->initializeSettings($pageId);
$defaultPageId = (int)$currentPageRecord['sys_language_uid'] > 0 ? (int)$currentPageRecord['l10n_parent'] : $pageId;
$this->initializeSettings($defaultPageId);
if ($this->autoUpdateSlugs || $this->autoCreateRedirects) {
$this->createCorrelationIds($pageId, $correlationId);
if ($this->autoCreateRedirects) {
Expand Down
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<dataset>
<pages>
<uid>1</uid>
<pid>0</pid>
<title>Root 1</title>
<slug>/</slug>
</pages>
<pages>
<uid>2</uid>
<pid>1</pid>
<title>Dummy 1-2</title>
<slug>/dummy-1-2</slug>
</pages>
<pages>
<uid>3</uid>
<pid>1</pid>
<title>Dummy 1-3</title>
<slug>/dummy-1-3</slug>
</pages>
<pages>
<uid>4</uid>
<pid>2</pid>
<title>Dummy 1-2-3</title>
<slug>/dummy-1-2/dummy-1-2-3</slug>
</pages>
<pages>
<uid>5</uid>
<pid>0</pid>
<title>Root 1 german</title>
<slug>/</slug>
<l10n_parent>1</l10n_parent>
<l10n_source>1</l10n_source>
<sys_language_uid>1</sys_language_uid>
</pages>
<pages>
<uid>6</uid>
<pid>1</pid>
<title>Dummy 1-2 german</title>
<slug>/dummy-1-2</slug>
<l10n_parent>2</l10n_parent>
<l10n_source>2</l10n_source>
<sys_language_uid>1</sys_language_uid>
</pages>
<pages>
<uid>7</uid>
<pid>1</pid>
<title>Dummy 1-3 german</title>
<slug>/dummy-1-3</slug>
<l10n_parent>3</l10n_parent>
<l10n_source>3</l10n_source>
<sys_language_uid>1</sys_language_uid>
</pages>
<pages>
<uid>8</uid>
<pid>2</pid>
<title>Dummy 1-2-3 german</title>
<slug>/dummy-1-2/dummy-1-2-3</slug>
<l10n_parent>4</l10n_parent>
<l10n_source>4</l10n_source>
<sys_language_uid>1</sys_language_uid>
</pages>
</dataset>
Expand Up @@ -290,6 +290,43 @@ public function rebuildSlugsForSlugChangeRenamesSubSlugsAndCreatesRedirectsWithL
$this->assertSlugsAndRedirectsExists($slugs, $redirects);
}

/**
* This test should prove, that a renaming of a subtree works as expected
* and all slugs of sub pages are renamed and redirects are created.
*
* We test here that rebuildSlugsForSlugChange works when changing a L>0 siteroot which has pid=0
* @test
*/
public function rebuildSlugsForSlugChangeRenamesSubSlugsAndCreatesRedirectsWithLanguagesForSiteroot(): void
{
$this->buildBaseSiteWithLanguages();
$this->createSubject();
$this->importDataSet(__DIR__ . '/Fixtures/SlugServiceTest_pages_test4.xml');
$this->subject->rebuildSlugsForSlugChange(5, '/', '/test-new', $this->correlationId);

// These are the slugs after rebuildSlugsForSlugChange() has run
$slugs = [
'/',
'/dummy-1-2',
'/dummy-1-3',
'/dummy-1-2/dummy-1-2-3',
'/test-new',
'/test-new/dummy-1-2',
'/test-new/dummy-1-3',
'/test-new/dummy-1-2/dummy-1-2-3'
];

// This redirects should exists, after rebuildSlugsForSlugChange() has run
$redirects = [
['source_path' => '/de/', 'target' => '/de/test-new'],
['source_path' => '/de/dummy-1-2', 'target' => '/de/test-new/dummy-1-2'],
['source_path' => '/de/dummy-1-3', 'target' => '/de/test-new/dummy-1-3'],
['source_path' => '/de/dummy-1-2/dummy-1-2-3', 'target' => '/de/test-new/dummy-1-2/dummy-1-2-3'],
];

$this->assertSlugsAndRedirectsExists($slugs, $redirects);
}

protected function buildBaseSite(): void
{
$configuration = [
Expand Down

0 comments on commit 8b191e5

Please sign in to comment.