|
15 | 15 | use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service\IndexWorkspaceTrait; |
16 | 16 | use TYPO3\Flow\Annotations as Flow; |
17 | 17 | use TYPO3\Flow\Cli\CommandController; |
| 18 | +use TYPO3\Neos\Controller\CreateContentContextTrait; |
| 19 | +use TYPO3\TYPO3CR\Domain\Model\Workspace; |
18 | 20 |
|
19 | 21 | /** |
20 | 22 | * Provides CLI features for index handling |
|
24 | 26 | class NodeIndexCommandController extends CommandController |
25 | 27 | { |
26 | 28 | use IndexWorkspaceTrait; |
| 29 | + use CreateContentContextTrait; |
27 | 30 |
|
28 | 31 | /** |
29 | 32 | * @Flow\Inject |
@@ -125,6 +128,63 @@ public function showMappingCommand() |
125 | 128 | } |
126 | 129 | } |
127 | 130 |
|
| 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 | + |
128 | 188 | /** |
129 | 189 | * Index all nodes by creating a new index and when everything was completed, switch the index alias. |
130 | 190 | * |
|
0 commit comments