Skip to content

Commit

Permalink
Fixed URL Alias cache invalidation for old achived entry
Browse files Browse the repository at this point in the history
  • Loading branch information
alongosz committed Aug 2, 2022
1 parent ba88a40 commit 50e8777
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ public function providerForUnCachedMethods(): array
[
['url_alias_location', [44], false],
['url_alias_location_path', [44], false],
['url_alias', ['44-abc'], false],
['url_alias_not_found', [], false],
],
null,
['urlal-44', 'urlalp-44', 'urlanf'],
['urlal-44', 'urlalp-44', 'urla-44-abc', 'urlanf'],
null,
'44-abc',
],
[
'createCustomUrlAlias',
Expand Down
7 changes: 5 additions & 2 deletions eZ/Publish/Core/Persistence/Cache/UrlAliasHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function publishUrlAliasForLocation(
$languageCode,
$alwaysAvailable = false,
$updatePathIdentificationString = false
) {
): string {
$this->logger->logCall(
__METHOD__,
[
Expand All @@ -53,7 +53,7 @@ public function publishUrlAliasForLocation(
]
);

$this->persistenceHandler->urlAliasHandler()->publishUrlAliasForLocation(
$urlAliasIdentity = $this->persistenceHandler->urlAliasHandler()->publishUrlAliasForLocation(
$locationId,
$parentLocationId,
$name,
Expand All @@ -65,8 +65,11 @@ public function publishUrlAliasForLocation(
$this->cache->invalidateTags([
$this->cacheIdentifierGenerator->generateTag(self::URL_ALIAS_LOCATION_IDENTIFIER, [$locationId]),
$this->cacheIdentifierGenerator->generateTag(self::URL_ALIAS_LOCATION_PATH_IDENTIFIER, [$locationId]),
$this->cacheIdentifierGenerator->generateTag(self::URL_ALIAS_IDENTIFIER, [$urlAliasIdentity]),
$this->cacheIdentifierGenerator->generateTag(self::URL_ALIAS_NOT_FOUND_IDENTIFIER),
]);

return $urlAliasIdentity;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ public function publishUrlAliasForLocation(
$languageCode,
$alwaysAvailable = false,
$updatePathIdentificationString = false
) {
): string {
$languageId = $this->languageHandler->loadByLanguageCode($languageCode)->id;

$this->internalPublishUrlAliasForLocation(
return $this->internalPublishUrlAliasForLocation(
$locationId,
$parentLocationId,
$name,
Expand Down Expand Up @@ -172,7 +172,7 @@ private function internalPublishUrlAliasForLocation(
$alwaysAvailable = false,
$updatePathIdentificationString = false,
$newId = null
) {
): string {
$parentId = $this->getRealAliasId($parentLocationId);
$name = $this->slugConverter->convert($name, 'location_' . $locationId);
$uniqueCounter = $this->slugConverter->getUniqueCounterValue($name, $parentId == 0);
Expand Down Expand Up @@ -300,6 +300,8 @@ private function internalPublishUrlAliasForLocation(
if ($cleanup) {
$this->gateway->cleanupAfterPublish($action, $languageId, $newId, $parentId, $newTextMD5);
}

return $this->mapper->generateIdentityKey($parentId, $newTextMD5);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function extractUrlAliasFromData($data)
$urlAlias = new UrlAlias();

list($type, $destination) = $this->matchTypeAndDestination($data['action']);
$urlAlias->id = $data['parent'] . '-' . $data['text_md5'];
$urlAlias->id = $this->generateIdentityKey((int)$data['parent'], $data['text_md5']);
$urlAlias->pathData = $this->normalizePathData($data['raw_path_data']);
$urlAlias->languageCodes = $this->languageMaskGenerator->extractLanguageCodesFromMask($data['lang_mask']);
$urlAlias->alwaysAvailable = $this->languageMaskGenerator->isAlwaysAvailable($data['lang_mask']);
Expand Down Expand Up @@ -90,6 +90,11 @@ public function extractLanguageCodesFromData(array $rows): array
return $this->languageMaskGenerator->extractLanguageCodesFromMask($languageMask);
}

public function generateIdentityKey(int $parentId, string $hash): string
{
return sprintf('%d-%s', $parentId, $hash);
}

/**
* @throws \RuntimeException
*
Expand Down
8 changes: 7 additions & 1 deletion eZ/Publish/SPI/Persistence/Content/UrlAlias/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,13 @@ interface Handler
* @param string $languageCode
* @param bool $alwaysAvailable
*/
public function publishUrlAliasForLocation($locationId, $parentLocationId, $name, $languageCode, $alwaysAvailable = false);
public function publishUrlAliasForLocation(
$locationId,
$parentLocationId,
$name,
$languageCode,
$alwaysAvailable = false
): string;

/**
* Create a user chosen $alias pointing to $locationId in $languageCode.
Expand Down

0 comments on commit 50e8777

Please sign in to comment.