@@ -211,21 +211,9 @@ public function buildCommand($limit = null, $update = false, $workspace = null,
211211 if ($ update === true ) {
212212 $ this ->logger ->log ('!!! Update Mode (Development) active! ' , LOG_INFO );
213213 } else {
214- $ this ->nodeIndexer ->setIndexNamePostfix ($ postfix ?: time ());
215- if ($ this ->nodeIndexer ->getIndex ()->exists () === true ) {
216- $ this ->logger ->log (sprintf ('Deleted index with the same postfix (%s)! ' , $ postfix ), LOG_WARNING );
217- $ this ->nodeIndexer ->getIndex ()->delete ();
218- }
219- $ this ->nodeIndexer ->getIndex ()->create ();
220- $ this ->logger ->log ('Created index ' . $ this ->nodeIndexer ->getIndexName (), LOG_INFO );
221-
222- $ nodeTypeMappingCollection = $ this ->nodeTypeMappingBuilder ->buildMappingInformation ($ this ->nodeIndexer ->getIndex ());
223- foreach ($ nodeTypeMappingCollection as $ mapping ) {
224- /** @var \Flowpack\ElasticSearch\Domain\Model\Mapping $mapping */
225- $ mapping ->apply ();
226- }
227- $ this ->logger ->log ('Updated Mapping. ' , LOG_INFO );
214+ $ this ->createNewIndex ($ postfix );
228215 }
216+ $ this ->applyMapping ();
229217
230218 $ this ->logger ->log (sprintf ('Indexing %snodes ... ' , ($ limit !== null ? 'the first ' . $ limit . ' ' : '' )), LOG_INFO );
231219
@@ -282,4 +270,36 @@ public function cleanupCommand()
282270 $ this ->logger ->log (sprintf ('Nothing removed. ElasticSearch responded with status %s, saying "%s: %s" ' , $ response ->status , $ response ->error ->type , $ response ->error ->reason ));
283271 }
284272 }
273+
274+ /**
275+ * Create a new index with the given $postfix.
276+ *
277+ * @param string $postfix
278+ * @return void
279+ */
280+ protected function createNewIndex ($ postfix )
281+ {
282+ $ this ->nodeIndexer ->setIndexNamePostfix ($ postfix ?: time ());
283+ if ($ this ->nodeIndexer ->getIndex ()->exists () === true ) {
284+ $ this ->logger ->log (sprintf ('Deleted index with the same postfix (%s)! ' , $ postfix ), LOG_WARNING );
285+ $ this ->nodeIndexer ->getIndex ()->delete ();
286+ }
287+ $ this ->nodeIndexer ->getIndex ()->create ();
288+ $ this ->logger ->log ('Created index ' . $ this ->nodeIndexer ->getIndexName (), LOG_INFO );
289+ }
290+
291+ /**
292+ * Apply the mapping to the current index.
293+ *
294+ * @return void
295+ */
296+ protected function applyMapping ()
297+ {
298+ $ nodeTypeMappingCollection = $ this ->nodeTypeMappingBuilder ->buildMappingInformation ($ this ->nodeIndexer ->getIndex ());
299+ foreach ($ nodeTypeMappingCollection as $ mapping ) {
300+ /** @var Mapping $mapping */
301+ $ mapping ->apply ();
302+ }
303+ $ this ->logger ->log ('Updated Mapping. ' , LOG_INFO );
304+ }
285305}
0 commit comments