Skip to content

Commit a61242e

Browse files
authored
Merge pull request #142 from dfeyer/task-indexnode
TASK: Add a CLI command to index a node by identifier and workspace name
2 parents 703c1dc + 852bc94 commit a61242e

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

Classes/Flowpack/ElasticSearch/ContentRepositoryAdaptor/Command/NodeIndexCommandController.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service\IndexWorkspaceTrait;
1616
use TYPO3\Flow\Annotations as Flow;
1717
use TYPO3\Flow\Cli\CommandController;
18+
use TYPO3\Neos\Controller\CreateContentContextTrait;
19+
use TYPO3\TYPO3CR\Domain\Model\Workspace;
1820

1921
/**
2022
* Provides CLI features for index handling
@@ -24,6 +26,7 @@
2426
class NodeIndexCommandController extends CommandController
2527
{
2628
use IndexWorkspaceTrait;
29+
use CreateContentContextTrait;
2730

2831
/**
2932
* @Flow\Inject
@@ -125,6 +128,63 @@ public function showMappingCommand()
125128
}
126129
}
127130

131+
/**
132+
* Index a single node by the given identifier and workspace name
133+
*
134+
* @param string $identifier
135+
* @param string $workspace
136+
* @return void
137+
*/
138+
public function indexNodeCommand($identifier, $workspace = null)
139+
{
140+
if ($workspace === null && $this->settings['indexAllWorkspaces'] === false) {
141+
$workspace = 'live';
142+
}
143+
144+
$indexNode = function ($identifier, Workspace $workspace, array $dimensions) {
145+
$context = $this->createContentContext($workspace->getName(), $dimensions);
146+
$node = $context->getNodeByIdentifier($identifier);
147+
if ($node === null) {
148+
$this->outputLine('Node with the given identifier is not found.');
149+
$this->quit();
150+
}
151+
$this->outputLine();
152+
$this->outputLine('Index node "%s" (%s)', [
153+
$node->getLabel(),
154+
$node->getIdentifier(),
155+
]);
156+
$this->outputLine(' workspace: %s', [
157+
$workspace->getName()
158+
]);
159+
$this->outputLine(' node type: %s', [
160+
$node->getNodeType()->getName()
161+
]);
162+
$this->outputLine(' dimensions: %s', [
163+
json_encode($dimensions)
164+
]);
165+
$this->nodeIndexer->indexNode($node);
166+
};
167+
168+
$indexInWorkspace = function ($identifier, Workspace $workspace) use ($indexNode) {
169+
$combinations = $this->contentDimensionCombinator->getAllAllowedCombinations();
170+
if ($combinations === []) {
171+
$indexNode($identifier, $workspace, []);
172+
} else {
173+
foreach ($combinations as $combination) {
174+
$indexNode($identifier, $workspace, $combination);
175+
}
176+
}
177+
};
178+
179+
if ($workspace === null) {
180+
foreach ($this->workspaceRepository->findAll() as $workspace) {
181+
$indexInWorkspace($identifier, $workspace);
182+
}
183+
} else {
184+
$indexInWorkspace($identifier, $workspace);
185+
}
186+
}
187+
128188
/**
129189
* Index all nodes by creating a new index and when everything was completed, switch the index alias.
130190
*

0 commit comments

Comments
 (0)