From b55c30634df716bad9bc1b218a82270254cca39e Mon Sep 17 00:00:00 2001 From: Timon Heuser Date: Tue, 20 Oct 2026 10:31:50 +0200 Subject: [PATCH 1/7] FEATURE: neos 9 compatibility --- .github/workflows/ci.yml | 6 +- Classes/Aspects/CacheUrlMappingAspect.php | 122 +++----- ...setHandlingInContentCacheFlusherAspect.php | 177 ----------- Classes/AssetChangeContentReleaseHandler.php | 53 ++++ .../AutomaticReleaseStatusDataSource.php | 3 +- Classes/BackendUi/BackendUiDataService.php | 56 ++-- Classes/ContentReleaseManager.php | 12 +- Classes/Exception/RenderingException.php | 4 +- .../PublishingAwareNodeWrappingHandler.php | 11 +- Classes/Fusion/ImageUriImplementation.php | 36 --- .../IncrementalContentReleaseCatchUpHook.php | 51 ++++ ...mentalContentReleaseCatchUpHookFactory.php | 25 ++ .../Domain/Dto/EnumeratedNode.php | 65 ++-- .../Domain/Service/DocumentNodeFilter.php | 107 ++----- .../Domain/Service/NodeContextCombinator.php | 185 ++++------- Classes/NodeEnumeration/NodeEnumerator.php | 9 +- .../Dto/DocumentNodeCacheKey.php | 46 +-- .../DocumentEnumeratorInterface.php | 4 +- .../DocumentEnumerators/DefaultEnumerator.php | 4 +- .../DocumentEnumerators/LimitEnumerator.php | 23 +- .../DocumentMetadataGeneratorInterface.php | 8 +- .../DocumentRendererInterface.php | 2 +- .../DocumentRenderers/FusionHtmlRenderer.php | 2 +- .../NodeRenderingExtensionManager.php | 18 +- .../InterruptibleProcessRuntime.php | 16 +- .../NodeRendering/NodeRenderOrchestrator.php | 18 +- Classes/NodeRendering/NodeRenderer.php | 65 ++-- .../NodeRendering/NodeRenderingUriService.php | 125 ++++---- .../NodeRendering/Render/CustomFusionView.php | 174 ++++++----- .../NodeRendering/Render/DocumentRenderer.php | 18 +- Classes/Package.php | 13 +- .../QuickPublishNodeEnumerator.php | 16 +- .../QuickPublishPreviewService.php | 34 ++- Configuration/Settings.yaml | 10 +- Configuration/Testing/Behat/Objects.yaml | 27 -- Configuration/Testing/Behat/Settings.yaml | 28 ++ .../Concepts/QuickContentReleases.md | 48 ++- Documentation/UpgradeGuides/4xto5x.md | 288 ++++++++++++++++++ README.md | 14 +- .../Integration/Backend.Details.fusion | 11 +- .../Integration/Backend.Index.fusion | 3 + Resources/Private/Fusion/Root.fusion | 7 - .../ContentModule/AutomaticReleaseWarning.js | 18 +- .../Features/Bootstrap/FeatureContext.php | 279 ++++++----------- .../Features/ContentStore/Basics.feature | 71 +++-- .../ContentStore/ErrorsWhileRendering.feature | 73 +++-- .../ContentStore/IncrementalRendering.feature | 73 +++-- .../ContentStore/QuickRelease.feature | 53 ++-- .../Features/ContentStore/Renamings.feature | 121 +++++--- .../Domain/Service/DocumentNodeFilterTest.php | 124 ++++---- composer.json | 32 +- phpstan-baseline.neon | 60 ---- 52 files changed, 1444 insertions(+), 1404 deletions(-) delete mode 100644 Classes/Aspects/FixedAssetHandlingInContentCacheFlusherAspect.php create mode 100644 Classes/AssetChangeContentReleaseHandler.php delete mode 100644 Classes/Fusion/ImageUriImplementation.php create mode 100644 Classes/IncrementalContentReleaseCatchUpHook.php create mode 100644 Classes/IncrementalContentReleaseCatchUpHookFactory.php delete mode 100644 Configuration/Testing/Behat/Objects.yaml create mode 100644 Documentation/UpgradeGuides/4xto5x.md diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9491f1b..7acffad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: strategy: fail-fast: false matrix: - php_version: [ '8.2', '8.5' ] + php_version: [ '8.4', '8.5' ] steps: - uses: actions/checkout@v7 @@ -41,8 +41,8 @@ jobs: - uses: actions/checkout@v7 - uses: php-actions/composer@v6 with: - php_version: '8.2' + php_version: '8.4' - uses: php-actions/phpstan@v3 with: - php_version: '8.2' + php_version: '8.4' configuration: phpstan.neon diff --git a/Classes/Aspects/CacheUrlMappingAspect.php b/Classes/Aspects/CacheUrlMappingAspect.php index bc1333a..0e5d77b 100644 --- a/Classes/Aspects/CacheUrlMappingAspect.php +++ b/Classes/Aspects/CacheUrlMappingAspect.php @@ -12,12 +12,19 @@ use Flowpack\DecoupledContentStore\NodeRendering\Render\DocumentRenderer; use Flowpack\DecoupledContentStore\NodeRendering\Render\RenderExceptionExtractor; use Neos\Cache\Exception\InvalidDataException; -use Neos\ContentRepository\Domain\Model\NodeInterface; +use Neos\Cache\Frontend\StringFrontend; +use Neos\ContentRepository\Core\Projection\ContentGraph\Node; +use Neos\ContentRepository\Core\SharedModel\Node\NodeAddress; use Neos\Flow\Annotations as Flow; use Neos\Flow\Aop\JoinPointInterface; +use Neos\Flow\Mvc\ActionRequest; use Neos\Fusion\Core\Cache\CacheSegmentParser; +use Neos\Fusion\Core\Cache\ContentCache; +use Neos\Fusion\Core\Cache\RuntimeContentCache; +use Neos\Fusion\Core\Runtime; use Neos\Utility\Exception\PropertyNotAccessibleException; use Neos\Utility\ObjectAccess; +use RuntimeException; /** * This aspect creates the root cache entry which maps the URL to the root cache identifier during rendering. @@ -26,84 +33,64 @@ * through Batch Rendering (so when {@see DocumentRenderer} has invoked the rendering. This is to keep complexity lower * and code paths simpler: The system NEVER re-uses content cache entries created by editors while browsing the page; but * ONLY re-uses content cache entries created by previous Batch Renderings. - * - * @Flow\Aspect - * @Flow\Scope("singleton") */ +#[Flow\Aspect] +#[Flow\Scope('singleton')] class CacheUrlMappingAspect { /** * are we currently rendering the page from within a Content Release? {@see DocumentRenderer} - * - * @var bool */ - protected $isActive = false; + private bool $isActive = false; - /** - * @var null | int - */ - protected $renderTimestamp = null; + private ?int $renderTimestamp = null; - /** - * @var array - */ - protected $currentEvaluateContext; + private array $currentEvaluateContext = []; /** - * @var \Neos\Flow\Mvc\Controller\ControllerContext + * The cache entry identifier only carries a string identifier of the node, so the node is taken from the Fusion + * context of the segment instead. */ - protected $controllerContext; + private ?Node $currentNode = null; - /** - * @Flow\Inject - * @var \Neos\Fusion\Core\Cache\ContentCache - */ - protected $contentCache; + private ?ActionRequest $actionRequest = null; - /** - * @Flow\Inject - * @var NodeRenderingExtensionManager - */ - protected $nodeRenderingExtensionManager; + #[Flow\Inject] + protected ContentCache $contentCache; - /** - * @var \Neos\Cache\Frontend\StringFrontend - */ - protected $contentCacheFrontend; + #[Flow\Inject] + protected NodeRenderingExtensionManager $nodeRenderingExtensionManager; /** - * @Flow\InjectConfiguration(path="nodeRendering.urlExcludelistRegex") - * @var string|false + * Injected via Objects.yaml */ - protected $urlExcludelistRegex = false; + protected StringFrontend $contentCacheFrontend; - /** - * @var ContentReleaseLogger - */ - protected $contentReleaseLogger; + #[Flow\InjectConfiguration('nodeRendering.urlExcludelistRegex')] + protected string|false|null $urlExcludelistRegex = false; + + private ?ContentReleaseLogger $contentReleaseLogger = null; /** * Did the current document rendering lead to a "doc--..." mapping entry? {@see afterDocumentRendering()} - * - * @var bool */ - protected $mappingWasWrittenForCurrentDocument = false; + private bool $mappingWasWrittenForCurrentDocument = false; - /** - * @Flow\Before("method(Neos\Fusion\Core\Cache\RuntimeContentCache->postProcess())") - */ - public function getCurrentEvaluateAndControllerContext(JoinPointInterface $joinPoint) + #[Flow\Before('method(Neos\Fusion\Core\Cache\RuntimeContentCache->postProcess())')] + public function getCurrentEvaluateAndControllerContext(JoinPointInterface $joinPoint): void { $this->currentEvaluateContext = $joinPoint->getMethodArgument('evaluateContext'); - /** @var \Neos\Fusion\Core\Cache\RuntimeContentCache $runtimeContentCache */ + /** @var RuntimeContentCache $runtimeContentCache */ $runtimeContentCache = $joinPoint->getProxy(); - /** @var \Neos\Fusion\Core\Runtime $runtime */ + /** @var Runtime $runtime */ $runtime = ObjectAccess::getProperty($runtimeContentCache, 'runtime', true); - $this->controllerContext = $runtime->getControllerContext(); + $contextNode = $runtime->getCurrentContext()['node'] ?? null; + $this->currentNode = $contextNode instanceof Node ? $contextNode : null; + $actionRequest = $runtime->fusionGlobals->get('request'); + $this->actionRequest = $actionRequest instanceof ActionRequest ? $actionRequest : null; } /** - * @Flow\After("method(Neos\Fusion\Core\Cache\ContentCache->processCacheSegments())") * @throws Exception * @throws \JsonException * @throws \Neos\Cache\Exception @@ -111,20 +98,16 @@ public function getCurrentEvaluateAndControllerContext(JoinPointInterface $joinP * @throws \Neos\Fusion\Exception * @throws PropertyNotAccessibleException */ + #[Flow\After('method(Neos\Fusion\Core\Cache\ContentCache->processCacheSegments())')] public function storeRootCacheIdentifier(JoinPointInterface $joinPoint): void { if (!$this->isActive) { return; } - if ( - !isset($this->currentEvaluateContext['cacheIdentifierValues']['node']) - || !$this->currentEvaluateContext['cacheIdentifierValues']['node'] instanceof NodeInterface - ) { + if (!isset($this->currentEvaluateContext['cacheIdentifierValues']['node']) || $this->currentNode === null) { return; } - - /** @var NodeInterface $node */ - $node = $this->currentEvaluateContext['cacheIdentifierValues']['node']; + $node = $this->currentNode; $url = $this->getCurrentUrl(); @@ -137,7 +120,7 @@ public function storeRootCacheIdentifier(JoinPointInterface $joinPoint): void 'Cache was disabled for ' . $url . ' with node ' - . $node->getContextPath() + . NodeAddress::fromNode($node)->toJson() . ', but no exception was handled by the publishing. This could be caused by a missing publishing aware @exceptionHandler in Fusion.' . ( $extractedExceptionDto !== null ? "\nException extracted from output: {$extractedExceptionDto}" : '' @@ -159,7 +142,7 @@ public function storeRootCacheIdentifier(JoinPointInterface $joinPoint): void $logger = $this->contentReleaseLogger; if ($logger === null) { - throw new \RuntimeException('TODO Logger not found - should never happen'); + throw new RuntimeException('TODO Logger not found - should never happen'); } if ($this->urlIsMatchingBlacklist($url)) { $logger->info(sprintf( @@ -191,7 +174,7 @@ public function storeRootCacheIdentifier(JoinPointInterface $joinPoint): void $rootCacheValues = $this->nodeRenderingExtensionManager->runDocumentMetadataGenerators( $node, $arguments, - $this->controllerContext, + $this->actionRequest, $rootCacheValues, ); $this->contentCacheFrontend->set( @@ -205,11 +188,9 @@ public function storeRootCacheIdentifier(JoinPointInterface $joinPoint): void /** * @return string */ - protected function getCurrentUrl(): string + private function getCurrentUrl(): string { - /** @var \Neos\Flow\Mvc\ActionRequest $actionRequest */ - $actionRequest = $this->controllerContext->getRequest(); - $httpRequest = $actionRequest->getHttpRequest(); + $httpRequest = $this->actionRequest->getHttpRequest(); $url = $httpRequest->getUri(); $url = $url->withQuery(''); @@ -217,22 +198,17 @@ protected function getCurrentUrl(): string } /** - * @param NodeInterface $node + * @param Node $node */ - protected function getCurrentArguments(NodeInterface $node): array + private function getCurrentArguments(Node $node): array { - /** @var \Neos\Flow\Mvc\ActionRequest $actionRequest */ - $actionRequest = $this->controllerContext->getRequest(); - $arguments = $actionRequest->getArguments(); + $arguments = $this->actionRequest->getArguments(); unset($arguments['node']); return $arguments; } - /** - * @param array $tags - * @return array - */ - protected function sanitizeTags($tags) + + private function sanitizeTags(array $tags): array { foreach ($tags as $key => $value) { $tags[$key] = strtr($value, '.:', '_-'); diff --git a/Classes/Aspects/FixedAssetHandlingInContentCacheFlusherAspect.php b/Classes/Aspects/FixedAssetHandlingInContentCacheFlusherAspect.php deleted file mode 100644 index 8a14874..0000000 --- a/Classes/Aspects/FixedAssetHandlingInContentCacheFlusherAspect.php +++ /dev/null @@ -1,177 +0,0 @@ -`. It is also mentioned here for completeness; so that one has a - * complete overview of the full issue. - * - * 3) Additional Bug: The default implementation of ContentCacheFlusher::registerAssetChange() does not flush the cache of the parent - * nodes until and including the parent document node of all nodes that use that asset. It only flushes the cache of the - * node that uses the asset. This is changed here. - * - * 4) Note: We also directly commit the cache flush and trigger the incremental rendering afterwards to prevent a race condition with - * node enumeration during incremental rendering. - * - * @Flow\Aspect - * @Flow\Scope("singleton") - */ -class FixedAssetHandlingInContentCacheFlusherAspect -{ - use CreateContentContextTrait; - - /** - * @Flow\Inject - * @var PersistenceManagerInterface - */ - protected $persistenceManager; - - /** - * @Flow\Inject - * @var AssetService - */ - protected $assetService; - - /** - * @Flow\Inject - * @var CachingHelper - */ - protected $cachingHelper; - - /** - * @Flow\Inject - * @var ContentReleaseManager - */ - protected $contentReleaseManager; - - /** - * @Flow\InjectConfiguration("startIncrementalReleaseOnAssetChange") - * @var bool - */ - protected $startIncrementalReleaseOnAssetChange; - - /** - * WHY: - * The default implementation of ContentCacheFlusher::registerAssetChange() does not flush the cache of the parent - * nodes until and including the parent document node of all nodes that use that asset. - * - * What we want to accomplish: - * When an asset is updated (including "replaced"), we want to - * 1. flush the cache of the updated asset (with and without workspace hash) - * 2. flush the cache of all parent nodes until (including) the parent document node of all nodes that use that - * asset (assetUsage) - * 3. Commit cache flushes to prevent race condition with node enumeration during incremental rendering - * 3. trigger incremental rendering - */ - /** - * @Flow\Around("method(Neos\Neos\Fusion\Cache\ContentCacheFlusher->registerAssetChange())") - */ - public function registerAssetChange(JoinPointInterface $joinPoint) - { - /* @var AssetInterface $asset */ - $asset = $joinPoint->getMethodArgument('asset'); - - if (!$asset->isInUse()) { - return; - } - - /* @var ContentCacheFlusher $contentCacheFlusher */ - $contentCacheFlusher = $joinPoint->getProxy(); - - // 1. flush asset tag without workspace hash - $assetIdentifier = $this->persistenceManager->getIdentifierByObject($asset); - - $assetCacheTag = 'AssetDynamicTag_' . $assetIdentifier; - - // WHY: ContentCacheFlusher has no public api to flush tags directly - $tagsToFlush = ObjectAccess::getProperty($contentCacheFlusher, 'tagsToFlush', true); - $tagsToFlush[$assetCacheTag] = sprintf( - 'which were tagged with "%s" because asset "%s" has changed.', - $assetCacheTag, - $assetIdentifier, - ); - ObjectAccess::setProperty($contentCacheFlusher, 'tagsToFlush', $tagsToFlush, true); - - $usageReferences = $this->assetService->getUsageReferences($asset); - - foreach ($usageReferences as $assetUsage) { - // get node that uses the asset - $context = $this->_contextFactory->create([ - 'workspaceName' => $assetUsage->getWorkspaceName(), - 'dimensions' => $assetUsage->getDimensionValues(), - 'invisibleContentShown' => true, - 'removedContentShown' => true, - ]); - - $node = $context->getNodeByIdentifier($assetUsage->getNodeIdentifier()); - - // We need this for cache tag generation - $workspaceHash = $this->cachingHelper->renderWorkspaceTagForContextNode($context->getWorkspaceName()); - - // 1. flush asset with workspace hash - $assetCacheTagWithWorkspace = 'AssetDynamicTag_' . $workspaceHash . '_' . $assetIdentifier; - - // WHY: ContentCacheFlusher has no public api to flush tags directly - $tagsToFlush = ObjectAccess::getProperty($contentCacheFlusher, 'tagsToFlush', true); - $tagsToFlush[$assetCacheTagWithWorkspace] = sprintf( - 'which were tagged with "%s" because asset "%s" has changed.', - $assetCacheTagWithWorkspace, - $assetIdentifier, - ); - ObjectAccess::setProperty($contentCacheFlusher, 'tagsToFlush', $tagsToFlush, true); - - // 2. flush all nodes on path to parent document node (a bit excessive, but for now it works) - $currentNode = $node; - while ($currentNode->getParent() !== null) { - // flush node cache - $contentCacheFlusher->registerNodeChange($node); - - // if document node, stop - if ($currentNode->getNodeType()->isOfType('Neos.Neos:Document')) { - break; - } - - // go to parent node - $currentNode = $currentNode->getParent(); - } - } - - // 3. commit cache flushes - // We need force the commit here because we run into a race condition otherwise, where the incremental rendering - // is starting node enumeration before the cache flushes are actually committed. - $contentCacheFlusher->shutdownObject(); - - // 4. trigger incremental rendering - if ($this->startIncrementalReleaseOnAssetChange) { - $this->contentReleaseManager->startIncrementalContentRelease(); - } - } -} diff --git a/Classes/AssetChangeContentReleaseHandler.php b/Classes/AssetChangeContentReleaseHandler.php new file mode 100644 index 0000000..1ccaa94 --- /dev/null +++ b/Classes/AssetChangeContentReleaseHandler.php @@ -0,0 +1,53 @@ +startIncrementalReleaseOnAssetChange) { + return; + } + + // Nodes reference the original asset, never a variant. + if ($asset instanceof AssetVariantInterface) { + $asset = $asset->getOriginalAsset(); + } + + if (!$this->assetService->isInUse($asset)) { + return; + } + + $this->contentCacheFlusher->flushCollectedTags(); + $this->contentReleaseManager->startIncrementalContentRelease(); + } +} diff --git a/Classes/BackendUi/AutomaticReleaseStatusDataSource.php b/Classes/BackendUi/AutomaticReleaseStatusDataSource.php index c5da260..b7b5165 100644 --- a/Classes/BackendUi/AutomaticReleaseStatusDataSource.php +++ b/Classes/BackendUi/AutomaticReleaseStatusDataSource.php @@ -5,6 +5,7 @@ namespace Flowpack\DecoupledContentStore\BackendUi; use Flowpack\DecoupledContentStore\Core\AutomaticReleaseSwitchService; +use Neos\ContentRepository\Core\Projection\ContentGraph\Node; use Neos\ContentRepository\Domain\Model\NodeInterface; use Neos\Flow\Annotations as Flow; use Neos\Flow\I18n\Translator; @@ -43,7 +44,7 @@ final class AutomaticReleaseStatusDataSource extends AbstractDataSource * @param array $arguments * @return array */ - public function getData(?NodeInterface $node = null, array $arguments = []): array + public function getData(?Node $node = null, array $arguments = []): array { $pauseState = $this->automaticReleaseSwitchService->getPauseState(); diff --git a/Classes/BackendUi/BackendUiDataService.php b/Classes/BackendUi/BackendUiDataService.php index cb8cde3..07dbff0 100644 --- a/Classes/BackendUi/BackendUiDataService.php +++ b/Classes/BackendUi/BackendUiDataService.php @@ -4,6 +4,7 @@ namespace Flowpack\DecoupledContentStore\BackendUi; +use Exception; use Flowpack\DecoupledContentStore\BackendUi\Dto\ContentReleaseDetails; use Flowpack\DecoupledContentStore\BackendUi\Dto\ContentReleaseOverviewRow; use Flowpack\DecoupledContentStore\BackendUi\Dto\RemovedContentReleaseOverviewRow; @@ -21,49 +22,33 @@ use Flowpack\Prunner\Dto\Job; use Flowpack\Prunner\PrunnerApiService; use Neos\Flow\Annotations as Flow; +use Throwable; -/** - * @Flow\Scope("singleton") - */ +#[Flow\Scope('singleton')] class BackendUiDataService { - /** - * @Flow\Inject - * @var PrunnerApiService - */ - protected $prunnerApiService; + #[Flow\Inject] + protected PrunnerApiService $prunnerApiService; - /** - * @Flow\Inject - * @var RedisEnumerationRepository - */ - protected $redisEnumerationRepository; + #[Flow\Inject] + protected RedisEnumerationRepository $redisEnumerationRepository; - /** - * @Flow\Inject - * @var RedisContentReleaseService - */ - protected $redisContentReleaseService; + #[Flow\Inject] + protected RedisContentReleaseService $redisContentReleaseService; - /** - * @Flow\Inject - * @var RedisRenderingTimeStatisticsStore - */ - protected $redisRenderingStatisticsStore; + #[Flow\Inject] + protected RedisRenderingTimeStatisticsStore $redisRenderingStatisticsStore; - /** - * @Flow\Inject - * @var RedisRenderingErrorManager - */ - protected $redisRenderingErrorManager; + #[Flow\Inject] + protected RedisRenderingErrorManager $redisRenderingErrorManager; + + #[Flow\Inject] + protected RedisReleaseSwitchService $redisReleaseSwitchService; /** - * @Flow\Inject - * @var RedisReleaseSwitchService + * @throws Exception */ - protected $redisReleaseSwitchService; - - public function loadBackendOverviewData(RedisInstanceIdentifier $redisInstanceIdentifier) + public function loadBackendOverviewData(RedisInstanceIdentifier $redisInstanceIdentifier): array { $contentReleaseIds = $this->redisContentReleaseService->fetchAllReleaseIds($redisInstanceIdentifier); $metadata = $this->redisContentReleaseService->fetchMetadataForContentReleases( @@ -93,7 +78,7 @@ public function loadBackendOverviewData(RedisInstanceIdentifier $redisInstanceId foreach ($this->prunnerApiService->loadPipelinesAndJobs()->getJobs() as $job) { $jobsById[$job->getId()->getId()] = $job; } - } catch (\Throwable $throwable) { + } catch (Throwable) { // the overview also holds the controls to pause releases, which must keep working while prunner is down $jobsById = null; } @@ -155,6 +140,7 @@ public function loadBackendOverviewData(RedisInstanceIdentifier $redisInstanceId * "replace", most of them were replaced while waiting and have no logs at all. * * @return RemovedContentReleaseOverviewRow[]|null NULL when the prunner API could not be reached + * @throws Exception */ public function loadRemovedReleasesOverviewData(RedisInstanceIdentifier $redisInstanceIdentifier): ?array { @@ -164,7 +150,7 @@ public function loadRemovedReleasesOverviewData(RedisInstanceIdentifier $redisIn try { $jobs = $this->prunnerApiService->loadPipelinesAndJobs()->getJobs(); - } catch (\Throwable $throwable) { + } catch (Throwable) { // the overview also holds the controls to pause releases, which must keep working while prunner is down return null; } diff --git a/Classes/ContentReleaseManager.php b/Classes/ContentReleaseManager.php index 47c7d6f..3722026 100644 --- a/Classes/ContentReleaseManager.php +++ b/Classes/ContentReleaseManager.php @@ -69,7 +69,7 @@ class ContentReleaseManager */ public function startIncrementalContentRelease( ?string $currentContentReleaseId = null, - ?Workspace $workspace = null, + ?\Neos\ContentRepository\Core\SharedModel\Workspace\Workspace $workspace = null, array $additionalVariables = [], ): ContentReleaseIdentifier { $contentReleaseId = ContentReleaseIdentifier::create(); @@ -96,7 +96,7 @@ public function startIncrementalContentRelease( 'currentContentReleaseId' => $this->resolveCurrentContentReleaseId($currentContentReleaseId), 'validate' => true, 'flushContentCache' => false, - 'workspaceName' => $workspace !== null ? $workspace->getName() : 'live', + 'workspaceName' => $workspace !== null ? $workspace->workspaceName->value : 'live', 'accountId' => $this->getAccountId(), ]), ); @@ -110,7 +110,7 @@ public function startIncrementalContentRelease( public function startFullContentRelease( bool $validate = true, ?string $currentContentReleaseId = null, - ?Workspace $workspace = null, + ?\Neos\ContentRepository\Core\SharedModel\Workspace\Workspace $workspace = null, array $additionalVariables = [], ): ContentReleaseIdentifier { $contentReleaseId = ContentReleaseIdentifier::create(); @@ -121,7 +121,7 @@ public function startFullContentRelease( 'currentContentReleaseId' => $this->resolveCurrentContentReleaseId($currentContentReleaseId), 'validate' => $validate, 'flushContentCache' => true, - 'workspaceName' => $workspace !== null ? $workspace->getName() : 'live', + 'workspaceName' => $workspace !== null ? $workspace->workspaceName->value : 'live', 'accountId' => $this->getAccountId(), ]), ); @@ -142,7 +142,7 @@ public function startFullContentRelease( */ public function startQuickContentRelease( NodeIdentifiers $nodeIdentifiers, - ?Workspace $workspace = null, + ?\Neos\ContentRepository\Core\SharedModel\Workspace\Workspace $workspace = null, array $additionalVariables = [], ): ContentReleaseIdentifier { $currentContentReleaseId = $this->resolveCurrentContentReleaseId(null); @@ -184,7 +184,7 @@ public function startQuickContentRelease( 'contentReleaseId' => $contentReleaseId, 'currentContentReleaseId' => $currentContentReleaseId, 'quickPublishNodeIdentifiers' => (string) $nodeIdentifiers, - 'workspaceName' => $workspace !== null ? $workspace->getName() : 'live', + 'workspaceName' => $workspace !== null ? $workspace->workspaceName->value : 'live', 'accountId' => $this->getAccountId(), ]), ); diff --git a/Classes/Exception/RenderingException.php b/Classes/Exception/RenderingException.php index a6f2536..233bfb4 100644 --- a/Classes/Exception/RenderingException.php +++ b/Classes/Exception/RenderingException.php @@ -13,14 +13,14 @@ class RenderingException extends \Flowpack\DecoupledContentStore\Exception /** * @param string $message - * @param NodeInterface $node + * @param \Neos\ContentRepository\Core\Projection\ContentGraph\Node $node * @param string $nodeUri * @param int $code * @param Exception $previous */ public function __construct( string $message, - NodeInterface $node, + \Neos\ContentRepository\Core\Projection\ContentGraph\Node $node, $nodeUri, int $code = 0, ?Exception $previous = null, diff --git a/Classes/Fusion/ExceptionHandlers/PublishingAwareNodeWrappingHandler.php b/Classes/Fusion/ExceptionHandlers/PublishingAwareNodeWrappingHandler.php index 0ec40c5..4360c24 100644 --- a/Classes/Fusion/ExceptionHandlers/PublishingAwareNodeWrappingHandler.php +++ b/Classes/Fusion/ExceptionHandlers/PublishingAwareNodeWrappingHandler.php @@ -4,21 +4,20 @@ namespace Flowpack\DecoupledContentStore\Fusion\ExceptionHandlers; +use Exception; use Flowpack\DecoupledContentStore\NodeRendering\Render\DocumentRenderer; use Neos\Flow\Annotations as Flow; class PublishingAwareNodeWrappingHandler extends \Neos\Neos\Fusion\ExceptionHandlers\NodeWrappingHandler { - /** - * @Flow\Inject - * @var DocumentRenderer - */ - protected $documentRenderer; + #[Flow\Inject()] + protected DocumentRenderer $documentRenderer; /** * {@inheritdoc} + * @throws Exception */ - protected function handle($fusionPath, \Exception $exception, $referenceCode) + protected function handle($fusionPath, Exception $exception, $referenceCode): string { if ($this->documentRenderer->isRendering()) { throw $exception; diff --git a/Classes/Fusion/ImageUriImplementation.php b/Classes/Fusion/ImageUriImplementation.php deleted file mode 100644 index 11c0268..0000000 --- a/Classes/Fusion/ImageUriImplementation.php +++ /dev/null @@ -1,36 +0,0 @@ -getAsset(); - - if ($asset) { - $this->runtime->addCacheTag('asset', $this->persistenceManager->getIdentifierByObject($asset)); - } - - return $result; - } -} diff --git a/Classes/IncrementalContentReleaseCatchUpHook.php b/Classes/IncrementalContentReleaseCatchUpHook.php new file mode 100644 index 0000000..7d23b92 --- /dev/null +++ b/Classes/IncrementalContentReleaseCatchUpHook.php @@ -0,0 +1,51 @@ +isBooting = $subscriptionStatus === SubscriptionStatus::BOOTING; + } + + public function onBeforeEvent(EventInterface $eventInstance, EventEnvelope $eventEnvelope): void + { + } + + public function onAfterEvent(EventInterface $eventInstance, EventEnvelope $eventEnvelope): void + { + if ( + !$this->isBooting + && $eventInstance instanceof WorkspaceWasPublished + && $eventInstance->targetWorkspaceName->isLive() + ) { + $this->incrementalContentReleaseHandler->nodePublished(); + } + } + + public function onAfterBatchCompleted(): void + { + } + + public function onAfterCatchUp(): void + { + } +} diff --git a/Classes/IncrementalContentReleaseCatchUpHookFactory.php b/Classes/IncrementalContentReleaseCatchUpHookFactory.php new file mode 100644 index 0000000..5cabc5d --- /dev/null +++ b/Classes/IncrementalContentReleaseCatchUpHookFactory.php @@ -0,0 +1,25 @@ + + */ +final readonly class IncrementalContentReleaseCatchUpHookFactory implements CatchUpHookFactoryInterface +{ + public function __construct( + private IncrementalContentReleaseHandler $incrementalContentReleaseHandler, + ) {} + + public function build(CatchUpHookFactoryDependencies $dependencies): CatchUpHookInterface + { + return new IncrementalContentReleaseCatchUpHook($this->incrementalContentReleaseHandler); + } +} diff --git a/Classes/NodeEnumeration/Domain/Dto/EnumeratedNode.php b/Classes/NodeEnumeration/Domain/Dto/EnumeratedNode.php index 52c723a..b61e581 100644 --- a/Classes/NodeEnumeration/Domain/Dto/EnumeratedNode.php +++ b/Classes/NodeEnumeration/Domain/Dto/EnumeratedNode.php @@ -4,43 +4,31 @@ namespace Flowpack\DecoupledContentStore\NodeEnumeration\Domain\Dto; -use Neos\ContentRepository\Domain\Model\NodeInterface; -use Neos\ContentRepository\Domain\Utility\NodePaths; +use Exception; +use JsonSerializable; +use Neos\ContentRepository\Core\Projection\ContentGraph\Node; +use Neos\ContentRepository\Core\SharedModel\Node\NodeAddress; use Neos\Flow\Annotations as Flow; -/** - * @Flow\Proxy(false) - */ -final class EnumeratedNode implements \JsonSerializable +#[Flow\Proxy(false)] +final class EnumeratedNode implements JsonSerializable { /** * We extract the to-be-rendered dimensions and the current site from the context path. Other than that, * it is used NOT for rendering. * * You are NOT ALLOWED to rely on this stored context path as a whole during rendering, because it might have changed because of a move. - * - * @var string */ - protected $contextPath; + private string $contextPath; /** * We identify the node by its identifier - * - * @var string */ - protected $nodeIdentifier; + private string $nodeIdentifier; - /** - * @var array - */ - protected $arguments; + private array $arguments; - /** - * The node type name - * - * @var string - */ - protected $nodeTypeName; + private string $nodeTypeName; /** * The renderer implementation to use for this EnumeratedNode; @@ -62,22 +50,25 @@ private function __construct( $this->rendererId = $rendererId; } - public static function fromNode(NodeInterface $node, array $arguments = []): self + public static function fromNode(Node $node, array $arguments = []): self { return new self( - $node->getContextPath(), - $node->getIdentifier(), - $node->getNodeType()->getName(), + NodeAddress::fromNode($node)->toJson(), + $node->aggregateId->value, + $node->nodeTypeName->value, $arguments, '', ); } + /** + * @throws Exception + */ public static function fromJsonString(string $enumeratedNodeString): self { $tmp = json_decode($enumeratedNodeString, true); if (!is_array($tmp)) { - throw new \Exception('EnumeratedNode cannot be constructed from: ' . $enumeratedNodeString); + throw new Exception('EnumeratedNode cannot be constructed from: ' . $enumeratedNodeString); } return new self( $tmp['contextPath'], @@ -99,28 +90,22 @@ public function jsonSerialize(): array ]; } - public function getSiteNodeNameFromContextPath(): string + public function getNodeAddress(): NodeAddress { - if (preg_match('#^/sites/([^/@]*)#', $this->contextPath, $matches)) { - return $matches[1]; - } else { - throw new \Exception( - 'Could not get site node name from context path "' . $this->contextPath . '"', - 1495535171, - ); - } + return NodeAddress::fromJsonString($this->contextPath); } + /** + * @return array + */ public function getDimensionsFromContextPath(): array { - $nodePathAndContext = NodePaths::explodeContextPath($this->contextPath); - return $nodePathAndContext['dimensions']; + return NodeAddress::fromJsonString($this->contextPath)->dimensionSpacePoint->coordinates; } public function getWorkspaceNameFromContextPath(): string { - $nodePathAndContext = NodePaths::explodeContextPath($this->contextPath); - return $nodePathAndContext['workspaceName']; + return NodeAddress::fromJsonString($this->contextPath)->workspaceName->value; } public function getNodeIdentifier(): string diff --git a/Classes/NodeEnumeration/Domain/Service/DocumentNodeFilter.php b/Classes/NodeEnumeration/Domain/Service/DocumentNodeFilter.php index 927636e..69bc713 100644 --- a/Classes/NodeEnumeration/Domain/Service/DocumentNodeFilter.php +++ b/Classes/NodeEnumeration/Domain/Service/DocumentNodeFilter.php @@ -4,10 +4,9 @@ namespace Flowpack\DecoupledContentStore\NodeEnumeration\Domain\Service; -use Neos\ContentRepository\Domain\Model\NodeInterface; -use Neos\ContentRepository\Domain\Projection\Content\TraversableNodeInterface; -use Neos\ContentRepository\Exception\NodeException; +use Neos\ContentRepository\Core\Projection\ContentGraph\Node; use Neos\Flow\Annotations as Flow; +use Neos\Neos\Domain\SubtreeTagging\NeosSubtreeTag; /** * Decides which document nodes end up in a content release. @@ -32,6 +31,8 @@ final class DocumentNodeFilter #[Flow\InjectConfiguration('nodeRendering.recurseHiddenContent')] protected bool $recurseHiddenContent; + #[\Neos\Flow\Annotations\Inject] + protected \Neos\ContentRepositoryRegistry\ContentRepositoryRegistry $contentRepositoryRegistry; /** * Builds a FlowQuery filter string from the node type whitelist, @@ -57,9 +58,13 @@ public function flowQueryNodeTypeFilter(): string * Concatenated FlowQuery filter parts are ANDed, so a node has to be of every included node type - not of any * of them. */ - public function matchesNodeTypeWhitelist(NodeInterface $node): bool + public function matchesNodeTypeWhitelist(Node $node): bool { - $nodeType = $node->getNodeType(); + $contentRepository = $this->contentRepositoryRegistry->get($node->contentRepositoryId); + $nodeType = $contentRepository->getNodeTypeManager()->getNodeType($node->nodeTypeName); + if ($nodeType === null) { + return false; + } $partitionedNodeTypes = self::partitionNodeTypeWhitelist($this->nodeTypeWhitelist); foreach ($partitionedNodeTypes['excludes'] as $excludedNodeType) { @@ -84,16 +89,11 @@ public function matchesNodeTypeWhitelist(NodeInterface $node): bool * passing it through the FlowQuery filter, and both enumerators would change behaviour if that were tightened * as a side effect. Callers which resolve nodes by identifier check {@see matchesNodeTypeWhitelist()} themselves. */ - public function skipReason(NodeInterface $node, NodeInterface $siteNode): ?string + public function skipReason(Node $node): ?string { - // the site node has no parent inside the site, so it can never be orphaned - if ($node !== $siteNode && self::isOrphaned($node, $siteNode)) { - return 'orphaned'; - } - - // isVisible() rather than isHidden(), so that a page hidden by "hiddenBeforeDateTime" or - // "hiddenAfterDateTime" counts as hidden as well - it is hidden to a visitor just the same - if (!$node->isVisible()) { + // only the node's own tag: an inherited one means a page above it is hidden, which the full enumeration + // decides by its traversal and {@see skipReasonForNamedNode()} by "recurseHiddenContent" + if ($node->tags->withoutInherited()->contain(NeosSubtreeTag::disabled())) { return 'hidden'; } @@ -107,79 +107,34 @@ public function skipReason(NodeInterface $node, NodeInterface $siteNode): ?strin * which was named by hand did not come out of the FlowQuery filter and was not reached by descending from the * site node, so nothing else checked either of them. */ - public function skipReasonForNamedNode(NodeInterface $node, NodeInterface $siteNode): ?string + public function skipReasonForNamedNode(Node $node): ?string { - $skipReason = $this->skipReason($node, $siteNode); - if ($skipReason !== null) { - return $skipReason; - } - - // "recurseHiddenContent" is what the full enumeration descends into hidden pages with, so where it is set a - // document below one is part of an ordinary release and has to be part of a quick release just the same - if (!$this->recurseHiddenContent && self::hasHiddenAncestor($node)) { - return 'below a hidden page'; - } - - return $this->matchesNodeTypeWhitelist($node) ? null : 'not of a node type which is published'; + return $this->visibilitySkipReasonForNamedNode($node) + ?? ($this->matchesNodeTypeWhitelist($node) ? null : 'not of a node type which is published'); } /** - * Whether one of the pages above the node is hidden, by its flag or by its hidden-before/after dates. + * Everything {@see skipReasonForNamedNode()} answers apart from the node type, which needs the content repository. * - * Only asked about a node named by identifier, which is resolved in a context that shows hidden nodes so that - * "it is hidden" can be reported instead of "it does not exist". The full enumeration needs no such check: it - * descends from the site node in a context built from "recurseHiddenContent", and therefore never reaches a - * document below a hidden page unless that setting says it should - publishing one from a quick release would - * put a page live which the next full release removes again. The walk goes past the site node, because a hidden - * site node keeps its whole site out of a full release just as well. + * A node named by identifier is resolved in a subgraph that shows disabled nodes, so that "it is hidden" can be + * reported instead of "it does not exist". The full enumeration needs no check for the pages above: it descends + * from the site node in a subgraph built from "recurseHiddenContent", and therefore never reaches a document + * below a hidden page unless that setting says it should - publishing one from a quick release would put a page + * live which the next full release removes again. Inherited tags include the site node's, because a hidden site + * node keeps its whole site out of a full release just as well. */ - private static function hasHiddenAncestor(NodeInterface $node): bool + private function visibilitySkipReasonForNamedNode(Node $node): ?string { - $parentNode = self::getParentNodeOrNull($node); - while ($parentNode !== null) { - if (!$parentNode->isVisible()) { - return true; - } - $parentNode = self::getParentNodeOrNull($parentNode); - } - - return false; - } - - private static function isOrphaned(NodeInterface $node, NodeInterface $siteNode): bool - { - $parentNode = self::getParentNodeOrNull($node); - while ($parentNode !== $siteNode) { - if ($parentNode === null) { - return true; - } - $parentNode = self::getParentNodeOrNull($parentNode); - } - - return false; - } - - /** - * The parent of a node, or NULL where the walk up leaves the tree. - * - * Walking up needs findParentNode(), which belongs to TraversableNodeInterface - a different interface from the - * NodeInterface the rest of this class works with, implemented side by side by the content repository's node - * class. Both conversions live here so that callers compare nodes of one type, and so that "left the tree" - * stays a NULL rather than an exception. - */ - private static function getParentNodeOrNull(NodeInterface $node): ?NodeInterface - { - if (!$node instanceof TraversableNodeInterface) { - return null; + $skipReason = $this->skipReason($node); + if ($skipReason !== null) { + return $skipReason; } - try { - $parentNode = $node->findParentNode(); - } catch (NodeException) { - return null; + if (!$this->recurseHiddenContent && $node->tags->onlyInherited()->contain(NeosSubtreeTag::disabled())) { + return 'below a hidden page'; } - return $parentNode instanceof NodeInterface ? $parentNode : null; + return null; } /** diff --git a/Classes/NodeEnumeration/Domain/Service/NodeContextCombinator.php b/Classes/NodeEnumeration/Domain/Service/NodeContextCombinator.php index 567d429..d5d8110 100644 --- a/Classes/NodeEnumeration/Domain/Service/NodeContextCombinator.php +++ b/Classes/NodeEnumeration/Domain/Service/NodeContextCombinator.php @@ -4,126 +4,61 @@ namespace Flowpack\DecoupledContentStore\NodeEnumeration\Domain\Service; -use Flowpack\DecoupledContentStore\Exception\NodeNotFoundException; use Generator; -use Neos\ContentRepository\Domain\Model\NodeInterface; -use Neos\ContentRepository\Domain\Projection\Content\TraversableNodeInterface; -use Neos\ContentRepository\Domain\Service\ContentDimensionCombinator; -use Neos\ContentRepository\Domain\Service\ContextFactoryInterface; +use Neos\ContentRepository\Core\Feature\Security\Exception\AccessDenied; +use Neos\ContentRepository\Core\Projection\ContentGraph\Node; +use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId; +use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId; +use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName; +use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry; use Neos\Flow\Annotations as Flow; use Neos\Neos\Domain\Model\Site; use Neos\Neos\Domain\Repository\SiteRepository; +use Neos\Neos\Domain\Service\NodeTypeNameFactory; +use Neos\Neos\Domain\SubtreeTagging\NeosVisibilityConstraints; class NodeContextCombinator { - /** - * @Flow\Inject - * @var ContentDimensionCombinator - */ - protected $contentDimensionCombinator; + #[Flow\Inject] + protected SiteRepository $siteRepository; - /** - * @Flow\Inject - * @var SiteRepository - */ - protected $siteRepository; + #[Flow\InjectConfiguration('nodeRendering.recurseHiddenContent')] + protected bool $recurseHiddenContent; - /** - * @Flow\Inject - * @var ContextFactoryInterface - */ - protected $contextFactory; + #[Flow\Inject] + protected ContentRepositoryRegistry $contentRepositoryRegistry; /** - * @Flow\InjectConfiguration(path="nodeRendering.recurseHiddenContent", package="Flowpack.DecoupledContentStore") - * @var ContextFactoryInterface - */ - protected $recurseHiddenContent; - - /** - * Iterate over the node with the given identifier and site in contexts for all available presets (if it exists as a variant) + * Iterate over the node with the given identifier in every dimension it exists in. * - * @return Generator - * @throws NodeNotFoundException + * An identifier which is no valid node aggregate id yields nothing. + * + * @return Generator + * @throws AccessDenied */ - public function nodeInContexts(string $nodeIdentifier, Site $site, string $workspaceName = 'live'): Generator + public function nodeVariants(string $nodeIdentifier, string $workspaceName = 'live'): Generator { - $nodeFound = false; - - /** @var NodeInterface $siteNode */ - foreach ($this->siteNodeInContexts($site, $workspaceName) as $siteNode) { - $node = $siteNode->getContext()->getNodeByIdentifier($nodeIdentifier); - - if ($node instanceof NodeInterface) { - $nodeFound = true; - yield $node; - } + $nodeAggregateId = NodeAggregateId::tryFromString($nodeIdentifier); + if ($nodeAggregateId === null) { + return; } - if (!$nodeFound) { - throw new NodeNotFoundException( - 'Could not find node by identifier ' . $nodeIdentifier . ' in any context', - 1467285561, - ); - } - } - - /** - * Iterate over the node with the given identifier in every dimension it exists in, together with the site node - * it belongs to. - * - * Unlike {@see nodeInContexts()} this searches every site and hands out the site node as well, which callers - * need for the orphan check. It also does not report "not found" per site: a node is part of one site, so all - * the others not having it is the normal case rather than an error. - * - * @return Generator the site node and the node, in that order - */ - public function nodeVariantsWithSiteNode(string $nodeIdentifier, string $workspaceName = 'live'): Generator - { - foreach ($this->sites() as $site) { - // a flag rather than a plain return after the inner loop: a site which does not contain the node - // yields nothing and has to fall through to the next site, and returning from inside the inner loop - // would cut off the node's remaining dimension variants - $nodeFound = false; + $contentRepository = $this->contentRepositoryRegistry->get(ContentRepositoryId::fromString('default')); + $contentGraph = $contentRepository->getContentGraph(WorkspaceName::fromString($workspaceName)); + foreach ($contentRepository->getVariationGraph()->getDimensionSpacePoints() as $dimensionSpacePoint) { // hidden nodes are shown here regardless of "recurseHiddenContent": somebody named this node by its - // identifier, and "it is hidden" is the answer they need - a context which filters it away could only + // identifier, and "it is hidden" is the answer they need - a subgraph which filters it away could only // report that it does not exist - foreach ($this->siteNodeInContexts($site, $workspaceName, true) as $siteNode) { - $node = $siteNode->getContext()->getNodeByIdentifier($nodeIdentifier); - // getNodeByIdentifier() looks the node up in the whole content repository rather than inside the - // site, so it answers for every site alike and the node has to be matched against the site itself - if ($node instanceof NodeInterface && self::isWithinSiteNode($node, $siteNode)) { - $nodeFound = true; - yield [$siteNode, $node]; - } - } + $subgraph = $contentGraph->getSubgraph($dimensionSpacePoint, NeosVisibilityConstraints::excludeRemoved()); - if ($nodeFound) { - // a node belongs to exactly one site, so the remaining ones cannot contribute further variants - return; + $node = $subgraph->findNodeById($nodeAggregateId); + if ($node !== null) { + yield $node; } } } - /** - * Whether the node is the site node itself or lives below it. - * - * Compared by path rather than by walking up the parents: the walk gives the same answer, while this runs for - * every site the node is looked up in. Nodes without a path cannot be placed in a site and count as outside it. - */ - private static function isWithinSiteNode(NodeInterface $node, NodeInterface $siteNode): bool - { - if (!$node instanceof TraversableNodeInterface || !$siteNode instanceof TraversableNodeInterface) { - return false; - } - - $nodePath = $node->findNodePath(); - $siteNodePath = $siteNode->findNodePath(); - - return $nodePath->equals($siteNodePath) || str_starts_with((string) $nodePath, $siteNodePath . '/'); - } - /** * Iterate over all sites * @@ -139,46 +74,32 @@ public function sites(): Generator } /** - * Iterate over the site node in all available presets (if it exists) + * Iterate over the site node in all dimension space points (if it exists), hiding disabled nodes unless + * "nodeRendering.recurseHiddenContent" is set * - * @param bool|null $invisibleContentShown NULL follows the "nodeRendering.recurseHiddenContent" setting - * @return Generator + * @return Generator + * @throws AccessDenied */ - public function siteNodeInContexts( - Site $site, - string $workspaceName = 'live', - ?bool $invisibleContentShown = null, - ): Generator { - $allowedContextCombinations = $this->contentDimensionCombinator->getAllAllowedCombinations(); - - foreach ($allowedContextCombinations as $dimensionContextCombination) { - $contentContext = $this->contextFactory->create(array( - 'currentSite' => $site, - 'workspaceName' => $workspaceName, - 'dimensions' => $dimensionContextCombination, - 'targetDimensions' => [], - 'invisibleContentShown' => $invisibleContentShown ?? $this->recurseHiddenContent, - )); - - $siteNode = $contentContext->getNode('/sites/' . $site->getNodeName()); - - if ($siteNode instanceof NodeInterface) { - yield $siteNode; - } - } - } - - /** - * Iterate over the given node and all document child nodes recursively - * - * @return Generator - */ - public function recurseDocumentChildNodes(NodeInterface $node): Generator + public function siteNodeInContexts(Site $site, string $workspaceName = 'live'): Generator { - yield $node; + $contentRepository = $this->contentRepositoryRegistry->get($site->getConfiguration()->contentRepositoryId); + $contentGraph = $contentRepository->getContentGraph(WorkspaceName::fromString($workspaceName)); + $visibilityConstraints = $this->recurseHiddenContent + ? NeosVisibilityConstraints::excludeRemoved() + : NeosVisibilityConstraints::excludeRemoved()->merge(NeosVisibilityConstraints::excludeDisabled()); + + foreach ($contentRepository->getVariationGraph()->getDimensionSpacePoints() as $dimensionSpacePoint) { + $subgraph = $contentGraph->getSubgraph($dimensionSpacePoint, $visibilityConstraints); + + $sitesNode = $subgraph->findRootNodeByType(NodeTypeNameFactory::forSites()); + if ($sitesNode === null) { + continue; + } - foreach ($node->getChildNodes('Neos.Neos:Document') as $childNode) { - yield from $this->recurseDocumentChildNodes($childNode); + $siteNode = $subgraph->findNodeByPath($site->getNodeName()->toNodeName(), $sitesNode->aggregateId); + if ($siteNode !== null) { + yield $siteNode; + } } } } diff --git a/Classes/NodeEnumeration/NodeEnumerator.php b/Classes/NodeEnumeration/NodeEnumerator.php index ea5a0e0..7e0c41e 100644 --- a/Classes/NodeEnumeration/NodeEnumerator.php +++ b/Classes/NodeEnumeration/NodeEnumerator.php @@ -16,7 +16,6 @@ use Flowpack\DecoupledContentStore\NodeRendering\Extensibility\NodeRenderingExtensionManager; use Flowpack\DecoupledContentStore\PrepareContentRelease\Infrastructure\RedisContentReleaseService; use Flowpack\DecoupledContentStore\Utility\GeneratorUtility; -use Neos\ContentRepository\Domain\Model\NodeInterface; use Neos\Eel\Exception; use Neos\Eel\FlowQuery\FlowQuery; use Neos\Flow\Annotations as Flow; @@ -126,20 +125,20 @@ private function enumerateAll( foreach ($combinator->siteNodeInContexts($site, $workspaceName) as $siteNode) { $startTime = microtime(true); - $dimensionValues = $siteNode->getContext()->getDimensions(); + $dimensionValues = $siteNode->dimensionSpacePoint->coordinates; $contentReleaseLogger->debug('Publishing dimension combination', [ 'dimensionValues' => $dimensionValues, ]); $nodeQuery = new FlowQuery([$siteNode]); - /** @var NodeInterface[] $matchingNodes */ + /** @var \Neos\ContentRepository\Core\Projection\ContentGraph\Node[] $matchingNodes */ $matchingNodes = $nodeQuery->find($nodeTypeFilter)->add($siteNode)->get(); foreach ($matchingNodes as $nodeToEnumerate) { - $contextPath = $nodeToEnumerate->getContextPath(); + $contextPath = \Neos\ContentRepository\Core\SharedModel\Node\NodeAddress::fromNode($nodeToEnumerate)->toJson(); - $skipReason = $this->documentNodeFilter->skipReason($nodeToEnumerate, $siteNode); + $skipReason = $this->documentNodeFilter->skipReason($nodeToEnumerate); if ($skipReason !== null) { $contentReleaseLogger->debug('Skipping node from publishing, because it is ' . $skipReason, [ 'node' => $contextPath, diff --git a/Classes/NodeRendering/Dto/DocumentNodeCacheKey.php b/Classes/NodeRendering/Dto/DocumentNodeCacheKey.php index d32f723..36c0cae 100644 --- a/Classes/NodeRendering/Dto/DocumentNodeCacheKey.php +++ b/Classes/NodeRendering/Dto/DocumentNodeCacheKey.php @@ -5,64 +5,46 @@ namespace Flowpack\DecoupledContentStore\NodeRendering\Dto; use Flowpack\DecoupledContentStore\NodeEnumeration\Domain\Dto\EnumeratedNode; -use Neos\ContentRepository\Domain\Model\NodeInterface; +use Neos\ContentRepository\Core\Projection\ContentGraph\Node; use Neos\Flow\Annotations as Flow; /** * Represents the top-level Fusion Cache identifier for a rendered node - * - * @Flow\Proxy(false) */ -final class DocumentNodeCacheKey +#[Flow\Proxy(false)] +final readonly class DocumentNodeCacheKey { - /** - * @var string - */ - protected $nodeIdentifier; + private array $arguments; - /** - * @var array - */ - protected $dimensions; + private array $dimensions; - /** - * @var string - */ - protected $workspaceName; - - /** - * @var array - */ - protected $arguments; - - private function __construct(string $nodeIdentifier, array $dimensions, string $workspaceName, array $arguments) + private function __construct( + private string $nodeIdentifier, + array $dimensions, + array $arguments, + ) { // we need to make this deterministic ksort($arguments); ksort($dimensions); - - $this->nodeIdentifier = $nodeIdentifier; $this->dimensions = $dimensions; - $this->workspaceName = $workspaceName; $this->arguments = $arguments; } - public static function fromNodeAndArguments(NodeInterface $node, array $arguments): self + public static function fromNodeAndArguments(Node $node, array $arguments): self { return new self( - $node->getIdentifier(), - $node->getContext()->getDimensions(), - $node->getWorkspace()->getName(), + $node->aggregateId->value, + $node->dimensionSpacePoint->coordinates, $arguments, ); } - public static function fromEnumeratedNode(EnumeratedNode $enumeratedNode) + public static function fromEnumeratedNode(EnumeratedNode $enumeratedNode): self { return new self( $enumeratedNode->getNodeIdentifier(), $enumeratedNode->getDimensionsFromContextPath(), - $enumeratedNode->getWorkspaceNameFromContextPath(), $enumeratedNode->getArguments(), ); } diff --git a/Classes/NodeRendering/Extensibility/DocumentEnumeratorInterface.php b/Classes/NodeRendering/Extensibility/DocumentEnumeratorInterface.php index 246763a..a1cfcde 100644 --- a/Classes/NodeRendering/Extensibility/DocumentEnumeratorInterface.php +++ b/Classes/NodeRendering/Extensibility/DocumentEnumeratorInterface.php @@ -5,7 +5,7 @@ namespace Flowpack\DecoupledContentStore\NodeRendering\Extensibility; use Flowpack\DecoupledContentStore\NodeEnumeration\Domain\Dto\EnumeratedNode; -use Neos\ContentRepository\Domain\Model\NodeInterface; +use Neos\ContentRepository\Core\Projection\ContentGraph\Node; /** * Adjust document enumeration. @@ -27,5 +27,5 @@ public function __construct(array $options = []); /** * @return iterable */ - public function enumerateDocumentNode(NodeInterface $documentNode): iterable; + public function enumerateDocumentNode(Node $documentNode): iterable; } diff --git a/Classes/NodeRendering/Extensibility/DocumentEnumerators/DefaultEnumerator.php b/Classes/NodeRendering/Extensibility/DocumentEnumerators/DefaultEnumerator.php index 843f461..f0476d1 100644 --- a/Classes/NodeRendering/Extensibility/DocumentEnumerators/DefaultEnumerator.php +++ b/Classes/NodeRendering/Extensibility/DocumentEnumerators/DefaultEnumerator.php @@ -6,13 +6,13 @@ use Flowpack\DecoupledContentStore\NodeEnumeration\Domain\Dto\EnumeratedNode; use Flowpack\DecoupledContentStore\NodeRendering\Extensibility\DocumentEnumeratorInterface; -use Neos\ContentRepository\Domain\Model\NodeInterface; +use Neos\ContentRepository\Core\Projection\ContentGraph\Node; class DefaultEnumerator implements DocumentEnumeratorInterface { public function __construct(array $options = []) {} - public function enumerateDocumentNode(NodeInterface $documentNode): iterable + public function enumerateDocumentNode(Node $documentNode): iterable { return [ EnumeratedNode::fromNode($documentNode), diff --git a/Classes/NodeRendering/Extensibility/DocumentEnumerators/LimitEnumerator.php b/Classes/NodeRendering/Extensibility/DocumentEnumerators/LimitEnumerator.php index 4f67b52..9396073 100644 --- a/Classes/NodeRendering/Extensibility/DocumentEnumerators/LimitEnumerator.php +++ b/Classes/NodeRendering/Extensibility/DocumentEnumerators/LimitEnumerator.php @@ -6,7 +6,9 @@ use Flowpack\DecoupledContentStore\NodeEnumeration\Domain\Dto\EnumeratedNode; use Flowpack\DecoupledContentStore\NodeRendering\Extensibility\DocumentEnumeratorInterface; -use Neos\ContentRepository\Domain\Model\NodeInterface; +use Neos\ContentRepository\Core\Projection\ContentGraph\Node; +use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry; +use Neos\Flow\Annotations as Flow; /** * An enumerator which only renders the first N pages. very useful for interactive testing. @@ -14,10 +16,13 @@ */ class LimitEnumerator implements DocumentEnumeratorInterface { - protected int $i = 0; - private ?int $limit = null; - private ?string $uriPathSegmentFilter = null; - private ?string $nodePathSegmentFilter = null; + #[Flow\Inject] + protected ContentRepositoryRegistry $contentRepositoryRegistry; + + private int $i = 0; + private ?int $limit; + private ?string $uriPathSegmentFilter; + private ?string $nodePathSegmentFilter; public function __construct( array $options = [], @@ -27,7 +32,7 @@ public function __construct( $this->nodePathSegmentFilter = $options['nodePathSegmentFilter'] ?? null; } - public function enumerateDocumentNode(NodeInterface $documentNode): iterable + public function enumerateDocumentNode(Node $documentNode): iterable { if ( $this->uriPathSegmentFilter !== null @@ -35,10 +40,14 @@ public function enumerateDocumentNode(NodeInterface $documentNode): iterable ) { return []; } + $subgraph = $this->contentRepositoryRegistry->subgraphForNode($documentNode); if ( $this->nodePathSegmentFilter !== null - && str_contains($documentNode->getPath(), $this->nodePathSegmentFilter) === false + && str_contains( + $subgraph->retrieveNodePath($documentNode->aggregateId)->serializeToString(), + $this->nodePathSegmentFilter, + ) === false ) { return []; } diff --git a/Classes/NodeRendering/Extensibility/DocumentMetadataGeneratorInterface.php b/Classes/NodeRendering/Extensibility/DocumentMetadataGeneratorInterface.php index 9101054..5869f0e 100644 --- a/Classes/NodeRendering/Extensibility/DocumentMetadataGeneratorInterface.php +++ b/Classes/NodeRendering/Extensibility/DocumentMetadataGeneratorInterface.php @@ -5,8 +5,8 @@ namespace Flowpack\DecoupledContentStore\NodeRendering\Extensibility; use Flowpack\DecoupledContentStore\NodeRendering\Dto\DocumentNodeCacheValues; -use Neos\ContentRepository\Domain\Model\NodeInterface; -use Neos\Flow\Mvc\Controller\ControllerContext; +use Neos\ContentRepository\Core\Projection\ContentGraph\Node; +use Neos\Flow\Mvc\ActionRequest; /** * Hook to deeply integrate into the rendering process; at the point where every enumerated document is rendered. @@ -20,9 +20,9 @@ interface DocumentMetadataGeneratorInterface * usually you call return $cacheValues->withMetadata('key', $value) inside this method. Be sure to return the modified cache values passed in. */ public function generateMetadata( - NodeInterface $node, + Node $node, array $arguments, - ControllerContext $controllerContext, + ActionRequest $actionRequest, DocumentNodeCacheValues $cacheValues, ): DocumentNodeCacheValues; } diff --git a/Classes/NodeRendering/Extensibility/DocumentRendererInterface.php b/Classes/NodeRendering/Extensibility/DocumentRendererInterface.php index ef62710..0939898 100644 --- a/Classes/NodeRendering/Extensibility/DocumentRendererInterface.php +++ b/Classes/NodeRendering/Extensibility/DocumentRendererInterface.php @@ -23,7 +23,7 @@ interface DocumentRendererInterface public function tryToExtractRenderingForEnumeratedNodeFromContentCache(EnumeratedNode $enumeratedNode): RenderedDocumentFromContentCache; public function renderDocumentNodeVariant( - NodeInterface $node, + \Neos\ContentRepository\Core\Projection\ContentGraph\Node $node, EnumeratedNode $enumeratedNode, ContentReleaseLogger $contentReleaseLogger, ): void; diff --git a/Classes/NodeRendering/Extensibility/DocumentRenderers/FusionHtmlRenderer.php b/Classes/NodeRendering/Extensibility/DocumentRenderers/FusionHtmlRenderer.php index ccf2227..2181d3b 100644 --- a/Classes/NodeRendering/Extensibility/DocumentRenderers/FusionHtmlRenderer.php +++ b/Classes/NodeRendering/Extensibility/DocumentRenderers/FusionHtmlRenderer.php @@ -36,7 +36,7 @@ public function tryToExtractRenderingForEnumeratedNodeFromContentCache(Enumerate } public function renderDocumentNodeVariant( - NodeInterface $node, + \Neos\ContentRepository\Core\Projection\ContentGraph\Node $node, EnumeratedNode $enumeratedNode, ContentReleaseLogger $contentReleaseLogger, ): void { diff --git a/Classes/NodeRendering/Extensibility/NodeRenderingExtensionManager.php b/Classes/NodeRendering/Extensibility/NodeRenderingExtensionManager.php index aa7c28f..94c2044 100644 --- a/Classes/NodeRendering/Extensibility/NodeRenderingExtensionManager.php +++ b/Classes/NodeRendering/Extensibility/NodeRenderingExtensionManager.php @@ -9,9 +9,9 @@ use Flowpack\DecoupledContentStore\NodeEnumeration\Domain\Dto\EnumeratedNode; use Flowpack\DecoupledContentStore\NodeRendering\Dto\DocumentNodeCacheValues; use Flowpack\DecoupledContentStore\NodeRendering\Dto\RenderedDocumentFromContentCache; -use Neos\ContentRepository\Domain\Model\NodeInterface; +use Neos\ContentRepository\Core\Projection\ContentGraph\Node; use Neos\Flow\Annotations as Flow; -use Neos\Flow\Mvc\Controller\ControllerContext; +use Neos\Flow\Mvc\ActionRequest; /** * @Flow\Scope("singleton") @@ -57,7 +57,7 @@ class NodeRenderingExtensionManager /** * @return iterable */ - public function enumerateDocumentNode(NodeInterface $documentNode): iterable + public function enumerateDocumentNode(Node $documentNode): iterable { if (!isset($this->documentEnumerators)) { $this->documentEnumerators = self::instantiateExtensions( @@ -85,7 +85,7 @@ public function tryToExtractRenderingForEnumeratedNodeFromContentCache(Enumerate } public function renderDocumentNodeVariant( - NodeInterface $node, + Node $node, EnumeratedNode $enumeratedNode, ContentReleaseLogger $contentReleaseLogger, ): void { @@ -113,16 +113,16 @@ protected function rendererFor(EnumeratedNode $enumeratedNode): DocumentRenderer /** * Execute Document Metadata Generators to modify $cacheValues * - * @param NodeInterface $node + * @param Node $node * @param array $arguments - * @param ControllerContext $controllerContext + * @param ActionRequest $actionRequest * @param DocumentNodeCacheValues $cacheValues * @return DocumentNodeCacheValues */ public function runDocumentMetadataGenerators( - NodeInterface $node, + Node $node, array $arguments, - ControllerContext $controllerContext, + ActionRequest $actionRequest, DocumentNodeCacheValues $cacheValues, ): DocumentNodeCacheValues { if (!isset($this->documentMetadataGenerators)) { @@ -136,7 +136,7 @@ public function runDocumentMetadataGenerators( $cacheValues = $documentMetadataGenerator->generateMetadata( $node, $arguments, - $controllerContext, + $actionRequest, $cacheValues, ); } diff --git a/Classes/NodeRendering/InterruptibleProcessRuntime.php b/Classes/NodeRendering/InterruptibleProcessRuntime.php index c3f890e..8858b3c 100644 --- a/Classes/NodeRendering/InterruptibleProcessRuntime.php +++ b/Classes/NodeRendering/InterruptibleProcessRuntime.php @@ -5,7 +5,9 @@ namespace Flowpack\DecoupledContentStore\NodeRendering; use Flowpack\DecoupledContentStore\NodeRendering\ProcessEvents\ExitEvent; +use Generator; use Neos\Flow\Annotations as Flow; +use ReflectionClass; /** * Our long-lived processes, especially {@see NodeRenderOrchestrator} and {@see NodeRenderer} are kind of hard to test, @@ -43,14 +45,14 @@ */ final class InterruptibleProcessRuntime { - private \Generator $generator; + private Generator $generator; private bool $inTestingMode; private bool $encounteredExitEvent = false; private bool $generatorIsPaused = false; - private function __construct(\Generator $generator, bool $inTestingMode) + private function __construct(Generator $generator, bool $inTestingMode) { $this->generator = $generator; $this->inTestingMode = $inTestingMode; @@ -59,10 +61,10 @@ private function __construct(\Generator $generator, bool $inTestingMode) /** * Generate a new Process Runtime in production mode * - * @param \Generator $generator + * @param Generator $generator * @return InterruptibleProcessRuntime */ - public static function create(\Generator $generator): self + public static function create(Generator $generator): self { return new self($generator, false); } @@ -70,10 +72,10 @@ public static function create(\Generator $generator): self /** * Generate a new Process Runtime in testing mode, where {@see ExitEvent} won't trigger an exit() call. * - * @param \Generator $generator + * @param Generator $generator * @return InterruptibleProcessRuntime */ - public static function createForTesting(\Generator $generator): self + public static function createForTesting(Generator $generator): self { return new self($generator, true); } @@ -109,7 +111,7 @@ public function runUntilEventEncountered(string ...$eventClassNames): ?Interrupt // stop iterating the iterator in all cases return $this->handleExitEvent($currentEvent); } - $shortName = (new \ReflectionClass($currentEvent))->getShortName(); + $shortName = new ReflectionClass($currentEvent)->getShortName(); foreach ($eventClassNames as $eventClassName) { if ($eventClassName === $shortName || is_a($currentEvent, $eventClassName)) { // stop here, can be restarted lateron. We still need to continue to the next event here. diff --git a/Classes/NodeRendering/NodeRenderOrchestrator.php b/Classes/NodeRendering/NodeRenderOrchestrator.php index 8d84aff..e8eced7 100644 --- a/Classes/NodeRendering/NodeRenderOrchestrator.php +++ b/Classes/NodeRendering/NodeRenderOrchestrator.php @@ -24,7 +24,7 @@ use Flowpack\DecoupledContentStore\PrepareContentRelease\Infrastructure\RedisContentReleaseService; use Neos\Flow\Annotations as Flow; use Neos\Fusion\Core\Cache\ContentCache; -use Neos\Neos\Fusion\Helper\CachingHelper; +use Neos\Neos\Fusion\Cache\CacheTag; /** * TODO: explain concept of Working Set @@ -104,9 +104,6 @@ class NodeRenderOrchestrator #[Flow\Inject] protected ContentCache $contentCache; - #[Flow\Inject] - protected CachingHelper $cachingHelper; - #[Flow\InjectConfiguration('nodeRendering.flushDocumentCacheOnRetry')] protected bool $flushDocumentCacheOnRetry; @@ -434,13 +431,12 @@ private function flushContentCacheForRetry( ): void { $tags = []; foreach ($nodesScheduledForRendering as $enumeratedNode) { - $tags[] = - 'Node_' - . $this->cachingHelper->renderWorkspaceTagForContextNode( - $enumeratedNode->getWorkspaceNameFromContextPath(), - ) - . '_' - . $enumeratedNode->getNodeIdentifier(); + $nodeAddress = $enumeratedNode->getNodeAddress(); + $tags[] = CacheTag::forNodeAggregate( + $nodeAddress->contentRepositoryId, + $nodeAddress->workspaceName, + $nodeAddress->aggregateId, + )->value; } foreach (array_unique($tags) as $tag) { diff --git a/Classes/NodeRendering/NodeRenderer.php b/Classes/NodeRendering/NodeRenderer.php index ec6443a..bf4bf0f 100644 --- a/Classes/NodeRendering/NodeRenderer.php +++ b/Classes/NodeRendering/NodeRenderer.php @@ -10,6 +10,7 @@ use Flowpack\DecoupledContentStore\Core\Infrastructure\ContentReleaseLogger; use Flowpack\DecoupledContentStore\Exception\RenderingException; use Flowpack\DecoupledContentStore\NodeEnumeration\Domain\Dto\EnumeratedNode; +use Flowpack\DecoupledContentStore\NodeEnumeration\Domain\Service\NodeContextCombinator; use Flowpack\DecoupledContentStore\NodeRendering\Dto\RendererIdentifier; use Flowpack\DecoupledContentStore\NodeRendering\Extensibility\NodeRenderingExtensionManager; use Flowpack\DecoupledContentStore\NodeRendering\Infrastructure\RedisRenderingErrorManager; @@ -21,11 +22,13 @@ use Flowpack\DecoupledContentStore\NodeRendering\Tracing\RenderTracerInterface; use Flowpack\DecoupledContentStore\NodeRendering\Tracing\RenderTracerProvider; use Flowpack\DecoupledContentStore\PrepareContentRelease\Infrastructure\RedisContentReleaseService; -use Neos\ContentRepository\Domain\Model\NodeInterface; -use Neos\ContentRepository\Domain\Service\ContextFactoryInterface; +use Neos\ContentRepository\Core\Projection\ContentGraph\Node; +use Neos\ContentRepository\Core\SharedModel\Node\NodeAddress; +use Neos\ContentRepository\Core\SharedModel\Node\NodeAggregateId; +use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry; use Neos\Flow\Annotations as Flow; use Neos\Flow\Persistence\PersistenceManagerInterface; -use Neos\Neos\Domain\Repository\SiteRepository; +use Neos\Neos\Domain\SubtreeTagging\NeosVisibilityConstraints; /** * Not called directly, but through Scripts/renderWorker.sh. @@ -85,18 +88,6 @@ class NodeRenderer */ protected $redisContentReleaseService; - /** - * @Flow\Inject - * @var SiteRepository - */ - protected $siteRepository; - - /** - * @Flow\Inject - * @var ContextFactoryInterface - */ - protected $contextFactory; - /** * @Flow\Inject * @var ContentReleaseManager @@ -124,6 +115,12 @@ class NodeRenderer #[Flow\Inject] protected RenderTracerProvider $renderTracerProvider; + #[Flow\Inject] + protected ContentRepositoryRegistry $contentRepositoryRegistry; + + #[Flow\InjectConfiguration('nodeRendering.recurseHiddenContent')] + protected bool $recurseHiddenContent; + public function render( ContentReleaseIdentifier $contentReleaseIdentifier, ContentReleaseLogger $contentReleaseLogger, @@ -247,15 +244,15 @@ protected function renderDocumentNodeVariant( try { $node = $this->fetchRenderableNode($enumeratedNode); - if (!$node instanceof NodeInterface) { + if (!$node instanceof \Neos\ContentRepository\Core\Projection\ContentGraph\Node) { // This could happen because a deleted node was queued after publishing $nodeWasFound = false; } else { $nodeWasFound = true; $contentReleaseLogger->debug('Rendering document node variant', [ - 'node' => $node->getContextPath(), - 'nodeIdentifier' => $node->getIdentifier(), + 'node' => NodeAddress::fromNode($node)->toJson(), + 'nodeIdentifier' => $node->aggregateId->value, 'workspaceName' => $enumeratedNode->getWorkspaceNameFromContextPath(), 'dimensions' => $enumeratedNode->getDimensionsFromContextPath(), 'arguments' => $enumeratedNode->getArguments(), @@ -264,13 +261,12 @@ protected function renderDocumentNodeVariant( $tracer = $this->renderTracerProvider->getTracer(); $spanParams = [ - 'node' => $node->getContextPath(), - 'site' => $enumeratedNode->getSiteNodeNameFromContextPath(), + 'node' => NodeAddress::fromNode($node)->toJson(), 'dimensions' => $enumeratedNode->getDimensionsFromContextPath(), 'arguments' => $enumeratedNode->getArguments(), ]; $tracer->openSpan(self::SPAN_RENDER_DOCUMENT, $spanParams); - $tracer->openSpan(self::SPAN_DOCUMENT_PREFIX . $node->getContextPath(), $spanParams); + $tracer->openSpan(self::SPAN_DOCUMENT_PREFIX . NodeAddress::fromNode($node)->toJson(), $spanParams); try { $this->nodeRenderingExtensionManager->renderDocumentNodeVariant( $node, @@ -347,20 +343,21 @@ protected function renderDocumentNodeVariant( } /** - * @param EnumeratedNode $enumeratedNode - * @return NodeInterface|null - * @throws \Exception + * Looks the node up by its identifier, not by the stored address as a whole: the node may have moved since the + * enumeration. Visibility follows {@see NodeContextCombinator::siteNodeInContexts()}, so a document which was + * hidden after the enumeration is not found. */ - protected function fetchRenderableNode(EnumeratedNode $enumeratedNode): ?NodeInterface + protected function fetchRenderableNode(EnumeratedNode $enumeratedNode): ?Node { - $site = $this->siteRepository->findOneByNodeName($enumeratedNode->getSiteNodeNameFromContextPath()); - - $context = $this->contextFactory->create([ - 'workspaceName' => $enumeratedNode->getWorkspaceNameFromContextPath(), - 'currentSite' => $site, - 'currentDomain' => $site->getFirstActiveDomain(), - 'dimensions' => $enumeratedNode->getDimensionsFromContextPath(), - ]); - return $context->getNodeByIdentifier($enumeratedNode->getNodeIdentifier()); + $nodeAddress = $enumeratedNode->getNodeAddress(); + $visibilityConstraints = $this->recurseHiddenContent + ? NeosVisibilityConstraints::excludeRemoved() + : NeosVisibilityConstraints::excludeRemoved()->merge(NeosVisibilityConstraints::excludeDisabled()); + + return $this->contentRepositoryRegistry + ->get($nodeAddress->contentRepositoryId) + ->getContentGraph($nodeAddress->workspaceName) + ->getSubgraph($nodeAddress->dimensionSpacePoint, $visibilityConstraints) + ->findNodeById(NodeAggregateId::fromString($enumeratedNode->getNodeIdentifier())); } } diff --git a/Classes/NodeRendering/NodeRenderingUriService.php b/Classes/NodeRendering/NodeRenderingUriService.php index 0af8708..9ec7151 100644 --- a/Classes/NodeRendering/NodeRenderingUriService.php +++ b/Classes/NodeRendering/NodeRenderingUriService.php @@ -9,9 +9,11 @@ use Flowpack\DecoupledContentStore\NodeRendering\Render\DocumentRenderer; use Flowpack\DecoupledContentStore\Transfer\Resource\Target\MultisiteFileSystemSymlinkTarget; use GuzzleHttp\Psr7\ServerRequest; -use Neos\ContentRepository\Domain\Model\NodeInterface; +use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindClosestNodeFilter; +use Neos\ContentRepository\Core\Projection\ContentGraph\Node; +use Neos\ContentRepository\Core\SharedModel\Node\NodeAddress; +use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry; use Neos\Flow\Annotations as Flow; -use Neos\Flow\Configuration\ConfigurationManager; use Neos\Flow\Http\BaseUriProvider; use Neos\Flow\Http\Helper\RequestInformationHelper; use Neos\Flow\Http\ServerRequestAttributes; @@ -24,7 +26,9 @@ use Neos\Flow\ResourceManagement\ResourceManager; use Neos\Flow\Security\Context as SecurityContext; use Neos\Neos\Domain\Model\Site; -use Neos\Neos\Service\LinkingService; +use Neos\Neos\Domain\Repository\SiteRepository; +use Neos\Neos\Domain\Service\NodeTypeNameFactory; +use Neos\Neos\FrontendRouting\SiteDetection\SiteDetectionResult; use Neos\Utility\ObjectAccess; /** @@ -33,38 +37,30 @@ */ final class NodeRenderingUriService { - #[Flow\Inject] - protected ConfigurationManager $configurationManager; - - /** - * NOTE: we need to use EAGER injection here, because in buildControllerContextAndSetBaseUri(), we - * directly set a property of the BaseUriProvider using ObjectAccess::setProperty() with forceDirectAccess. - */ - #[Flow\Inject(lazy: false)] - protected BaseUriProvider $baseUriProvider; - - #[Flow\Inject] - protected LinkingService $linkingService; - - #[Flow\Inject] - protected SecurityContext $securityContext; - - #[Flow\Inject] - protected ResourceManager $resourceManager; - #[Flow\InjectConfiguration('nodeRendering.useRelativeResourceUris')] protected bool $useRelativeResourceUris; + public function __construct( + private readonly BaseUriProvider $baseUriProvider, + private readonly SecurityContext $securityContext, + private readonly ResourceManager $resourceManager, + private readonly ContentRepositoryRegistry $contentRepositoryRegistry, + private readonly SiteRepository $siteRepository, + ) {} + /** - * @param NodeInterface $node + * @param Node $node * @param array $arguments * @return string The resolved URI for the given node * @throws \Exception */ - public function buildNodeUri(NodeInterface $node, array $arguments): string + public function buildNodeUri(Node $node, array $arguments): string { - /** @var Site $currentSite */ - $currentSite = $node->getContext()->getCurrentSite(); + $currentSite = $this->findSiteForNode($node) + ?? throw new Exception( + sprintf('No site node found for node %s', $node->aggregateId->value), + 1762862400, + ); if (!$currentSite->hasActiveDomains()) { throw new Exception(sprintf('Site %s has no active domain', $currentSite->getNodeName()), 1666684522); } @@ -89,19 +85,17 @@ public function buildNodeUri(NodeInterface $node, array $arguments): string $arguments, ); $format = $arguments['@format'] ?? 'html'; - $uri = $this->linkingService->createNodeUri( - $baseControllerContext, - $node, - null, - $format, - true, - $arguments, - '', - false, - [], - false, - ); - return self::removeQueryPartFromUri($uri); + $uri = $baseControllerContext + ->getUriBuilder() + ->reset() + ->setArguments($arguments) + ->setFormat($format) + ->setCreateAbsoluteUri(true) + ->uriFor('show', ['node' => NodeAddress::fromNode($node)->toJson()], 'Frontend\\Node', 'Neos.Neos'); + + // remove query from uri + $uriData = explode('?', $uri); + return $uriData[0]; } /** @@ -109,7 +103,7 @@ public function buildNodeUri(NodeInterface $node, array $arguments): string */ public function buildControllerContextAndSetBaseUri( string $uri, - NodeInterface $node, + Node $node, array $arguments = [], ): ControllerContext { @@ -140,11 +134,9 @@ public function buildControllerContextAndSetBaseUri( * broken host. Targets that already have an override keep it: callers like DocumentRenderer, or exports that * want relative URIs, set it explicitly. */ - private function injectResourceBaseUri(NodeInterface $node): void + private function injectResourceBaseUri(Node $node): void { - /** @var Site|null $currentSite */ - $currentSite = $node->getContext()->getCurrentSite(); - $domain = $currentSite?->getFirstActiveDomain(); + $domain = $this->findSiteForNode($node)?->getFirstActiveDomain(); if ($domain === null) { return; } @@ -159,14 +151,32 @@ private function injectResourceBaseUri(NodeInterface $node): void } } - private function buildFakeRequest(string $uri, NodeInterface $node): ActionRequest + public function findSiteForNode(Node $node): ?Site + { + $siteNode = $this->contentRepositoryRegistry->subgraphForNode($node)->findClosestNode( + $node->aggregateId, + FindClosestNodeFilter::create(NodeTypeNameFactory::NAME_SITE), + ); + + return $siteNode === null ? null : $this->siteRepository->findSiteBySiteNode($siteNode); + } + + private function buildFakeRequest(string $uri, Node $node): ActionRequest { $_SERVER['FLOW_REWRITEURLS'] = '1'; $httpRequest = new ServerRequest('GET', $uri); - $routingParameters = RouteParameters::createEmpty()->withParameter( - 'requestUriHost', - $httpRequest->getUri()->getHost(), + $site = $this->findSiteForNode($node) + ?? throw new Exception( + sprintf('No site node found for node %s', $node->aggregateId->value), + 1762862402, + ); + // what the SiteDetectionMiddleware stores for a real request - Neos' frontend routing reads it from here + $routingParameters = SiteDetectionResult::create( + $site->getNodeName(), + $site->getConfiguration()->contentRepositoryId, + )->storeInRouteParameters( + RouteParameters::createEmpty()->withParameter('requestUriHost', $httpRequest->getUri()->getHost()), ); $httpRequest = $httpRequest->withAttribute(ServerRequestAttributes::ROUTING_PARAMETERS, $routingParameters); @@ -174,33 +184,16 @@ private function buildFakeRequest(string $uri, NodeInterface $node): ActionReque $request->setControllerObjectName('Neos\Neos\Controller\Frontend\NodeController'); $request->setControllerActionName('show'); $request->setFormat('html'); - $request->setArgument('node', $node->getContextPath()); + $request->setArgument('node', NodeAddress::fromNode($node)->toJson()); return $request; } - /** - * @param ActionRequest $request - * @return UriBuilder - * @throws \Neos\Utility\Exception\PropertyNotAccessibleException - */ private function uriBuilderForRequest(ActionRequest $request): UriBuilder { $uriBuilder = new UriBuilder(); $uriBuilder->setRequest($request); - $routesConfiguration = $this->configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_ROUTES); - $router = ObjectAccess::getProperty($uriBuilder, 'router', true); - - $router->setRoutesConfiguration($routesConfiguration); - return $uriBuilder; } - - private static function removeQueryPartFromUri(string $uri): string - { - $uriData = explode('?', $uri); - - return $uriData[0]; - } } diff --git a/Classes/NodeRendering/Render/CustomFusionView.php b/Classes/NodeRendering/Render/CustomFusionView.php index bf8af7a..98e491f 100644 --- a/Classes/NodeRendering/Render/CustomFusionView.php +++ b/Classes/NodeRendering/Render/CustomFusionView.php @@ -4,63 +4,78 @@ namespace Flowpack\DecoupledContentStore\NodeRendering\Render; -use Neos\ContentRepository\Domain\Projection\Content\TraversableNodeInterface; -use Neos\Fusion\Core\Cache\RuntimeContentCache; +use Neos\ContentRepository\Core\Projection\ContentGraph\Node; +use Neos\Flow\Annotations as Flow; +use Neos\Flow\Mvc\Controller\ControllerContext; +use Neos\Fusion\Core\FusionConfiguration; +use Neos\Fusion\Core\FusionGlobals; +use Neos\Fusion\Core\FusionSourceCodeCollection; +use Neos\Fusion\Core\Parser; use Neos\Fusion\Core\Runtime; +use Neos\Fusion\Core\RuntimeConfiguration; +use Neos\Neos\Domain\Model\Site; +use Neos\Neos\Domain\Service\FusionSourceCodeFactory; use Neos\Neos\View\FusionView; +use ReflectionProperty; /** - * This Fusion View improves performance by: - * - re-using merged Fusion Object Tree throughout multiple renderings - * - also re-using the Fusion Runtime with all caches. + * This Fusion View improves performance by re-using, per site, the merged Fusion configuration and the + * Fusion Runtime's path configuration cache across all documents of a content release. * - * This leads to a tremendous speed up; in my local tests the full publish - * before was about 3h; now it is about 1h10. + * The Runtime itself is created per document: its "request" Fusion global is readonly, and the request + * differs for every rendered document (URI, format, base URI). */ class CustomFusionView extends FusionView { - private $fusionRuntimePerSiteNode = []; + public static bool $useCustomSiteRootFusionPatternEntryPointForBehavioralTests = false; /** - * @var \ReflectionProperty + * @var array */ - private $controllerContextAccessor; - /** - * @var \ReflectionProperty - */ - private $runtimeContentCacheAccessor; - /** - * @var \ReflectionProperty - */ - private $defaultContextVariablesAccessor; + private array $fusionConfigurationPerSiteNode = []; /** - * @var boolean + * @var array */ - private $contentCacheEnabled = true; + private array $runtimeConfigurationPerSiteNode = []; + + private ReflectionProperty $runtimeConfigurationAccessor; + + private bool $contentCacheEnabled = true; + + #[Flow\Inject] + protected Parser $fusionParser; - public static $useCustomSiteRootFusionPatternEntryPointForBehavioralTests = false; + #[Flow\Inject] + protected FusionSourceCodeFactory $fusionSourceCodeFactory; public function __construct(array $options = []) { parent::__construct($options); - $this->controllerContextAccessor = new \ReflectionProperty(Runtime::class, 'controllerContext'); - $this->controllerContextAccessor->setAccessible(true); - - $this->runtimeContentCacheAccessor = new \ReflectionProperty(Runtime::class, 'runtimeContentCache'); - $this->runtimeContentCacheAccessor->setAccessible(true); + $this->fusionRuntime = null; + $this->runtimeConfigurationAccessor = new ReflectionProperty(Runtime::class, 'runtimeConfiguration'); + } - $this->defaultContextVariablesAccessor = new \ReflectionProperty(Runtime::class, 'defaultContextVariables'); - $this->defaultContextVariablesAccessor->setAccessible(true); + /** + * The view is reused for every document, so the request of the current document has to replace the + * previous one (the parent only sets it once). + */ + public function setControllerContext(ControllerContext $controllerContext): void + { + $this->assignedActionRequest = $controllerContext->getRequest(); } - public function initializeObject() + /** + * The parent resolves the site node lazily and stores it as the "site" variable; with a reused view + * it has to be resolved again for every document, which may belong to another site or dimension. + */ + public function assign(string $key, mixed $value): self { - if (self::$useCustomSiteRootFusionPatternEntryPointForBehavioralTests) { - // for self-contained tests, we read fusion from another folder. - $this->fusionService->setSiteRootFusionPattern('resource://%s/Private/EndToEndTestFusion/Root.fusion'); + if ($key === 'value') { + unset($this->variables['site']); } + return parent::assign($key, $value); } /** @@ -97,7 +112,7 @@ public function initializeObject() * 2. EXISTING FusionRuntime instances (if we call this method, for whatever reason, already * during a rendering). In this case, we can directly set $this->fusionRuntime->setEnableContentCache(false); */ - public function disableCache() + public function disableCache(): void { $this->contentCacheEnabled = false; @@ -109,7 +124,7 @@ public function disableCache() /** * See disableCache() method for detailed documentation. */ - public function enableCache() + public function enableCache(): void { $this->contentCacheEnabled = true; @@ -118,54 +133,65 @@ public function enableCache() } } - /** - * @param TraversableNodeInterface $currentSiteNode - * @return \Neos\Fusion\Core\Runtime - */ - protected function getFusionRuntime(TraversableNodeInterface $currentSiteNode) + protected function getFusionRuntime(Node $currentSiteNode): Runtime { - // $this->fusionRuntime is RESET during a call to self::assign() - // so this means for every rendered document, we enter this block again + // $this->fusionRuntime is reset by every assign(), so this block runs for every rendered document. if ($this->fusionRuntime === null) { - $currentSiteNodeContextPath = $currentSiteNode->getContextPath(); - - if (!isset($this->fusionRuntimePerSiteNode[$currentSiteNodeContextPath])) { - // OPTIMIZATION 1: we only want to parse the fusion code ONCE and then reuse it again and again. - // This is done by reusing FusionRuntime again and again. - $fusionObjectTree = $this->fusionService->getMergedFusionObjectTree($currentSiteNode); - - // ... but we need to watch out, as the FusionRuntime also gets $this->controllerContext passed in, - // !!*WHICH CHANGES FOR EVERY DOCUMENT*!! - $this->fusionRuntimePerSiteNode[$currentSiteNodeContextPath] = new Runtime( - $fusionObjectTree, - $this->controllerContext, - ); + $siteNodeKey = $currentSiteNode->contentRepositoryId->value . '|' . $currentSiteNode->aggregateId->value; + + if (!isset($this->fusionConfigurationPerSiteNode[$siteNodeKey])) { + $site = $this->siteRepository->findSiteBySiteNode($currentSiteNode); + $this->fusionConfigurationPerSiteNode[$siteNodeKey] = + self::$useCustomSiteRootFusionPatternEntryPointForBehavioralTests + ? $this->createEndToEndTestFusionConfiguration($site) + : $this->fusionService->createFusionConfigurationFromSite($site); } - $this->fusionRuntime = $this->fusionRuntimePerSiteNode[$currentSiteNodeContextPath]; - - // Luckily for us, the ControllerContext is only stored at $fusionRuntime->controllerContext; - // so we can simply set it for reflection. - // HOWEVER, controllerContext->getRequest() is additionally cached in Runtime::defaultContextVariables, - // so we need to reset this properly as well (see next block). - $this->controllerContextAccessor->setValue($this->fusionRuntime, $this->controllerContext); - - // getDefaultContextVariables() caches the "request" from the controller context lazily. - // As we need the updated request (e.g. with a different format or base URI), we need to reset - // the defaultContextVariables between renderings. - $this->defaultContextVariablesAccessor->setValue($this->fusionRuntime, null); - - // technically, we do NOT need to replace the RuntimeContentCache (it works as well without the next line) - // but I felt this would be an additional safeguard against problems with the cache (e.g. content leaking through dimensions or pages) - $this->runtimeContentCacheAccessor->setValue( - $this->fusionRuntime, - new RuntimeContentCache($this->fusionRuntime), + + $renderingMode = $this->renderingModeService->findByName($this->getOption('renderingModeName')); + $this->fusionRuntime = $this->runtimeFactory->createFromConfiguration( + $this->fusionConfigurationPerSiteNode[$siteNodeKey], + FusionGlobals::fromArray(array_filter([ + 'request' => $this->assignedActionRequest, + 'renderingMode' => $renderingMode, + ])), ); - // after replacing the RuntimeContentCache, we again need to enable the content cache explicitly. - // Otherwise, we do not get any contents into the content store. + // The path configuration cache only depends on the Fusion configuration, so it is shared by all + // Runtimes of a site instead of being rebuilt for every document. + if (isset($this->runtimeConfigurationPerSiteNode[$siteNodeKey])) { + $this->runtimeConfigurationAccessor->setValue( + $this->fusionRuntime, + $this->runtimeConfigurationPerSiteNode[$siteNodeKey], + ); + } else { + $this->runtimeConfigurationPerSiteNode[$siteNodeKey] = + $this->runtimeConfigurationAccessor->getValue($this->fusionRuntime); + } + // We use the property here as the content cache might currently be disabled. $this->fusionRuntime->setEnableContentCache($this->contentCacheEnabled); } return $this->fusionRuntime; } + + /** + * Self-contained behavioral tests read the site's Fusion from Private/EndToEndTestFusion instead of + * Private/Fusion. + */ + private function createEndToEndTestFusionConfiguration(Site $site): FusionConfiguration + { + return $this->fusionParser->parseFromSource( + $this->fusionSourceCodeFactory + ->createFromNodeTypeDefinitions($site->getConfiguration()->contentRepositoryId) + ->union($this->fusionSourceCodeFactory->createFromAutoIncludes()) + ->union( + FusionSourceCodeCollection::fromFilePath( + sprintf( + 'resource://%s/Private/EndToEndTestFusion/Root.fusion', + $site->getSiteResourcesPackageKey(), + ), + ), + ), + ); + } } diff --git a/Classes/NodeRendering/Render/DocumentRenderer.php b/Classes/NodeRendering/Render/DocumentRenderer.php index 69ac7c4..d27b5c6 100644 --- a/Classes/NodeRendering/Render/DocumentRenderer.php +++ b/Classes/NodeRendering/Render/DocumentRenderer.php @@ -69,13 +69,13 @@ class DocumentRenderer /** * Render a specific node variant * - * @param NodeInterface $node + * @param \Neos\ContentRepository\Core\Projection\ContentGraph\Node $node * @param array $arguments Request arguments when rendering the node * @return string the rendered document (not needed inside this package, but might be useful for others who want to trigger the rendering) * @throws Exception\RenderingException */ public function renderDocumentNodeVariant( - NodeInterface $node, + \Neos\ContentRepository\Core\Projection\ContentGraph\Node $node, array $arguments, ContentReleaseLogger $contentReleaseLogger, ): string { @@ -83,7 +83,7 @@ public function renderDocumentNodeVariant( $nodeUri = $this->nodeRenderingUriService->buildNodeUri($node, $arguments); try { - $arguments['node'] = $node->getContextPath(); + $arguments['node'] = \Neos\ContentRepository\Core\SharedModel\Node\NodeAddress::fromNode($node)->toJson(); return $this->renderDocumentView($node, $nodeUri, $arguments, $contentReleaseLogger); } catch (\Exception $exception) { throw new Exception\RenderingException( @@ -104,14 +104,14 @@ public function renderDocumentNodeVariant( * This will set up a simulated request for rendering the view. If the output contains a "next link" * it will render * - * @param NodeInterface $node + * @param \Neos\ContentRepository\Core\Projection\ContentGraph\Node $node * @param string $uri The URI for the node * @param array $requestArguments Plain request arguments (e.g. node by context path), could come from routing match results * @return string the rendered output * @throws Exception\InvalidSiteConfigurationException */ protected function renderDocumentView( - NodeInterface $node, + \Neos\ContentRepository\Core\Projection\ContentGraph\Node $node, $uri, array $requestArguments, ContentReleaseLogger $contentReleaseLogger, @@ -119,9 +119,11 @@ protected function renderDocumentView( $this->isRendering = true; try { - /** @var ContentContext $contentContext */ - $contentContext = $node->getContext(); - $site = $contentContext->getCurrentSite(); + $site = $this->nodeRenderingUriService->findSiteForNode($node) + ?? throw new Exception\InvalidSiteConfigurationException( + 'No site node found for node ' . $node->aggregateId->value, + 1762862401, + ); $domain = $site->getFirstActiveDomain(); $baseUri = (string) $domain; if ($baseUri === '') { diff --git a/Classes/Package.php b/Classes/Package.php index cdb1315..cf2f738 100644 --- a/Classes/Package.php +++ b/Classes/Package.php @@ -4,10 +4,10 @@ namespace Flowpack\DecoupledContentStore; -use Neos\ContentRepository\Domain\Model\Workspace; use Neos\Flow\Core\Bootstrap; use Neos\Flow\Mvc\Controller\ControllerInterface; use Neos\Flow\Package\Package as BasePackage; +use Neos\Media\Domain\Service\AssetService; class Package extends BasePackage { @@ -19,11 +19,14 @@ public function boot(Bootstrap $bootstrap) { $dispatcher = $bootstrap->getSignalSlotDispatcher(); + // Neos.Neos connects its own AssetChangeHandlerForCacheFlushing first (it boots before this package), so the + // cache tags are already collected when this slot runs. $dispatcher->connect( - Workspace::class, - 'afterNodePublishing', - IncrementalContentReleaseHandler::class, - 'nodePublished', + AssetService::class, + 'assetUpdated', + AssetChangeContentReleaseHandler::class, + 'assetUpdated', + false, ); // NASTY WORKAROUND - explanation follows. diff --git a/Classes/QuickPublish/QuickPublishNodeEnumerator.php b/Classes/QuickPublish/QuickPublishNodeEnumerator.php index ebb1d85..796e6cd 100644 --- a/Classes/QuickPublish/QuickPublishNodeEnumerator.php +++ b/Classes/QuickPublish/QuickPublishNodeEnumerator.php @@ -21,7 +21,8 @@ use Flowpack\DecoupledContentStore\PrepareContentRelease\Infrastructure\RedisContentReleaseService; use Flowpack\DecoupledContentStore\QuickPublish\Dto\NodeIdentifiers; use Flowpack\DecoupledContentStore\Utility\GeneratorUtility; -use Neos\ContentRepository\Domain\Model\NodeInterface; +use Neos\ContentRepository\Core\Projection\ContentGraph\Node; +use Neos\ContentRepository\Core\SharedModel\Node\NodeAddress; use Neos\Flow\Annotations as Flow; use Neos\Fusion\Core\Cache\ContentCache; use Neos\Neos\Fusion\Helper\CachingHelper; @@ -145,7 +146,7 @@ public function enumerateGivenNodesAndStoreInRedis( * marks the security context as initialized as a side effect, which would change what the node lookups of the * remaining identifiers are allowed to see. * - * @param array $nodesToRender + * @param array $nodesToRender */ private function writeChangedUrls( array $nodesToRender, @@ -167,7 +168,7 @@ private function writeChangedUrls( /** * The node variants to render, skipping every given identifier which must not or cannot be published. * - * @return array + * @return array */ private function enumerateGivenNodes( NodeIdentifiers $nodeIdentifiers, @@ -179,17 +180,16 @@ private function enumerateGivenNodes( foreach ($nodeIdentifiers as $nodeIdentifier) { $contentCacheFlushed = false; - $variants = $this->nodeContextCombinator->nodeVariantsWithSiteNode($nodeIdentifier, $workspaceName); - foreach ($variants as [$siteNode, $nodeToEnumerate]) { + foreach ($this->nodeContextCombinator->nodeVariants($nodeIdentifier, $workspaceName) as $nodeToEnumerate) { if (!$contentCacheFlushed) { // the tags carry the node identifier and the workspace, so one flush covers every dimension $this->flushContentCacheForNode($nodeToEnumerate, $nodeIdentifier, $contentReleaseLogger); $contentCacheFlushed = true; } - $contextPath = $nodeToEnumerate->getContextPath(); + $contextPath = NodeAddress::fromNode($nodeToEnumerate)->toJson(); - $skipReason = $this->documentNodeFilter->skipReasonForNamedNode($nodeToEnumerate, $siteNode); + $skipReason = $this->documentNodeFilter->skipReasonForNamedNode($nodeToEnumerate); if ($skipReason !== null) { // warn rather than debug: somebody asked for this node by hand and will not see it change $contentReleaseLogger->warn('Skipping node from publishing, because it is ' . $skipReason, [ @@ -228,7 +228,7 @@ private function enumerateGivenNodes( * it copied - the editor's change would be missing without a single error anywhere. */ private function flushContentCacheForNode( - NodeInterface $node, + Node $node, string $nodeIdentifier, ContentReleaseLogger $contentReleaseLogger, ): void { diff --git a/Classes/QuickPublish/QuickPublishPreviewService.php b/Classes/QuickPublish/QuickPublishPreviewService.php index 4f1e330..19ccbf0 100644 --- a/Classes/QuickPublish/QuickPublishPreviewService.php +++ b/Classes/QuickPublish/QuickPublishPreviewService.php @@ -8,10 +8,12 @@ use Flowpack\DecoupledContentStore\NodeEnumeration\Domain\Service\NodeContextCombinator; use Flowpack\DecoupledContentStore\QuickPublish\Dto\NodeIdentifiers; use Flowpack\DecoupledContentStore\QuickPublish\Dto\QuickPublishPreviewRow; -use Neos\ContentRepository\Domain\Model\NodeInterface; -use Neos\ContentRepository\Domain\Projection\Content\TraversableNodeInterface; +use Neos\ContentRepository\Core\Projection\ContentGraph\Node; +use Neos\ContentRepository\Core\SharedModel\Node\NodeAddress; +use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry; use Neos\Flow\Annotations as Flow; use Neos\Flow\Mvc\Controller\ControllerContext; +use Neos\Neos\Domain\NodeLabel\NodeLabelGeneratorInterface; /** * Resolves the node identifiers of a quick release into what the confirmation page shows. @@ -29,6 +31,12 @@ final class QuickPublishPreviewService #[Flow\Inject] protected DocumentNodeFilter $documentNodeFilter; + #[Flow\Inject] + protected NodeLabelGeneratorInterface $nodeLabelGenerator; + + #[Flow\Inject] + protected ContentRepositoryRegistry $contentRepositoryRegistry; + /** * @return array one row per dimension variant of every given identifier */ @@ -39,16 +47,18 @@ public function preview(NodeIdentifiers $nodeIdentifiers, ControllerContext $con foreach ($nodeIdentifiers as $nodeIdentifier) { $nodeFound = false; - foreach ($this->nodeContextCombinator->nodeVariantsWithSiteNode($nodeIdentifier) as [$siteNode, $node]) { + foreach ($this->nodeContextCombinator->nodeVariants($nodeIdentifier) as $node) { $nodeFound = true; $rows[] = QuickPublishPreviewRow::forNode( $nodeIdentifier, - $node->getLabel(), - $node instanceof TraversableNodeInterface ? (string) $node->findNodePath() : '', + $this->nodeLabelGenerator->getLabel($node), + $this->contentRepositoryRegistry->subgraphForNode($node) + ->retrieveNodePath($node->aggregateId) + ->serializeToString(), self::describeDimensions($node), - $node->getNodeType()->getName(), + $node->nodeTypeName->value, $this->backendUri($node, $controllerContext), - $this->documentNodeFilter->skipReasonForNamedNode($node, $siteNode), + $this->documentNodeFilter->skipReasonForNamedNode($node), ); } @@ -68,18 +78,18 @@ public function countPublishedRows(array $rows): int return count(array_filter($rows, static fn(QuickPublishPreviewRow $row): bool => $row->isPublished())); } - private function backendUri(NodeInterface $node, ControllerContext $controllerContext): string + private function backendUri(Node $node, ControllerContext $controllerContext): string { return $controllerContext->getUriBuilder() ->reset() - ->uriFor('index', ['node' => $node->getContextPath()], 'Backend', 'Neos.Neos.Ui'); + ->uriFor('index', ['node' => NodeAddress::fromNode($node)->toJson()], 'Backend', 'Neos.Neos.Ui'); } - private static function describeDimensions(NodeInterface $node): string + private static function describeDimensions(Node $node): string { $dimensions = []; - foreach ($node->getContext()->getDimensions() as $dimensionName => $dimensionValues) { - $dimensions[] = $dimensionName . ': ' . implode(', ', $dimensionValues); + foreach ($node->dimensionSpacePoint->coordinates as $dimensionName => $dimensionValue) { + $dimensions[] = $dimensionName . ': ' . $dimensionValue; } return implode(' | ', $dimensions); diff --git a/Configuration/Settings.yaml b/Configuration/Settings.yaml index 6f5e062..dc3face 100644 --- a/Configuration/Settings.yaml +++ b/Configuration/Settings.yaml @@ -262,8 +262,6 @@ Neos: javascript: 'Flowpack.DecoupledContentStore:AutomaticReleaseWarning': resource: 'resource://Flowpack.DecoupledContentStore/Public/ContentModule/AutomaticReleaseWarning.js' - # Before the UI host and without "defer", because the host reads the inlined _NEOS_UI_* globals once and - # deletes them - the script has to capture the route table before that happens. position: 'before Neos.Neos.UI:Host' stylesheets: 'Flowpack.DecoupledContentStore:AutomaticReleaseWarning': @@ -292,6 +290,14 @@ Neos: 'Flowpack.DecoupledContentStore': position: 'before Neos.Neos' + ContentRepositoryRegistry: + presets: + 'default': + contentGraphProjection: + catchUpHooks: + 'Flowpack.DecoupledContentStore:IncrementalContentRelease': + factoryObjectName: Flowpack\DecoupledContentStore\IncrementalContentReleaseCatchUpHookFactory + Fusion: defaultContext: Flowpack.DecoupledContentStore: Flowpack\DecoupledContentStore\Eel\ModuleHelper diff --git a/Configuration/Testing/Behat/Objects.yaml b/Configuration/Testing/Behat/Objects.yaml deleted file mode 100644 index 2f76f3d..0000000 --- a/Configuration/Testing/Behat/Objects.yaml +++ /dev/null @@ -1,27 +0,0 @@ -# Normally, content dimension presets get injected from the Neos.ContentRepository.contentDimensions Setting. -# For running the Behat tests, we do not want the settings to be merged together, because we want to fully -# control all active content dimensions. -# If we would not do this here, the content dimensions of this package (for testing) would be merged -# with the content dimensions of other site packages, leading to indeterministic tests. -'Neos\ContentRepository\Domain\Service\ConfigurationContentDimensionPresetSource': - properties: - configuration: &contentDimensionPresets - value: - language: - default: en_US - defaultPreset: en_US - presets: - en_US: - label: 'English (US)' - values: - - en_US - uriSegment: en - de: - label: 'DE' - values: - - de - uriSegment: de - -Neos\Neos\Domain\Service\ConfigurationContentDimensionPresetSource: - properties: - configuration: *contentDimensionPresets diff --git a/Configuration/Testing/Behat/Settings.yaml b/Configuration/Testing/Behat/Settings.yaml index 0bbff78..9b0d6b2 100644 --- a/Configuration/Testing/Behat/Settings.yaml +++ b/Configuration/Testing/Behat/Settings.yaml @@ -21,3 +21,31 @@ Flowpack: # the key is written by documentMetadataGenerators, and the test setup registers none - so nothing that # requires every registered key to exist could ever pass here isRequired: false + +Neos: + ContentRepositoryRegistry: + contentRepositories: + # The scenarios declare node types and dimensions themselves (see FeatureContext), and the release code reads + # the "default" content repository. + default: + authProvider: + factoryObjectName: Neos\ContentRepository\TestSuite\Fakes\FakeAuthProviderFactory + nodeTypeManager: + factoryObjectName: Neos\ContentRepository\TestSuite\Fakes\FakeNodeTypeManagerFactory + contentDimensionSource: + factoryObjectName: Neos\ContentRepository\TestSuite\Fakes\FakeContentDimensionSourceFactory + + Neos: + sites: + 'test': + preset: default + uriPathSuffix: '' + contentDimensions: + resolver: + factoryClassName: Neos\Neos\FrontendRouting\DimensionResolution\Resolver\UriPathResolverFactory + options: + segments: + - + dimensionIdentifier: language + dimensionValueMapping: + de: de diff --git a/Documentation/Concepts/QuickContentReleases.md b/Documentation/Concepts/QuickContentReleases.md index 145b65a..41b4442 100644 --- a/Documentation/Concepts/QuickContentReleases.md +++ b/Documentation/Concepts/QuickContentReleases.md @@ -175,7 +175,7 @@ the release which was copied while the document itself is re-rendered, so a page go live disagreeing with each other. They are not written into `quickPublish:changedUrls`, though, which only knows the documents that were named — a scoped validator does not see them. -The hidden / orphaned / node-type guards are shared with the full enumeration through +The hidden / node-type guards are shared with the full enumeration through `NodeEnumeration/Domain/Service/DocumentNodeFilter`, which expresses `nodeTypeWhitelist` twice: as the FlowQuery filter string the full enumeration passes to `find()`, and as a check for a single node, which is what an enumerator starting from identifiers needs. The node-type check is deliberately **not** part of the shared `skipReason()`: @@ -192,34 +192,32 @@ The identifiers are a value object, `QuickPublish/Dto/NodeIdentifiers`, which re This is not cosmetic: the list travels through a pipeline variable into a shell command, so unvalidated input is a command-injection hole. The check lives at the point where the list is read, not only in the backend form. -Variants of a node are resolved through `NodeContextCombinator::nodeVariantsWithSiteNode()` — via `sites()` and -`siteNodeInContexts()` rather than `nodeInContexts()`, because the orphan check needs the site node. -`getNodeByIdentifier()` searches the whole content repository rather than one site, so it answers for every site -alike: each candidate is matched against the site node by its `findNodePath()` before it is handed out, or a -multi-site installation would pair every node with the first site and report it as orphaned. Once a site has claimed -the node the remaining ones are skipped, since a node belongs to exactly one site. +Variants of a node are resolved through `NodeContextCombinator::nodeVariants()`: one `findNodeById()` per dimension +space point of the content repository. There is no site lookup and no orphan check — the content graph only holds a +node in a dimension space point where its parent is covered as well, so every node it hands out sits below a site node. -That lookup shows invisible content regardless of `nodeRendering.recurseHiddenContent`, which defaults to `false`. +That lookup shows disabled nodes regardless of `nodeRendering.recurseHiddenContent`, which defaults to `false`. The setting is about recursing into hidden content while walking the tree; applied to a lookup by identifier it makes a hidden page indistinguishable from one which does not exist, and the first hidden page tried reported "not found in -any site and dimension". `siteNodeInContexts()` therefore takes an `$invisibleContentShown` override, `NULL` keeping -the configured behaviour for the full enumeration. Hidden pages are still not published — the skip reason says -"hidden", on the confirmation page and in the pipeline log alike. +any site and dimension". `nodeVariants()` therefore uses its own visibility constraints (soft-removed nodes excluded, +disabled ones shown), while `siteNodeInContexts()` builds the full enumeration's subgraphs from the setting. Hidden +pages are still not published — the skip reason says "hidden", on the confirmation page and in the pipeline log alike. -Because of that override, `skipReasonForNamedNode()` also has to walk the pages **above** the node, which -`skipReason()` does not: with `recurseHiddenContent` at its default the full enumeration descends from the site node -in a context which hides them, so a document below a hidden page is not in the content store at all. Naming it in a -quick release would resolve, render and publish it — a page live until the next full release quietly removes it -again. The skip reason for that is "below a hidden page". +Because of that, `skipReasonForNamedNode()` also has to look at the pages **above** the node, which `skipReason()` +does not: with `recurseHiddenContent` at its default the full enumeration descends from the site node in a subgraph +which hides them, so a document below a hidden page is not in the content store at all. Naming it in a quick release +would resolve, render and publish it — a page live until the next full release quietly removes it again. The skip +reason for that is "below a hidden page". -That walk is therefore gated on the very setting which decides the traversal: where `recurseHiddenContent` is `true` +That check is therefore gated on the very setting which decides the traversal: where `recurseHiddenContent` is `true` the full enumeration does reach such a document, and skipping it in a quick release would be the same mismatch the other way round. The hidden page itself stays unpublished either way — that is `skipReason()`, which the setting does not touch. -Both levels ask `isVisible()` rather than `isHidden()`, so a page hidden by `hiddenBeforeDateTime` / -`hiddenAfterDateTime` counts as hidden as well: it is hidden to a visitor just the same, and the context of the full -enumeration filters it on exactly that measure. +Both levels read the `disabled` subtree tag: `skipReason()` the node's own, `skipReasonForNamedNode()` the inherited +one, which the content graph already carries on every node below a disabled one — no walk up the tree is needed. A +page hidden by `enableAfterDateTime` / `disableAfterDateTime` counts as hidden only once +`neos/timeable-node-visibility` has disabled it, which is also when the full enumeration stops seeing it. ## 6. Validation scoped to the changed URLs @@ -291,16 +289,14 @@ administrators inside the Content Store module. The state is published as a Neos the backend module: `ModulePrivilege` expands internally into a method privilege over every action of the module controller, so a status action there would be readable only by the people who already have module access — precisely not the editors the warning is for. Data sources are granted to `Neos.Neos:AbstractEditor` by Neos itself, need no -route of their own, and the script reaches them through `_NEOS_UI_routes.core.service.dataSource`, so no URI is +route of their own, and the script reaches them through `routes.core.service.dataSource`, so no URI is hardcoded. The data source returns nothing but the flag, the timestamp, the account and the counter, so widening its access costs nothing. It must not be `final`: Neos instantiates data sources with `new`, and an unproxied class gets no property injection. -Two constraints on the script which registers under `Neos.Neos.Ui.resources.javascript`, both learned the hard way: -it must run **before** `Neos.Neos.UI:Host` and **without `defer`**. The UI host reads the inlined `_NEOS_UI_*` -globals through `getInlinedData()`, which does `delete window[...]` immediately after reading, so a deferred script -finds `_NEOS_UI_routes` already gone and cannot build the endpoint URI. The script therefore captures the route table -at evaluation time and waits for `DOMContentLoaded` before touching the DOM. +The script registers under `Neos.Neos.Ui.resources.javascript` and reads the route table from the JSON the UI inlines +into `