Skip to content

Commit

Permalink
EZP-28883: Removing Translation from Draft corrupts all Url Aliases f…
Browse files Browse the repository at this point in the history
…or the removed Translation (#2262)

* EZP-28883: Fixed wrong SQL query constraints

* EZP-28883: Created integration test

* EZP-28883: Replaced Generator with array to avoid endless loop

Possible reason: It seems that SQLite driver executes query multiple times
which in conjunction with other operations in the transaction creates
an endless loop.
  • Loading branch information
slaci authored and Andrew Longosz committed Mar 2, 2018
1 parent 15067f9 commit b8cd3ea
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 4 deletions.
64 changes: 64 additions & 0 deletions eZ/Publish/API/Repository/Tests/ContentServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5414,6 +5414,11 @@ public function providerForDeleteTranslationFromDraftRemovesUrlAliasOnPublishing
* @dataProvider providerForDeleteTranslationFromDraftRemovesUrlAliasOnPublishing
*
* @param string[] $fieldValues translated field values
*
* @throws \eZ\Publish\API\Repository\Exceptions\BadStateException
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
*/
public function testDeleteTranslationFromDraftRemovesUrlAliasOnPublishing(array $fieldValues)
{
Expand Down Expand Up @@ -5476,6 +5481,65 @@ public function testDeleteTranslationFromDraftRemovesUrlAliasOnPublishing(array
}
}

/**
* Test that URL aliases for deleted Translations are properly archived.
*/
public function testDeleteTranslationFromDraftArchivesUrlAliasOnPublishing()
{
$repository = $this->getRepository();
$contentService = $repository->getContentService();
$urlAliasService = $repository->getURLAliasService();

$content = $contentService->publishVersion(
$this->createMultilingualContentDraft(
'folder',
2,
'eng-US',
[
'name' => [
'eng-GB' => 'BritishEnglishContent',
'eng-US' => 'AmericanEnglishContent',
],
]
)->versionInfo
);

$unrelatedContent = $contentService->publishVersion(
$this->createMultilingualContentDraft(
'folder',
2,
'eng-US',
[
'name' => [
'eng-GB' => 'AnotherBritishContent',
'eng-US' => 'AnotherAmericanContent',
],
]
)->versionInfo
);

$urlAlias = $urlAliasService->lookup('/BritishEnglishContent');
self::assertFalse($urlAlias->isHistory);
self::assertEquals($urlAlias->path, '/BritishEnglishContent');
self::assertEquals($urlAlias->destination, $content->contentInfo->mainLocationId);

$draft = $contentService->deleteTranslationFromDraft(
$contentService->createContentDraft($content->contentInfo)->versionInfo,
'eng-GB'
);
$content = $contentService->publishVersion($draft->versionInfo);

$urlAlias = $urlAliasService->lookup('/BritishEnglishContent');
self::assertTrue($urlAlias->isHistory);
self::assertEquals($urlAlias->path, '/BritishEnglishContent');
self::assertEquals($urlAlias->destination, $content->contentInfo->mainLocationId);

$unrelatedUrlAlias = $urlAliasService->lookup('/AnotherBritishContent');
self::assertFalse($unrelatedUrlAlias->isHistory);
self::assertEquals($unrelatedUrlAlias->path, '/AnotherBritishContent');
self::assertEquals($unrelatedUrlAlias->destination, $unrelatedContent->contentInfo->mainLocationId);
}

/**
* Test deleting a Translation from Draft which has single Translation throws BadStateException.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1250,14 +1250,14 @@ private function loadLocationEntriesMatchingMultipleLanguages($locationId, array
->from($this->table)
->where('action = :action')
// fetch rows matching any of the given Languages
->where('lang_mask & :languageMask <> 0')
->andWhere('lang_mask & :languageMask <> 0')
->setParameter(':action', 'eznode:' . $locationId)
->setParameter(':languageMask', $languageMask)
;

$statement = $query->execute();
while (false !== ($row = $statement->fetch(\PDO::FETCH_ASSOC))) {
yield $row;
}
$rows = $statement->fetchAll(\PDO::FETCH_ASSOC);

return $rows ?: [];
}
}

0 comments on commit b8cd3ea

Please sign in to comment.