3636use Neos \ContentRepository \Domain \Service \ContextFactory ;
3737use Neos \ContentRepository \Search \Indexer \AbstractNodeIndexer ;
3838use Neos \ContentRepository \Search \Indexer \BulkNodeIndexerInterface ;
39- use Neos \ContentRepository \Utility ;
4039use Neos \Flow \Annotations as Flow ;
4140use Neos \Flow \Persistence \Exception \IllegalObjectTypeException ;
42- use Neos \Utility \Files ;
41+ use Neos \Utility \Exception \ FilesException ;
4342use Neos \Flow \Log \Utility \LogEnvironment ;
4443use Psr \Log \LoggerInterface ;
4544
@@ -208,6 +207,7 @@ public function getIndex(): Index
208207 * @param NodeInterface $node
209208 * @param string $targetWorkspaceName In case indexing is triggered during publishing, a target workspace name will be passed in
210209 * @return void
210+ * @throws Exception
211211 */
212212 public function indexNode (NodeInterface $ node , $ targetWorkspaceName = null ): void
213213 {
@@ -271,7 +271,7 @@ public function indexNode(NodeInterface $node, $targetWorkspaceName = null): voi
271271 $ handleNode = function (NodeInterface $ node , Context $ context ) use ($ targetWorkspaceName , $ indexer ) {
272272 $ nodeFromContext = $ context ->getNodeByIdentifier ($ node ->getIdentifier ());
273273 if ($ nodeFromContext instanceof NodeInterface) {
274- $ this ->searchClient ->withDimensions (function () use ($ indexer , $ nodeFromContext , $ targetWorkspaceName ) {
274+ $ this ->searchClient ->withDimensions (static function () use ($ indexer , $ nodeFromContext , $ targetWorkspaceName ) {
275275 $ indexer ($ nodeFromContext , $ targetWorkspaceName );
276276 }, $ nodeFromContext ->getContext ()->getTargetDimensions ());
277277 } else {
@@ -315,15 +315,18 @@ protected function createContentContext(string $workspaceName, array $dimensions
315315
316316 /**
317317 * @param NodeInterface $node
318- * @param array|null $tuple
318+ * @param array|null $requests
319+ * @throws Exception
320+ * @throws \Flowpack\ElasticSearch\Exception
321+ * @throws FilesException
319322 */
320- protected function toBulkRequest (NodeInterface $ node , array $ tuple = null )
323+ protected function toBulkRequest (NodeInterface $ node , array $ requests = null ): void
321324 {
322- if ($ tuple === null ) {
325+ if ($ requests === null ) {
323326 return ;
324327 }
325328
326- $ this ->currentBulkRequest [] = new BulkRequestPart ($ this ->dimensionService ->hashByNode ($ node ), $ tuple );
329+ $ this ->currentBulkRequest [] = new BulkRequestPart ($ this ->dimensionService ->hashByNode ($ node ), $ requests );
327330 $ this ->flushIfNeeded ();
328331 }
329332
@@ -352,7 +355,10 @@ protected function calculateDocumentIdentifier(NodeInterface $node, $targetWorks
352355 * @param NodeInterface $node
353356 * @param string $targetWorkspaceName
354357 * @return void
358+ * @throws Exception
359+ * @throws FilesException
355360 * @throws IllegalObjectTypeException
361+ * @throws \Flowpack\ElasticSearch\Exception
356362 */
357363 public function removeNode (NodeInterface $ node , string $ targetWorkspaceName = null ): void
358364 {
@@ -380,7 +386,7 @@ public function removeNode(NodeInterface $node, string $targetWorkspaceName = nu
380386 /**
381387 * @throws Exception
382388 * @throws \Flowpack\ElasticSearch\Exception
383- * @throws \Neos\Utility\Exception\ FilesException
389+ * @throws FilesException
384390 */
385391 protected function flushIfNeeded (): void
386392 {
@@ -391,7 +397,7 @@ protected function flushIfNeeded(): void
391397
392398 protected function bulkRequestSize (): int
393399 {
394- return array_reduce ($ this ->currentBulkRequest , function ($ sum , BulkRequestPart $ request ) {
400+ return array_reduce ($ this ->currentBulkRequest , static function ($ sum , BulkRequestPart $ request ) {
395401 return $ sum + $ request ->getSize ();
396402 }, 0 );
397403 }
@@ -407,7 +413,7 @@ protected function bulkRequestLenght(): int
407413 * @return void
408414 * @throws Exception
409415 * @throws \Flowpack\ElasticSearch\Exception
410- * @throws \Neos\Utility\Exception\ FilesException
416+ * @throws FilesException
411417 */
412418 public function flush (): void
413419 {
@@ -450,32 +456,23 @@ public function flush(): void
450456 return ;
451457 }
452458
453- $ logDirectory = FLOW_PATH_DATA . 'Logs/ElasticSearch/ ' ;
454- if (!@is_dir ($ logDirectory )) {
455- Files::createDirectoryRecursively ($ logDirectory );
456- }
457-
458- // TODO: Remove fileystem logging
459459 foreach ($ this ->dimensionService ->getDimensionsRegistry () as $ hash => $ dimensions ) {
460460 if (!isset ($ payload [$ hash ])) {
461461 continue ;
462462 }
463+
463464 $ this ->searchClient ->setDimensions ($ dimensions );
465+
464466 $ response = $ this ->requestDriver ->bulk ($ this ->getIndex (), implode (chr (10 ), $ payload [$ hash ]));
467+
468+
465469 foreach ($ response as $ responseLine ) {
466470 if (isset ($ response ['errors ' ]) && $ response ['errors ' ] !== false ) {
467- $ this ->errorHandlingService ->log (
468- new BulkIndexingError ($ this ->currentBulkRequest , $ responseLine )
469- );
470- file_put_contents ($ logDirectory . 'BulkIndexing_Error_ ' . time () . '.json ' , json_encode ([
471- 'request ' => $ payload [$ hash ],
472- 'response ' => $ responseLine
473- ], JSON_PRETTY_PRINT ));
471+ $ this ->errorHandlingService ->log (new BulkIndexingError ($ this ->currentBulkRequest , $ responseLine ));
474472 }
475473 }
476474 }
477475
478-
479476 $ this ->reset ();
480477 }
481478
0 commit comments