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 | 17 | public function __construct( |
|
91 | |||
92 | /** |
||
93 | * Looks for new objects that should be indexed. |
||
94 | * |
||
95 | * @param LifecycleEventArgs $eventArgs |
||
96 | */ |
||
97 | 3 | public function postPersist(LifecycleEventArgs $eventArgs) |
|
105 | |||
106 | /** |
||
107 | * Looks for objects being updated that should be indexed or removed from the index. |
||
108 | * |
||
109 | * @param LifecycleEventArgs $eventArgs |
||
110 | */ |
||
111 | 3 | public function postUpdate(LifecycleEventArgs $eventArgs) |
|
124 | |||
125 | /** |
||
126 | * Delete objects preRemove instead of postRemove so that we have access to the id. Because this is called |
||
127 | * preRemove, first check that the entity is managed by Doctrine. |
||
128 | * |
||
129 | * @param LifecycleEventArgs $eventArgs |
||
130 | */ |
||
131 | 3 | public function preRemove(LifecycleEventArgs $eventArgs) |
|
139 | |||
140 | /** |
||
141 | * Persist scheduled objects to ElasticSearch |
||
142 | * After persisting, clear the scheduled queue to prevent multiple data updates when using multiple flush calls. |
||
143 | */ |
||
144 | 9 | private function persistScheduled() |
|
164 | |||
165 | /** |
||
166 | * Iterate through scheduled actions before flushing to emulate 2.x behavior. |
||
167 | * Note that the ElasticSearch index will fall out of sync with the source |
||
168 | * data in the event of a crash during flush. |
||
169 | * |
||
170 | * This method is only called in legacy configurations of the listener. |
||
171 | * |
||
172 | * @deprecated This method should only be called in applications that depend |
||
173 | * on the behaviour that entities are indexed regardless of if a |
||
174 | * flush is successful. |
||
175 | */ |
||
176 | public function preFlush() |
||
180 | |||
181 | /** |
||
182 | * Iterating through scheduled actions *after* flushing ensures that the |
||
183 | * ElasticSearch index will be affected only if the query is successful. |
||
184 | */ |
||
185 | 9 | public function postFlush() |
|
189 | |||
190 | /** |
||
191 | * Record the specified identifier to delete. Do not need to entire object. |
||
192 | * |
||
193 | * @param object $object |
||
194 | */ |
||
195 | 4 | private function scheduleForDeletion($object) |
|
201 | |||
202 | /** |
||
203 | * Checks if the object is indexable or not. |
||
204 | * |
||
205 | * @param object $object |
||
206 | * |
||
207 | * @return bool |
||
208 | */ |
||
209 | 6 | private function isObjectIndexable($object) |
|
217 | } |
||
218 |