Skip to content

Commit ee1b0cf

Browse files
authored
IBX-1201: Added handling of already generated aliases during subtree copying
For more details see https://issues.ibexa.co/browse/IBX-1201 and ezsystems/ezpublish-kernel#3127 * Added handling of already generated aliases during subtree copying * Added integration test
1 parent e9ca8b1 commit ee1b0cf

File tree

2 files changed

+76
-5
lines changed

2 files changed

+76
-5
lines changed

eZ/Publish/API/Repository/Tests/LocationServiceTest.php

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use eZ\Publish\API\Repository\Values\Content\Query;
2222
use eZ\Publish\API\Repository\Values\Content\Search\SearchHit;
2323
use eZ\Publish\API\Repository\Values\Content\URLAlias;
24+
use eZ\Publish\Core\Repository\Values\Content\ContentUpdateStruct;
2425

2526
/**
2627
* Test case for operations in the LocationService using in memory storage.
@@ -2384,6 +2385,62 @@ public function testCopySubtreeWithAliases()
23842385
$this->assertGeneratedAliases($urlAliasService, $expectedSubItemAliases);
23852386
}
23862387

2388+
/**
2389+
* @covers \eZ\Publish\API\Repository\LocationService::copySubtree
2390+
*/
2391+
public function testCopySubtreeWithTranslatedContent(): void
2392+
{
2393+
$repository = $this->getRepository();
2394+
$contentService = $repository->getContentService();
2395+
$contentTypeService = $repository->getContentTypeService();
2396+
$locationService = $repository->getLocationService();
2397+
$urlAliasService = $repository->getURLAliasService();
2398+
2399+
$mediaLocationId = $this->generateId('location', 43);
2400+
$filesLocationId = $this->generateId('location', 52);
2401+
$demoDesignLocationId = $this->generateId('location', 56);
2402+
2403+
$locationToCopy = $locationService->loadLocation($mediaLocationId);
2404+
$filesLocation = $locationService->loadLocation($filesLocationId);
2405+
$newParentLocation = $locationService->loadLocation($demoDesignLocationId);
2406+
2407+
// translating the 'middle' folder
2408+
$translatedDraft = $contentService->createContentDraft($filesLocation->contentInfo);
2409+
$contentUpdateStruct = new ContentUpdateStruct([
2410+
'initialLanguageCode' => 'ger-DE',
2411+
'fields' => $translatedDraft->getFields(),
2412+
]);
2413+
$contentUpdateStruct->setField('short_name', 'FilesGER', 'ger-DE');
2414+
$translatedContent = $contentService->updateContent($translatedDraft->versionInfo, $contentUpdateStruct);
2415+
$contentService->publishVersion($translatedContent->versionInfo);
2416+
2417+
// creating additional content under translated folder
2418+
$contentType = $contentTypeService->loadContentTypeByIdentifier('folder');
2419+
$contentCreate = $contentService->newContentCreateStruct($contentType, 'eng-GB');
2420+
$contentCreate->setField('name', 'My folder');
2421+
$content = $contentService->createContent(
2422+
$contentCreate,
2423+
[new LocationCreateStruct(['parentLocationId' => $filesLocationId])]
2424+
);
2425+
$contentService->publishVersion($content->versionInfo);
2426+
2427+
$expectedSubItemAliases = [
2428+
'/Design/Plain-site/Media/Multimedia',
2429+
'/Design/Plain-site/Media/Images',
2430+
'/Design/Plain-site/Media/Files',
2431+
'/Design/Plain-site/Media/Files/my-folder',
2432+
];
2433+
2434+
$this->assertAliasesBeforeCopy($urlAliasService, $expectedSubItemAliases);
2435+
2436+
$locationService->copySubtree(
2437+
$locationToCopy,
2438+
$newParentLocation
2439+
);
2440+
2441+
$this->assertGeneratedAliases($urlAliasService, $expectedSubItemAliases);
2442+
}
2443+
23872444
/**
23882445
* Asserts that given Content has default ContentStates.
23892446
*

eZ/Publish/Core/Persistence/Legacy/Content/UrlAlias/Handler.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -957,12 +957,18 @@ protected function getRealAliasId($locationId)
957957
* @param array $actionMap
958958
* @param mixed $oldParentAliasId
959959
* @param mixed $newParentAliasId
960+
* @param string[] $alreadyGeneratedAliases
960961
*/
961-
protected function copySubtree($actionMap, $oldParentAliasId, $newParentAliasId)
962+
protected function copySubtree($actionMap, $oldParentAliasId, $newParentAliasId, array $alreadyGeneratedAliases = []): array
962963
{
963964
$rows = $this->gateway->loadAutogeneratedEntries($oldParentAliasId);
964965
$newIdsMap = [];
965966
foreach ($rows as $row) {
967+
$identifier = $row['parent'] . $row['text_md5'];
968+
if (in_array($identifier, $alreadyGeneratedAliases)) {
969+
continue;
970+
}
971+
966972
$oldParentAliasId = $row['id'];
967973

968974
// Ensure that same action entries remain grouped by the same id
@@ -975,12 +981,20 @@ protected function copySubtree($actionMap, $oldParentAliasId, $newParentAliasId)
975981
$row['id'] = $row['link'] = $newIdsMap[$oldParentAliasId];
976982
$this->gateway->insertRow($row);
977983

978-
$this->copySubtree(
979-
$actionMap,
980-
$oldParentAliasId,
981-
$row['id']
984+
$alreadyGeneratedAliases[] = $identifier;
985+
986+
$alreadyGeneratedAliases = array_merge(
987+
$alreadyGeneratedAliases,
988+
$this->copySubtree(
989+
$actionMap,
990+
$oldParentAliasId,
991+
$row['id'],
992+
$alreadyGeneratedAliases
993+
)
982994
);
983995
}
996+
997+
return $alreadyGeneratedAliases;
984998
}
985999

9861000
/**

0 commit comments

Comments
 (0)