Skip to content

Commit

Permalink
Merge pull request neos#5415 from mficzel/bugfix/fixCacheFlushingForA…
Browse files Browse the repository at this point in the history
…ssetsInForeignWorlspaces

BUGFIX: Ensure cache flushing for asset changes works with foreign workspaces
  • Loading branch information
nezaniel authored Jan 7, 2025
2 parents 6c038fb + be73462 commit f20b28c
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 f20b28c

Please sign in to comment.