From 2977654cd0c4caba35e749b92a506dce6970519d Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Mon, 2 Oct 2023 16:59:03 +0200 Subject: [PATCH 1/6] IBX-3957: Made NOP URL aliases reusable and original --- .../Legacy/Content/UrlAlias/Gateway/DoctrineDatabase.php | 2 +- eZ/Publish/Core/Persistence/Legacy/Content/UrlAlias/Handler.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabase.php b/eZ/Publish/Core/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabase.php index 1e403b8967..87af06be01 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabase.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabase.php @@ -603,7 +603,7 @@ public function insertRow(array $values): int $values['is_original'] = 1; } if ($values['action'] === self::NOP_ACTION) { - $values['is_original'] = 0; + $values['is_original'] = 1; } $query = $this->connection->createQueryBuilder(); diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/UrlAlias/Handler.php b/eZ/Publish/Core/Persistence/Legacy/Content/UrlAlias/Handler.php index d9b8fc48c8..9b1da114f9 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/UrlAlias/Handler.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/UrlAlias/Handler.php @@ -234,7 +234,6 @@ private function internalPublishUrlAliasForLocation( // 2. existing location or custom alias entry // 3. history entry if ( - $row['action'] === Gateway::NOP_ACTION || $row['action'] === $action || (int)$row['is_original'] === 0 ) { From 582d3ce7abe47ed9653ced13a73cb25cd122e712 Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Fri, 13 Oct 2023 14:02:18 +0200 Subject: [PATCH 2/6] IBX-3957: Added an integration test --- .../Repository/Tests/URLAliasServiceTest.php | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/eZ/Publish/API/Repository/Tests/URLAliasServiceTest.php b/eZ/Publish/API/Repository/Tests/URLAliasServiceTest.php index 0bb87cc2a8..6e2d1d8c63 100644 --- a/eZ/Publish/API/Repository/Tests/URLAliasServiceTest.php +++ b/eZ/Publish/API/Repository/Tests/URLAliasServiceTest.php @@ -1600,6 +1600,57 @@ public function testDeleteCorruptedUrlAliases() ); } + public function testRenamingParentContentDoesntBreakChildAlias(): void + { + $repository = $this->getRepository(); + $locationService = $repository->getLocationService(); + $urlAliasService = $repository->getURLAliasService(); + $contentTypeService = $repository->getContentTypeService(); + $contentService = $repository->getContentService(); + + $languageCode = 'eng-GB'; + $contentType = $contentTypeService->loadContentTypeByIdentifier('folder'); + + // 1. Create parent folder + $folderCreateStruct = $contentService->newContentCreateStruct($contentType, $languageCode); + $folderCreateStruct->setField('name', 'A'); + $folderDraft = $contentService->createContent($folderCreateStruct, [ + $locationService->newLocationCreateStruct(2), + ]); + $folder = $contentService->publishVersion($folderDraft->getVersionInfo()); + $folderLocation = $locationService->loadLocation($folder->contentInfo->getMainLocationId()); + + // 2. Create child folder + $childCreateStruct = $contentService->newContentCreateStruct($contentType, $languageCode); + $childCreateStruct->setField('title', 'B'); + $childDraft = $contentService->createContent($folderCreateStruct, [ + $locationService->newLocationCreateStruct($folderLocation->id), + ]); + $child = $contentService->publishVersion($childDraft->getVersionInfo()); + $childLocation = $locationService->loadLocation($child->contentInfo->getMainLocationId()); + + // 3. Create custom URL alias for child folder + $urlAliasService->createUrlAlias($childLocation, '/c/b', $languageCode); + $lookup = $urlAliasService->lookup('/c/b'); + + self::assertSame('/c/b', $lookup->path); + + // 4. Rename "A" to "C" + $folderDraft = $contentService->createContentDraft($folder->contentInfo); + $folderUpdateStruct = $contentService->newContentUpdateStruct(); + $folderUpdateStruct->setField('name', 'C'); + $renamedFolder = $contentService->updateContent($folderDraft->getVersionInfo(), $folderUpdateStruct); + $contentService->publishVersion($renamedFolder->getVersionInfo()); + + // Loading aliases shouldn't throw a `BadStateException` + $urlAliasService->listLocationAliases($childLocation); + + // Renamed content should have '/c2' path alias + $lookupRenamed = $urlAliasService->lookup('C2'); + + self::assertSame('/C2', $lookupRenamed->path); + } + /** * Mutate 'ezpublish.persistence.slug_converter' Service configuration. * From f9e27683489cc918d1f6f3bf78218e6bbbc28f35 Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Tue, 24 Oct 2023 15:55:06 +0200 Subject: [PATCH 3/6] IBX-3957: Updated `internalPublishUrlAliasForLocation`'s comments --- .../Core/Persistence/Legacy/Content/UrlAlias/Handler.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/UrlAlias/Handler.php b/eZ/Publish/Core/Persistence/Legacy/Content/UrlAlias/Handler.php index 9b1da114f9..782918f72c 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/UrlAlias/Handler.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/UrlAlias/Handler.php @@ -230,9 +230,8 @@ private function internalPublishUrlAliasForLocation( } // Row exists, check if it is reusable. There are 3 cases when this is possible: - // 1. NOP entry - // 2. existing location or custom alias entry - // 3. history entry + // 1. existing location or custom alias entry + // 2. history entry if ( $row['action'] === $action || (int)$row['is_original'] === 0 From cef062e14ecc43fdbed1df9b1dc151dabbe6e91c Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Tue, 24 Oct 2023 17:57:36 +0200 Subject: [PATCH 4/6] IBX-3957: Applied review remarks --- .../Repository/Tests/URLAliasServiceTest.php | 35 ++++++++----------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/eZ/Publish/API/Repository/Tests/URLAliasServiceTest.php b/eZ/Publish/API/Repository/Tests/URLAliasServiceTest.php index 6e2d1d8c63..d1f36a58f1 100644 --- a/eZ/Publish/API/Repository/Tests/URLAliasServiceTest.php +++ b/eZ/Publish/API/Repository/Tests/URLAliasServiceTest.php @@ -1605,50 +1605,45 @@ public function testRenamingParentContentDoesntBreakChildAlias(): void $repository = $this->getRepository(); $locationService = $repository->getLocationService(); $urlAliasService = $repository->getURLAliasService(); - $contentTypeService = $repository->getContentTypeService(); $contentService = $repository->getContentService(); $languageCode = 'eng-GB'; - $contentType = $contentTypeService->loadContentTypeByIdentifier('folder'); // 1. Create parent folder - $folderCreateStruct = $contentService->newContentCreateStruct($contentType, $languageCode); - $folderCreateStruct->setField('name', 'A'); - $folderDraft = $contentService->createContent($folderCreateStruct, [ - $locationService->newLocationCreateStruct(2), - ]); - $folder = $contentService->publishVersion($folderDraft->getVersionInfo()); - $folderLocation = $locationService->loadLocation($folder->contentInfo->getMainLocationId()); + $folder = $this->createFolder([$languageCode => 'a'], 2); + $folderLocationId = $folder->contentInfo->getMainLocationId(); // 2. Create child folder - $childCreateStruct = $contentService->newContentCreateStruct($contentType, $languageCode); - $childCreateStruct->setField('title', 'B'); - $childDraft = $contentService->createContent($folderCreateStruct, [ - $locationService->newLocationCreateStruct($folderLocation->id), - ]); - $child = $contentService->publishVersion($childDraft->getVersionInfo()); - $childLocation = $locationService->loadLocation($child->contentInfo->getMainLocationId()); + $child = $this->createFolder([$languageCode => 'b'], $folderLocationId); + $childLocationId = $child->contentInfo->getMainLocationId(); + $childLocation = $locationService->loadLocation($childLocationId); // 3. Create custom URL alias for child folder $urlAliasService->createUrlAlias($childLocation, '/c/b', $languageCode); $lookup = $urlAliasService->lookup('/c/b'); self::assertSame('/c/b', $lookup->path); + self::assertSame($childLocationId, $lookup->destination); // 4. Rename "A" to "C" $folderDraft = $contentService->createContentDraft($folder->contentInfo); $folderUpdateStruct = $contentService->newContentUpdateStruct(); - $folderUpdateStruct->setField('name', 'C'); + $folderUpdateStruct->setField('name', 'c'); $renamedFolder = $contentService->updateContent($folderDraft->getVersionInfo(), $folderUpdateStruct); $contentService->publishVersion($renamedFolder->getVersionInfo()); // Loading aliases shouldn't throw a `BadStateException` - $urlAliasService->listLocationAliases($childLocation); + $childLocationAliases = $urlAliasService->listLocationAliases($childLocation); + + self::assertCount(1, $childLocationAliases); + self::assertSame('/c/b', $childLocationAliases[0]->path); // Renamed content should have '/c2' path alias - $lookupRenamed = $urlAliasService->lookup('C2'); + $lookupRenamed = $urlAliasService->lookup('c2'); + $originalLookup = $urlAliasService->lookup('/c/b'); - self::assertSame('/C2', $lookupRenamed->path); + self::assertSame($childLocationId, $originalLookup->destination); + self::assertSame('/c2', $lookupRenamed->path); } /** From b545d4d3f33bb1a0302b21045f961ad46e94f242 Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Wed, 25 Oct 2023 11:59:03 +0200 Subject: [PATCH 5/6] IBX-3957: Applied review remarks --- eZ/Publish/API/Repository/Tests/URLAliasServiceTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/eZ/Publish/API/Repository/Tests/URLAliasServiceTest.php b/eZ/Publish/API/Repository/Tests/URLAliasServiceTest.php index d1f36a58f1..ce9cdd6c03 100644 --- a/eZ/Publish/API/Repository/Tests/URLAliasServiceTest.php +++ b/eZ/Publish/API/Repository/Tests/URLAliasServiceTest.php @@ -1615,8 +1615,8 @@ public function testRenamingParentContentDoesntBreakChildAlias(): void // 2. Create child folder $child = $this->createFolder([$languageCode => 'b'], $folderLocationId); - $childLocationId = $child->contentInfo->getMainLocationId(); - $childLocation = $locationService->loadLocation($childLocationId); + $childLocation = $child->getVersionInfo()->getContentInfo()->getMainLocation(); + $childLocationId = $childLocation->id; // 3. Create custom URL alias for child folder $urlAliasService->createUrlAlias($childLocation, '/c/b', $languageCode); From 7c46168c2ee74eeebc6cc2e31ba26d285ca9d544 Mon Sep 17 00:00:00 2001 From: Bartek Wajda Date: Wed, 25 Oct 2023 12:03:19 +0200 Subject: [PATCH 6/6] IBX-3957: CS --- eZ/Publish/API/Repository/Tests/URLAliasServiceTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/eZ/Publish/API/Repository/Tests/URLAliasServiceTest.php b/eZ/Publish/API/Repository/Tests/URLAliasServiceTest.php index ce9cdd6c03..200ab1ffaa 100644 --- a/eZ/Publish/API/Repository/Tests/URLAliasServiceTest.php +++ b/eZ/Publish/API/Repository/Tests/URLAliasServiceTest.php @@ -1603,7 +1603,6 @@ public function testDeleteCorruptedUrlAliases() public function testRenamingParentContentDoesntBreakChildAlias(): void { $repository = $this->getRepository(); - $locationService = $repository->getLocationService(); $urlAliasService = $repository->getURLAliasService(); $contentService = $repository->getContentService();