Skip to content

Commit

Permalink
BUGFIX: Ensure cache flushing for asset changes works with foreign wo…
Browse files Browse the repository at this point in the history
…rkspaces

This is done by flushing the caches inside inside a securityContext->withoutAuthorizationChecks closure.

Resolves: #5414
  • Loading branch information
mficzel committed Dec 25, 2024
1 parent e339da0 commit be73462
Showing 1 changed file with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\Flow\Persistence\PersistenceManagerInterface;
use Neos\Flow\Security\Context;
use Neos\Media\Domain\Model\AssetInterface;
use Neos\Media\Domain\Model\AssetVariantInterface;
use Neos\Neos\AssetUsage\Dto\AssetUsageFilter;
Expand All @@ -24,6 +25,7 @@ public function __construct(
protected readonly ContentRepositoryRegistry $contentRepositoryRegistry,
protected readonly PersistenceManagerInterface $persistenceManager,
protected readonly ContentCacheFlusher $contentCacheFlusher,
protected readonly Context $securityContext,
) {
}

Expand All @@ -46,30 +48,32 @@ public function registerAssetChange(AssetInterface $asset): void
->groupByNodeAggregate()
->includeVariantsOfAsset();

foreach ($this->globalAssetUsageService->findByFilter($filter) as $contentRepositoryId => $usages) {
$contentRepository = $this->contentRepositoryRegistry->get(ContentRepositoryId::fromString($contentRepositoryId));
$this->securityContext->withoutAuthorizationChecks(function () use ($filter) {
foreach ($this->globalAssetUsageService->findByFilter($filter) as $contentRepositoryId => $usages) {
$contentRepository = $this->contentRepositoryRegistry->get(ContentRepositoryId::fromString($contentRepositoryId));

foreach ($usages as $usage) {
$workspaceNames = $this->getWorkspaceNameAndChildWorkspaceNames($contentRepository, $usage->workspaceName);
foreach ($usages as $usage) {
$workspaceNames = $this->getWorkspaceNameAndChildWorkspaceNames($contentRepository, $usage->workspaceName);

foreach ($workspaceNames as $workspaceName) {
$contentGraph = $contentRepository->getContentGraph($workspaceName);
$nodeAggregate = $contentGraph->findNodeAggregateById($usage->nodeAggregateId);
if ($nodeAggregate === null) {
continue;
}
$flushNodeAggregateRequest = FlushNodeAggregateRequest::create(
$contentRepository->id,
$workspaceName,
$nodeAggregate->nodeAggregateId,
$nodeAggregate->nodeTypeName,
$contentGraph->findAncestorNodeAggregateIds($nodeAggregate->nodeAggregateId),
);
foreach ($workspaceNames as $workspaceName) {
$contentGraph = $contentRepository->getContentGraph($workspaceName);
$nodeAggregate = $contentGraph->findNodeAggregateById($usage->nodeAggregateId);
if ($nodeAggregate === null) {
continue;
}
$flushNodeAggregateRequest = FlushNodeAggregateRequest::create(
$contentRepository->id,
$workspaceName,
$nodeAggregate->nodeAggregateId,
$nodeAggregate->nodeTypeName,
$contentGraph->findAncestorNodeAggregateIds($nodeAggregate->nodeAggregateId),
);

$this->contentCacheFlusher->flushNodeAggregate($flushNodeAggregateRequest, CacheFlushingStrategy::ON_SHUTDOWN);
$this->contentCacheFlusher->flushNodeAggregate($flushNodeAggregateRequest, CacheFlushingStrategy::ON_SHUTDOWN);
}
}
}
}
});
}

/**
Expand Down

0 comments on commit be73462

Please sign in to comment.