Skip to content

Commit f20b28c

Browse files
authored
Merge pull request neos#5415 from mficzel/bugfix/fixCacheFlushingForAssetsInForeignWorlspaces
BUGFIX: Ensure cache flushing for asset changes works with foreign workspaces
2 parents 6c038fb + be73462 commit f20b28c

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

Neos.Neos/Classes/Fusion/Cache/AssetChangeHandlerForCacheFlushing.php

+23-19
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
1010
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
1111
use Neos\Flow\Persistence\PersistenceManagerInterface;
12+
use Neos\Flow\Security\Context;
1213
use Neos\Media\Domain\Model\AssetInterface;
1314
use Neos\Media\Domain\Model\AssetVariantInterface;
1415
use Neos\Neos\AssetUsage\Dto\AssetUsageFilter;
@@ -24,6 +25,7 @@ public function __construct(
2425
protected readonly ContentRepositoryRegistry $contentRepositoryRegistry,
2526
protected readonly PersistenceManagerInterface $persistenceManager,
2627
protected readonly ContentCacheFlusher $contentCacheFlusher,
28+
protected readonly Context $securityContext,
2729
) {
2830
}
2931

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

49-
foreach ($this->globalAssetUsageService->findByFilter($filter) as $contentRepositoryId => $usages) {
50-
$contentRepository = $this->contentRepositoryRegistry->get(ContentRepositoryId::fromString($contentRepositoryId));
51+
$this->securityContext->withoutAuthorizationChecks(function () use ($filter) {
52+
foreach ($this->globalAssetUsageService->findByFilter($filter) as $contentRepositoryId => $usages) {
53+
$contentRepository = $this->contentRepositoryRegistry->get(ContentRepositoryId::fromString($contentRepositoryId));
5154

52-
foreach ($usages as $usage) {
53-
$workspaceNames = $this->getWorkspaceNameAndChildWorkspaceNames($contentRepository, $usage->workspaceName);
55+
foreach ($usages as $usage) {
56+
$workspaceNames = $this->getWorkspaceNameAndChildWorkspaceNames($contentRepository, $usage->workspaceName);
5457

55-
foreach ($workspaceNames as $workspaceName) {
56-
$contentGraph = $contentRepository->getContentGraph($workspaceName);
57-
$nodeAggregate = $contentGraph->findNodeAggregateById($usage->nodeAggregateId);
58-
if ($nodeAggregate === null) {
59-
continue;
60-
}
61-
$flushNodeAggregateRequest = FlushNodeAggregateRequest::create(
62-
$contentRepository->id,
63-
$workspaceName,
64-
$nodeAggregate->nodeAggregateId,
65-
$nodeAggregate->nodeTypeName,
66-
$contentGraph->findAncestorNodeAggregateIds($nodeAggregate->nodeAggregateId),
67-
);
58+
foreach ($workspaceNames as $workspaceName) {
59+
$contentGraph = $contentRepository->getContentGraph($workspaceName);
60+
$nodeAggregate = $contentGraph->findNodeAggregateById($usage->nodeAggregateId);
61+
if ($nodeAggregate === null) {
62+
continue;
63+
}
64+
$flushNodeAggregateRequest = FlushNodeAggregateRequest::create(
65+
$contentRepository->id,
66+
$workspaceName,
67+
$nodeAggregate->nodeAggregateId,
68+
$nodeAggregate->nodeTypeName,
69+
$contentGraph->findAncestorNodeAggregateIds($nodeAggregate->nodeAggregateId),
70+
);
6871

69-
$this->contentCacheFlusher->flushNodeAggregate($flushNodeAggregateRequest, CacheFlushingStrategy::ON_SHUTDOWN);
72+
$this->contentCacheFlusher->flushNodeAggregate($flushNodeAggregateRequest, CacheFlushingStrategy::ON_SHUTDOWN);
73+
}
7074
}
7175
}
72-
}
76+
});
7377
}
7478

7579
/**

0 commit comments

Comments
 (0)