1111 * source code.
1212 */
1313
14+ use Flowpack \ElasticSearch \ContentRepositoryAdaptor \LoggerInterface ;
1415use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Mapping \NodeTypeMappingBuilder ;
1516use Flowpack \ElasticSearch \ContentRepositoryAdaptor \Service \IndexWorkspaceTrait ;
17+ use Flowpack \ElasticSearch \Domain \Model \Mapping ;
18+ use Flowpack \ElasticSearch \Transfer \Exception \ApiException ;
19+ use Neos \ContentRepository \Domain \Factory \NodeFactory ;
20+ use Neos \ContentRepository \Domain \Model \Workspace ;
21+ use Neos \ContentRepository \Domain \Repository \NodeDataRepository ;
22+ use Neos \ContentRepository \Domain \Repository \WorkspaceRepository ;
23+ use Neos \ContentRepository \Domain \Service \ContentDimensionPresetSourceInterface ;
1624use Neos \ContentRepository \Domain \Service \Context ;
1725use Neos \ContentRepository \Domain \Service \ContextFactoryInterface ;
26+ use Neos \ContentRepository \Search \Indexer \NodeIndexerInterface ;
1827use Neos \Flow \Annotations as Flow ;
1928use Neos \Flow \Cli \CommandController ;
20- use Neos \ContentRepository \Domain \Model \Workspace ;
29+ use Neos \Flow \Configuration \ConfigurationManager ;
30+ use Neos \Flow \ObjectManagement \ObjectManagerInterface ;
31+ use Symfony \Component \Yaml \Yaml ;
2132
2233/**
2334 * Provides CLI features for index handling
@@ -30,31 +41,31 @@ class NodeIndexCommandController extends CommandController
3041
3142 /**
3243 * @Flow\Inject
33- * @var \Neos\ContentRepository\Search\Indexer\ NodeIndexerInterface
44+ * @var NodeIndexerInterface
3445 */
3546 protected $ nodeIndexer ;
3647
3748 /**
3849 * @Flow\Inject
39- * @var \Neos\ContentRepository\Domain\Repository\ WorkspaceRepository
50+ * @var WorkspaceRepository
4051 */
4152 protected $ workspaceRepository ;
4253
4354 /**
4455 * @Flow\Inject
45- * @var \Neos\ContentRepository\Domain\Repository\ NodeDataRepository
56+ * @var NodeDataRepository
4657 */
4758 protected $ nodeDataRepository ;
4859
4960 /**
5061 * @Flow\Inject
51- * @var \Neos\ContentRepository\Domain\Factory\ NodeFactory
62+ * @var NodeFactory
5263 */
5364 protected $ nodeFactory ;
5465
5566 /**
5667 * @Flow\Inject
57- * @var \Neos\ContentRepository\Domain\Service\ ContentDimensionPresetSourceInterface
68+ * @var ContentDimensionPresetSourceInterface
5869 */
5970 protected $ contentDimensionPresetSource ;
6071
@@ -66,13 +77,13 @@ class NodeIndexCommandController extends CommandController
6677
6778 /**
6879 * @Flow\Inject
69- * @var \Flowpack\ElasticSearch\ContentRepositoryAdaptor\ LoggerInterface
80+ * @var LoggerInterface
7081 */
7182 protected $ logger ;
7283
7384 /**
7485 * @Flow\Inject
75- * @var \Neos\Flow\Configuration\ ConfigurationManager
86+ * @var ConfigurationManager
7687 */
7788 protected $ configurationManager ;
7889
@@ -94,8 +105,8 @@ class NodeIndexCommandController extends CommandController
94105 */
95106 public function initializeObject ($ cause )
96107 {
97- if ($ cause === \ Neos \ Flow \ ObjectManagement \ ObjectManagerInterface::INITIALIZATIONCAUSE_CREATED ) {
98- $ this ->settings = $ this ->configurationManager ->getConfiguration (\ Neos \ Flow \ Configuration \ ConfigurationManager::CONFIGURATION_TYPE_SETTINGS , 'Neos.ContentRepository.Search ' );
108+ if ($ cause === ObjectManagerInterface::INITIALIZATIONCAUSE_CREATED ) {
109+ $ this ->settings = $ this ->configurationManager ->getConfiguration (ConfigurationManager::CONFIGURATION_TYPE_SETTINGS , 'Neos.ContentRepository.Search ' );
99110 }
100111 }
101112
@@ -108,8 +119,8 @@ public function showMappingCommand()
108119 {
109120 $ nodeTypeMappingCollection = $ this ->nodeTypeMappingBuilder ->buildMappingInformation ($ this ->nodeIndexer ->getIndex ());
110121 foreach ($ nodeTypeMappingCollection as $ mapping ) {
111- /** @var \Flowpack\ElasticSearch\Domain\Model\ Mapping $mapping */
112- $ this ->output (\ Symfony \ Component \ Yaml \ Yaml::dump ($ mapping ->asArray (), 5 , 2 ));
122+ /** @var Mapping $mapping */
123+ $ this ->output (Yaml::dump ($ mapping ->asArray (), 5 , 2 ));
113124 $ this ->outputLine ();
114125 }
115126 $ this ->outputLine ('------------ ' );
@@ -187,6 +198,7 @@ public function indexNodeCommand($identifier, $workspace = null)
187198 $ indexInWorkspace ($ identifier , $ workspace );
188199 }
189200 } else {
201+ /** @var Workspace $workspaceInstance */
190202 $ workspaceInstance = $ this ->workspaceRepository ->findByIdentifier ($ workspace );
191203 if ($ workspaceInstance === null ) {
192204 $ this ->outputLine ('The given workspace (%s) does not exist. ' , [$ workspace ]);
@@ -204,7 +216,7 @@ public function indexNodeCommand($identifier, $workspace = null)
204216 * @param integer $limit Amount of nodes to index at maximum
205217 * @param boolean $update if TRUE, do not throw away the index at the start. Should *only be used for development*.
206218 * @param string $workspace name of the workspace which should be indexed
207- * @param string $postfix Index postfix, index with the same postifix will be deleted if exist
219+ * @param string $postfix Index postfix, index with the same postfix will be deleted if exist
208220 * @return void
209221 */
210222 public function buildCommand ($ limit = null , $ update = false , $ workspace = null , $ postfix = null )
@@ -217,21 +229,9 @@ public function buildCommand($limit = null, $update = false, $workspace = null,
217229 if ($ update === true ) {
218230 $ this ->logger ->log ('!!! Update Mode (Development) active! ' , LOG_INFO );
219231 } else {
220- $ this ->nodeIndexer ->setIndexNamePostfix ($ postfix ?: time ());
221- if ($ this ->nodeIndexer ->getIndex ()->exists () === true ) {
222- $ this ->logger ->log (sprintf ('Deleted index with the same postfix (%s)! ' , $ postfix ), LOG_WARNING );
223- $ this ->nodeIndexer ->getIndex ()->delete ();
224- }
225- $ this ->nodeIndexer ->getIndex ()->create ();
226- $ this ->logger ->log ('Created index ' . $ this ->nodeIndexer ->getIndexName (), LOG_INFO );
227-
228- $ nodeTypeMappingCollection = $ this ->nodeTypeMappingBuilder ->buildMappingInformation ($ this ->nodeIndexer ->getIndex ());
229- foreach ($ nodeTypeMappingCollection as $ mapping ) {
230- /** @var \Flowpack\ElasticSearch\Domain\Model\Mapping $mapping */
231- $ mapping ->apply ();
232- }
233- $ this ->logger ->log ('Updated Mapping. ' , LOG_INFO );
232+ $ this ->createNewIndex ($ postfix );
234233 }
234+ $ this ->applyMapping ();
235235
236236 $ this ->logger ->log (sprintf ('Indexing %snodes ... ' , ($ limit !== null ? 'the first ' . $ limit . ' ' : '' )), LOG_INFO );
237237
@@ -283,7 +283,7 @@ public function cleanupCommand()
283283 } else {
284284 $ this ->logger ->log ('Nothing to remove. ' );
285285 }
286- } catch (\ Flowpack \ ElasticSearch \ Transfer \ Exception \ ApiException $ exception ) {
286+ } catch (ApiException $ exception ) {
287287 $ response = json_decode ($ exception ->getResponse ());
288288 $ this ->logger ->log (sprintf ('Nothing removed. ElasticSearch responded with status %s, saying "%s: %s" ' , $ response ->status , $ response ->error ->type , $ response ->error ->reason ));
289289 }
@@ -314,4 +314,35 @@ protected function createContentContext($workspaceName, array $dimensions = [])
314314 return $ this ->contextFactory ->create ($ contextProperties );
315315 }
316316
317+ /**
318+ * Create a new index with the given $postfix.
319+ *
320+ * @param string $postfix
321+ * @return void
322+ */
323+ protected function createNewIndex ($ postfix )
324+ {
325+ $ this ->nodeIndexer ->setIndexNamePostfix ($ postfix ?: time ());
326+ if ($ this ->nodeIndexer ->getIndex ()->exists () === true ) {
327+ $ this ->logger ->log (sprintf ('Deleted index with the same postfix (%s)! ' , $ postfix ), LOG_WARNING );
328+ $ this ->nodeIndexer ->getIndex ()->delete ();
329+ }
330+ $ this ->nodeIndexer ->getIndex ()->create ();
331+ $ this ->logger ->log ('Created index ' . $ this ->nodeIndexer ->getIndexName (), LOG_INFO );
332+ }
333+
334+ /**
335+ * Apply the mapping to the current index.
336+ *
337+ * @return void
338+ */
339+ protected function applyMapping ()
340+ {
341+ $ nodeTypeMappingCollection = $ this ->nodeTypeMappingBuilder ->buildMappingInformation ($ this ->nodeIndexer ->getIndex ());
342+ foreach ($ nodeTypeMappingCollection as $ mapping ) {
343+ /** @var Mapping $mapping */
344+ $ mapping ->apply ();
345+ }
346+ $ this ->logger ->log ('Updated Mapping. ' , LOG_INFO );
347+ }
317348}
0 commit comments