Skip to content

Commit

Permalink
Adapted clearing persistance tags after the refactoring (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
mnocon authored Sep 16, 2021
1 parent acb8c97 commit 302fee9
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions API/Facade/ContentTypeFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,32 @@
use eZ\Publish\API\Repository\Values\ContentType\ContentType;
use eZ\Publish\API\Repository\Values\ContentType\ContentTypeGroup;
use EzSystems\EzPlatformAdminUi\Behat\PageElement\Fields\EzFieldElement;
use Ibexa\Core\Persistence\Cache\Tag\CacheIdentifierGeneratorInterface;
use Symfony\Component\Cache\Adapter\TagAwareAdapterInterface;

class ContentTypeFacade
{
private const CONTENT_TYPE_LIST_BY_GROUP_IDENTIFIER = 'content_type_list_by_group';

/** @var \eZ\Publish\API\Repository\ContentTypeService */
private $contentTypeService;

/** @var Symfony\Component\Cache\Adapter\TagAwareAdapterInterface */
private $cachePool;

/** @var Ibexa\Core\Persistence\Cache\Tag\CacheIdentifierGeneratorInterface */
private $cacheIdentifierGenerator;

private const MAX_LOAD_TRIES = 10;

public function __construct(ContentTypeService $contentTypeService, TagAwareAdapterInterface $cachePool)
{
public function __construct(
ContentTypeService $contentTypeService,
TagAwareAdapterInterface $cachePool,
CacheIdentifierGeneratorInterface $cacheIdentifierGenerator
) {
$this->contentTypeService = $contentTypeService;
$this->cachePool = $cachePool;
$this->cacheIdentifierGenerator = $cacheIdentifierGenerator;
}

public function createContentType(string $contentTypeName, string $contentTypeIdentifier, string $contentTypeGroupName, string $mainLanguageCode, bool $isContainer, array $fieldDefinitions)
Expand Down Expand Up @@ -81,8 +91,14 @@ private function assertContentTypeExistsInGroup(string $contentTypeIdentifier, C

$iterationsCount = 0;

$cacheKey = $this->cacheIdentifierGenerator->generateKey(
self::CONTENT_TYPE_LIST_BY_GROUP_IDENTIFIER,
[$contentTypeGroup->id],
true
);

while (!\in_array($contentTypeIdentifier, $contentTypeIdentifiersInGroup)) {
$this->cachePool->deleteItems(['ez-content-type-list-by-group-' . $contentTypeGroup->id]);
$this->cachePool->deleteItems([$cacheKey]);

$contentTypeIdentifiersInGroup = array_map(function (ContentType $contentType) {
return $contentType->identifier;
Expand Down

0 comments on commit 302fee9

Please sign in to comment.