|
15 | 15 | use Flowpack\ElasticSearch\ContentRepositoryAdaptor\Service\IndexWorkspaceTrait; |
16 | 16 | use Neos\Flow\Annotations as Flow; |
17 | 17 | use Neos\Flow\Cli\CommandController; |
18 | | -use Neos\ContentRepository\Domain\Model\NodeInterface; |
| 18 | +use Neos\Neos\Controller\CreateContentContextTrait; |
| 19 | +use Neos\ContentRepository\Domain\Model\Workspace; |
19 | 20 |
|
20 | 21 | /** |
21 | 22 | * Provides CLI features for index handling |
|
25 | 26 | class NodeIndexCommandController extends CommandController |
26 | 27 | { |
27 | 28 | use IndexWorkspaceTrait; |
| 29 | + use CreateContentContextTrait; |
28 | 30 |
|
29 | 31 | /** |
30 | 32 | * @Flow\Inject |
@@ -131,6 +133,64 @@ public function showMappingCommand() |
131 | 133 | } |
132 | 134 | } |
133 | 135 |
|
| 136 | + /** |
| 137 | + * Index a single node by the given identifier and workspace name |
| 138 | + * |
| 139 | + * @param string $identifier |
| 140 | + * @param string $workspace |
| 141 | + * @return void |
| 142 | + */ |
| 143 | + public function indexNodeCommand($identifier, $workspace = null) |
| 144 | + { |
| 145 | + if ($workspace === null && $this->settings['indexAllWorkspaces'] === false) { |
| 146 | + $workspace = 'live'; |
| 147 | + } |
| 148 | + |
| 149 | + $indexNode = function ($identifier, Workspace $workspace, array $dimensions) { |
| 150 | + $context = $this->createContentContext($workspace->getName(), $dimensions); |
| 151 | + $node = $context->getNodeByIdentifier($identifier); |
| 152 | + if ($node === null) { |
| 153 | + $this->outputLine('Node with the given identifier is not found.'); |
| 154 | + $this->quit(); |
| 155 | + } |
| 156 | + $this->outputLine(); |
| 157 | + $this->outputLine('Index node "%s" (%s)', [ |
| 158 | + $node->getLabel(), |
| 159 | + $node->getIdentifier(), |
| 160 | + ]); |
| 161 | + $this->outputLine(' workspace: %s', [ |
| 162 | + $workspace->getName() |
| 163 | + ]); |
| 164 | + $this->outputLine(' node type: %s', [ |
| 165 | + $node->getNodeType()->getName() |
| 166 | + ]); |
| 167 | + $this->outputLine(' dimensions: %s', [ |
| 168 | + json_encode($dimensions) |
| 169 | + ]); |
| 170 | + $this->nodeIndexer->indexNode($node); |
| 171 | + }; |
| 172 | + |
| 173 | + $indexInWorkspace = function ($identifier, Workspace $workspace) use ($indexNode) { |
| 174 | + $combinations = $this->contentDimensionCombinator->getAllAllowedCombinations(); |
| 175 | + if ($combinations === []) { |
| 176 | + $indexNode($identifier, $workspace, []); |
| 177 | + } else { |
| 178 | + foreach ($combinations as $combination) { |
| 179 | + $indexNode($identifier, $workspace, $combination); |
| 180 | + } |
| 181 | + } |
| 182 | + }; |
| 183 | + |
| 184 | + if ($workspace === null) { |
| 185 | + foreach ($this->workspaceRepository->findAll() as $workspace) { |
| 186 | + $indexInWorkspace($identifier, $workspace); |
| 187 | + } |
| 188 | + } else { |
| 189 | + $workspace = $this->workspaceRepository->findByIdentifier($workspace); |
| 190 | + $indexInWorkspace($identifier, $workspace); |
| 191 | + } |
| 192 | + } |
| 193 | + |
134 | 194 | /** |
135 | 195 | * Index all nodes by creating a new index and when everything was completed, switch the index alias. |
136 | 196 | * |
|
0 commit comments