1 | <?php |
||
17 | class Listener |
||
18 | { |
||
19 | /** |
||
20 | * Object persister. |
||
21 | * |
||
22 | * @var ObjectPersisterInterface |
||
23 | */ |
||
24 | protected $objectPersister; |
||
25 | |||
26 | /** |
||
27 | * Configuration for the listener. |
||
28 | * |
||
29 | * @var array |
||
30 | */ |
||
31 | private $config; |
||
32 | |||
33 | /** |
||
34 | * Objects scheduled for insertion. |
||
35 | * |
||
36 | * @var array |
||
37 | */ |
||
38 | public $scheduledForInsertion = array(); |
||
39 | |||
40 | /** |
||
41 | * Objects scheduled to be updated or removed. |
||
42 | * |
||
43 | * @var array |
||
44 | */ |
||
45 | public $scheduledForUpdate = array(); |
||
46 | |||
47 | /** |
||
48 | * IDs of objects scheduled for removal. |
||
49 | * |
||
50 | * @var array |
||
51 | */ |
||
52 | public $scheduledForDeletion = array(); |
||
53 | |||
54 | /** |
||
55 | * PropertyAccessor instance. |
||
56 | * |
||
57 | * @var PropertyAccessorInterface |
||
58 | */ |
||
59 | protected $propertyAccessor; |
||
60 | |||
61 | /** |
||
62 | * @var IndexableInterface |
||
63 | */ |
||
64 | private $indexable; |
||
65 | |||
66 | /** |
||
67 | * Constructor. |
||
68 | * |
||
69 | * @param ObjectPersisterInterface $objectPersister |
||
70 | * @param IndexableInterface $indexable |
||
71 | * @param array $config |
||
72 | * @param LoggerInterface $logger |
||
73 | */ |
||
74 | 11 | public function __construct( |
|
93 | |||
94 | /** |
||
95 | * Handler for the "kernel.terminate" Symfony event. This event is subscribed to if the listener is configured to |
||
96 | * persist asynchronously. |
||
97 | */ |
||
98 | 1 | public function onKernelTerminate() |
|
105 | |||
106 | /** |
||
107 | * Looks for new objects that should be indexed. |
||
108 | * |
||
109 | * @param LifecycleEventArgs $eventArgs |
||
110 | */ |
||
111 | 3 | public function postPersist(LifecycleEventArgs $eventArgs) |
|
119 | |||
120 | /** |
||
121 | * Looks for objects being updated that should be indexed or removed from the index. |
||
122 | * |
||
123 | * @param LifecycleEventArgs $eventArgs |
||
124 | */ |
||
125 | 2 | public function postUpdate(LifecycleEventArgs $eventArgs) |
|
138 | |||
139 | /** |
||
140 | * Delete objects preRemove instead of postRemove so that we have access to the id. Because this is called |
||
141 | * preRemove, first check that the entity is managed by Doctrine. |
||
142 | * |
||
143 | * @param LifecycleEventArgs $eventArgs |
||
144 | */ |
||
145 | 2 | public function preRemove(LifecycleEventArgs $eventArgs) |
|
153 | |||
154 | /** |
||
155 | * Determines whether or not it is okay to persist now. |
||
156 | * |
||
157 | * @return bool |
||
158 | */ |
||
159 | 8 | private function shouldPersist() |
|
163 | |||
164 | /** |
||
165 | * Persist scheduled objects to ElasticSearch |
||
166 | * After persisting, clear the scheduled queue to prevent multiple data updates when using multiple flush calls. |
||
167 | */ |
||
168 | 8 | private function persistScheduled() |
|
185 | |||
186 | /** |
||
187 | * Iterate through scheduled actions before flushing to emulate 2.x behavior. |
||
188 | * Note that the ElasticSearch index will fall out of sync with the source |
||
189 | * data in the event of a crash during flush. |
||
190 | * |
||
191 | * This method is only called in legacy configurations of the listener. |
||
192 | * |
||
193 | * @deprecated This method should only be called in applications that depend |
||
194 | * on the behaviour that entities are indexed regardless of if a |
||
195 | * flush is successful. |
||
196 | */ |
||
197 | public function preFlush() |
||
201 | |||
202 | /** |
||
203 | * Iterating through scheduled actions *after* flushing ensures that the |
||
204 | * ElasticSearch index will be affected only if the query is successful. |
||
205 | */ |
||
206 | 7 | public function postFlush() |
|
210 | |||
211 | /** |
||
212 | * Record the specified identifier to delete. Do not need to entire object. |
||
213 | * |
||
214 | * @param object $object |
||
215 | */ |
||
216 | 3 | private function scheduleForDeletion($object) |
|
222 | |||
223 | /** |
||
224 | * Checks if the object is indexable or not. |
||
225 | * |
||
226 | * @param object $object |
||
227 | * |
||
228 | * @return bool |
||
229 | */ |
||
230 | 5 | private function isObjectIndexable($object) |
|
238 | } |
||
239 |