Skip to content

Commit fcb18a2

Browse files
committed
TASK: Add a CLI command to index a node by identifier and workspace name
1 parent fa136a6 commit fcb18a2

1 file changed

Lines changed: 55 additions & 0 deletions

File tree

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

Lines changed: 55 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,58 @@ 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+
*/
137+
public function indexNodeCommand($identifier, $workspace = null)
138+
{
139+
if ($workspace === null && $this->settings['indexAllWorkspaces'] === false) {
140+
$workspace = 'live';
141+
}
142+
143+
$indexNode = function ($identifier, Workspace $workspace, array $dimensions) {
144+
$context = $this->createContentContext($workspace->getName(), $dimensions);
145+
$node = $context->getNodeByIdentifier($identifier);
146+
$this->outputLine();
147+
$this->outputLine('Index node "%s" (%s)', [
148+
$node->getLabel(),
149+
$node->getIdentifier(),
150+
]);
151+
$this->outputLine(' workspace: %s', [
152+
$workspace->getName()
153+
]);
154+
$this->outputLine(' node type: %s', [
155+
$node->getNodeType()->getName()
156+
]);
157+
$this->outputLine(' dimensions: %s', [
158+
json_encode($dimensions)
159+
]);
160+
$this->nodeIndexer->indexNode($node);
161+
};
162+
163+
$indexInWorkspacce = function ($identifier, Workspace $workspace) use ($indexNode) {
164+
$combinations = $this->contentDimensionCombinator->getAllAllowedCombinations();
165+
if ($combinations === []) {
166+
$indexNode($identifier, $workspace, []);
167+
} else {
168+
foreach ($combinations as $combination) {
169+
$indexNode($identifier, $workspace, $combination);
170+
}
171+
}
172+
};
173+
174+
if ($workspace === null) {
175+
foreach ($this->workspaceRepository->findAll() as $workspace) {
176+
$indexInWorkspacce($identifier, $workspace);
177+
}
178+
} else {
179+
$indexInWorkspacce($identifier, $workspace);
180+
}
181+
}
182+
128183
/**
129184
* Index all nodes by creating a new index and when everything was completed, switch the index alias.
130185
*

0 commit comments

Comments
 (0)