Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUGFIX: Ensure cache flushing for asset changes works with foreign workspaces #5415

Open
wants to merge 1 commit into
base: 9.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading