Skip to content

!!! FEATURE: Neos 9.0 compatibility #50

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 50 additions & 67 deletions Classes/Command/NodeIndexCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@

use Flowpack\SimpleSearch\Domain\Service\IndexInterface;
use Flowpack\SimpleSearch\Exception;
use Neos\ContentRepository\Domain\Model\NodeInterface;
use Neos\ContentRepository\Domain\Repository\NodeDataRepository;
use Neos\ContentRepository\Domain\Repository\WorkspaceRepository;
use Neos\ContentRepository\Domain\Service\ContextFactoryInterface;
use Neos\ContentRepository\Exception\NodeException;
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePoint;
use Neos\ContentRepository\Core\DimensionSpace\DimensionSpacePointSet;
use Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindDescendantNodesFilter;
use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId;
use Neos\ContentRepository\Core\SharedModel\Workspace\WorkspaceName;
use Neos\ContentRepository\Search\Exception\IndexingException;
use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry;
use Neos\ContentRepository\Search\Indexer\NodeIndexerInterface;
use Neos\Eel\Exception as EelException;
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Cli\CommandController;
use Neos\Neos\Domain\Service\ContentDimensionPresetSourceInterface;
use Neos\Neos\Domain\Service\NodeTypeNameFactory;
use Neos\Neos\Domain\SubtreeTagging\NeosVisibilityConstraints;

/**
* Provides CLI features for index handling
Expand All @@ -36,34 +39,8 @@ class NodeIndexCommandController extends CommandController
*/
protected $indexClient;

/**
* @Flow\Inject
* @var WorkspaceRepository
*/
protected $workspaceRepository;

/**
* @Flow\Inject
* @var NodeDataRepository
*/
protected $nodeDataRepository;

/**
* @Flow\Inject
* @var ContextFactoryInterface
*/
protected $contextFactory;

/**
* @Flow\Inject
* @var ContentDimensionPresetSourceInterface
*/
protected $contentDimensionPresetSource;

/**
* @var integer
*/
protected $indexedNodes;
#[Flow\Inject]
protected ContentRepositoryRegistry $contentRepositoryRegistry;

/**
* Index all nodes.
Expand All @@ -75,15 +52,18 @@ class NodeIndexCommandController extends CommandController
* @return void
* @throws Exception
*/
public function buildCommand(string $workspace = null): void
public function buildCommand(string $contentRepository = 'default', ?string $workspace = null): void
{
$this->indexedNodes = 0;
$contentRepositoryId = ContentRepositoryId::fromString($contentRepository);
$contentRepository = $this->contentRepositoryRegistry->get($contentRepositoryId);

if ($workspace === null) {
foreach ($this->workspaceRepository->findAll() as $workspaceInstance) {
$this->indexWorkspace($workspaceInstance->getName());
foreach ($contentRepository->findWorkspaces() as $workspaceInstance) {
$this->indexWorkspace($contentRepositoryId, $workspaceInstance->workspaceName);
}
} else {
$this->indexWorkspace($workspace);
$workspaceName = WorkspaceName::fromString($workspace);
$this->indexWorkspace($contentRepositoryId, $workspaceName);
}
$this->outputLine('Finished indexing.');
}
Expand All @@ -92,44 +72,47 @@ public function buildCommand(string $workspace = null): void
* @param string $workspaceName
* @throws Exception
*/
protected function indexWorkspace(string $workspaceName): void
protected function indexWorkspace(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName): void
{
$dimensionCombinations = $this->nodeIndexer->calculateDimensionCombinations();
if ($dimensionCombinations !== []) {
foreach ($dimensionCombinations as $combination) {
$context = $this->contextFactory->create(['workspaceName' => $workspaceName, 'dimensions' => $combination]);
$rootNode = $context->getRootNode();

$this->traverseNodes($rootNode);
$rootNode->getContext()->getFirstLevelNodeCache()->flush();
$this->outputLine('Workspace "' . $workspaceName . '" and dimensions "' . json_encode($combination) . '" done. (Indexed ' . $this->indexedNodes . ' nodes)');
$this->indexedNodes = 0;
}
} else {
$context = $this->contextFactory->create(['workspaceName' => $workspaceName]);
$rootNode = $context->getRootNode();
$dimensionSpacePoints = $this->nodeIndexer->calculateDimensionCombinations($contentRepositoryId);
if ($dimensionSpacePoints->isEmpty()) {
$dimensionSpacePoints = DimensionSpacePointSet::fromArray([DimensionSpacePoint::createWithoutDimensions()]);
}

$this->traverseNodes($rootNode);
$this->outputLine('Workspace "' . $workspaceName . '" without dimensions done. (Indexed ' . $this->indexedNodes . ' nodes)');
$this->indexedNodes = 0;
foreach ($dimensionSpacePoints as $dimensionSpacePoint) {
$indexedNodes = $this->indexWorkspaceInDimension($contentRepositoryId, $workspaceName, $dimensionSpacePoint);
$this->outputLine('Workspace "' . $workspaceName . '" and dimensions "' . json_encode($dimensionSpacePoint) . '" done. (Indexed ' . $indexedNodes . ' nodes)');
}
}

/**
* @param NodeInterface $currentNode
* @param Node $currentNode
* @throws Exception
*/
protected function traverseNodes(NodeInterface $currentNode): void
protected function indexWorkspaceInDimension(ContentRepositoryId $contentRepositoryId, WorkspaceName $workspaceName, DimensionSpacePoint $dimensionSpacePoint): int
{
try {
$this->nodeIndexer->indexNode($currentNode, null, false);
} catch (NodeException|IndexingException|EelException $exception) {
throw new Exception(sprintf('Error during indexing of node %s (%s)', $currentNode->findNodePath(), (string) $currentNode->getNodeAggregateIdentifier()), 1579170291, $exception);
}
$this->indexedNodes++;
foreach ($currentNode->findChildNodes() as $childNode) {
$this->traverseNodes($childNode);
$contentRepository = $this->contentRepositoryRegistry->get($contentRepositoryId);
$contentGraph = $contentRepository->getContentGraph($workspaceName);

$rootNodeAggregate = $contentGraph->findRootNodeAggregateByType(NodeTypeNameFactory::forSites());
$subgraph = $contentGraph->getSubgraph($dimensionSpacePoint, NeosVisibilityConstraints::excludeRemoved());

$rootNode = $subgraph->findNodeById($rootNodeAggregate->nodeAggregateId);
$indexedNodes = 0;

$this->nodeIndexer->indexNode($rootNode, null, false);
$indexedNodes++;

foreach ($subgraph->findDescendantNodes($rootNode->aggregateId, FindDescendantNodesFilter::create()) as $descendantNode) {
try {
$this->nodeIndexer->indexNode($descendantNode, null, false);
$indexedNodes++;
} catch (IndexingException|EelException $exception) {
throw new Exception(sprintf('Error during indexing of node %s', (string)$descendantNode->aggregateId), 1579170291, $exception);
};
}

return $indexedNodes;
}

/**
Expand Down
Loading