Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-3957: Made NOP URL aliases not reusable and original #385

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions eZ/Publish/API/Repository/Tests/URLAliasServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1600,6 +1600,51 @@ public function testDeleteCorruptedUrlAliases()
);
}

public function testRenamingParentContentDoesntBreakChildAlias(): void
{
$repository = $this->getRepository();
$urlAliasService = $repository->getURLAliasService();
$contentService = $repository->getContentService();

$languageCode = 'eng-GB';

// 1. Create parent folder
$folder = $this->createFolder([$languageCode => 'a'], 2);
$folderLocationId = $folder->contentInfo->getMainLocationId();

// 2. Create child folder
$child = $this->createFolder([$languageCode => 'b'], $folderLocationId);
$childLocation = $child->getVersionInfo()->getContentInfo()->getMainLocation();
$childLocationId = $childLocation->id;

// 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);
barw4 marked this conversation as resolved.
Show resolved Hide resolved
barw4 marked this conversation as resolved.
Show resolved Hide resolved
self::assertSame($childLocationId, $lookup->destination);

// 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`
$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');
$originalLookup = $urlAliasService->lookup('/c/b');

self::assertSame($childLocationId, $originalLookup->destination);
self::assertSame('/c2', $lookupRenamed->path);
}

/**
* Mutate 'ezpublish.persistence.slug_converter' Service configuration.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,9 @@ 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'] === Gateway::NOP_ACTION ||
$row['action'] === $action ||
(int)$row['is_original'] === 0
) {
Expand Down
Loading