1414namespace  Pimcore \Bundle \GenericDataIndexBundle \Service \SearchIndex ;
1515
1616use  Exception ;
17+ use  Pimcore \Model \Asset ;
18+ use  Pimcore \Model \Element \ElementInterface ;
19+ use  Symfony \Component \Messenger \MessageBusInterface ;
1720use  Pimcore \Bundle \GenericDataIndexBundle \Entity \IndexQueue ;
18- use  Pimcore \Bundle \GenericDataIndexBundle \Enum \ SearchIndex \ ElementType ;
21+ use  Pimcore \Bundle \GenericDataIndexBundle \Traits \ LoggerAwareTrait ;
1922use  Pimcore \Bundle \GenericDataIndexBundle \Enum \SearchIndex \IndexName ;
20- use  Pimcore \Bundle \GenericDataIndexBundle \Enum \SearchIndex \IndexQueueOperation ;
21- use  Pimcore \Bundle \GenericDataIndexBundle \Exception \HandleIndexQueueEntriesException ;
23+ use  Pimcore \Bundle \GenericDataIndexBundle \Enum \SearchIndex \ElementType ;
2224use  Pimcore \Bundle \GenericDataIndexBundle \Exception \IndexDataException ;
23- use  Pimcore \Bundle \GenericDataIndexBundle \Exception \InvalidArgumentException ;
2425use  Pimcore \Bundle \GenericDataIndexBundle \Repository \IndexQueueRepository ;
25- use  Pimcore \Bundle \GenericDataIndexBundle \SearchIndexAdapter \BulkOperationServiceInterface ;
26- use  Pimcore \Bundle \GenericDataIndexBundle \SearchIndexAdapter \PathServiceInterface ;
2726use  Pimcore \Bundle \GenericDataIndexBundle \Service \ElementServiceInterface ;
27+ use  Pimcore \Bundle \GenericDataIndexBundle \Message \EnqueueRelatedIdsMessage ;
28+ use  Pimcore \Bundle \GenericDataIndexBundle \Exception \InvalidArgumentException ;
29+ use  Pimcore \Bundle \GenericDataIndexBundle \Enum \SearchIndex \IndexQueueOperation ;
30+ use  Pimcore \Bundle \GenericDataIndexBundle \SearchIndexAdapter \PathServiceInterface ;
31+ use  Pimcore \Bundle \GenericDataIndexBundle \Exception \HandleIndexQueueEntriesException ;
32+ use  Pimcore \Bundle \GenericDataIndexBundle \SearchIndexAdapter \BulkOperationServiceInterface ;
2833use  Pimcore \Bundle \GenericDataIndexBundle \Service \SearchIndex \IndexQueue \EnqueueServiceInterface ;
2934use  Pimcore \Bundle \GenericDataIndexBundle \Service \SearchIndex \IndexService \IndexServiceInterface ;
30- use  Pimcore \Bundle \GenericDataIndexBundle \Traits \LoggerAwareTrait ;
31- use  Pimcore \Model \Asset ;
32- use  Pimcore \Model \Element \ElementInterface ;
3335
3436/** 
3537 * @internal 
@@ -45,14 +47,17 @@ public function __construct(
4547        private  readonly  IndexQueueRepository $ indexQueueRepository
4648        private  readonly  EnqueueServiceInterface $ enqueueService
4749        private  readonly  ElementServiceInterface $ elementService
48-         private  readonly  SearchIndexConfigServiceInterface $ searchIndexConfigService
50+         private  readonly  SearchIndexConfigServiceInterface $ searchIndexConfigService
51+         private  readonly  MessageBusInterface $ messageBus
4952    ) {
5053    }
5154
5255    public  function  updateIndexQueue (
5356        ElementInterface $ element
5457        string  $ operation
55-         bool  $ processSynchronouslyfalse 
58+         bool  $ processSynchronouslyfalse ,
59+         bool  $ enqueueRelatedItemstrue ,
60+         bool  $ enqueueRelatedItemsAsyncfalse 
5661    ): IndexQueueService 
5762        try  {
5863            $ this checkOperationValid ($ operation
@@ -61,8 +66,14 @@ public function updateIndexQueue(
6166                $ this doHandleIndexData ($ element$ operation
6267            }
6368
64-             $ this handleQueueByOperation ($ element$ operation$ processSynchronously
65- 
69+             if ($ enqueueRelatedItems$ processSynchronouslyfalse ) {
70+                 if  ($ enqueueRelatedItemsAsync
71+                     $ this dispatchEnqueueRelatedIdsMessage ($ element$ operation$ processSynchronously
72+                 } else  {
73+                     $ this handleQueueByOperation ($ element$ operation$ processSynchronously
74+                 }
75+             }          
76+          
6677            $ this pathService ->rewriteChildrenIndexPaths ($ element
6778        } catch  (Exception $ e
6879            $ this logger ->error (
@@ -197,4 +208,19 @@ private function checkOperationValid(string $operation): void
197208            throw  new  IndexDataException (sprintf ('Operation %s not valid ' , $ operation
198209        }
199210    }
211+ 
212+     private  function  dispatchEnqueueRelatedIdsMessage (
213+         ElementInterface $ element
214+         string  $ operation
215+         bool  $ addParentElement
216+     ): void  {
217+         $ this messageBus ->dispatch (
218+             new  EnqueueRelatedIdsMessage (
219+                 $ elementgetId (),  
220+                 $ this elementService ->getElementType ($ element
221+                 $ operation
222+                 $ addParentElement
223+             )
224+         );
225+     }
200226}
0 commit comments