File tree Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Expand file tree Collapse file tree 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /*
4+ * This file is part of the FOSElasticaBundle package.
5+ *
6+ * (c) FriendsOfSymfony <https://friendsofsymfony.github.com/>
7+ *
8+ * For the full copyright and license information, please view the LICENSE
9+ * file that was distributed with this source code.
10+ */
11+
12+ namespace FOS \ElasticaBundle \Doctrine ;
13+
14+ interface ConditionalUpdate
15+ {
16+ /**
17+ * Determines if an entity should be updated in Elasticsearch.
18+ */
19+ public function shouldBeUpdated (): bool ;
20+ }
Original file line number Diff line number Diff line change 1212namespace FOS \ElasticaBundle \Doctrine ;
1313
1414use Doctrine \Persistence \Event \LifecycleEventArgs ;
15+ use FOS \ElasticaBundle \Doctrine \ConditionalUpdate ;
1516use FOS \ElasticaBundle \Persister \ObjectPersister ;
1617use FOS \ElasticaBundle \Persister \ObjectPersisterInterface ;
1718use FOS \ElasticaBundle \Provider \IndexableInterface ;
@@ -96,7 +97,9 @@ public function postPersist(LifecycleEventArgs $eventArgs)
9697 $ entity = $ eventArgs ->getObject ();
9798
9899 if ($ this ->objectPersister ->handlesObject ($ entity ) && $ this ->isObjectIndexable ($ entity )) {
99- $ this ->scheduledForInsertion [] = $ entity ;
100+ if (!$ entity instanceof ConditionalUpdate || $ entity ->shouldBeUpdated ()) {
101+ $ this ->scheduledForInsertion [] = $ entity ;
102+ }
100103 }
101104 }
102105
@@ -109,7 +112,9 @@ public function postUpdate(LifecycleEventArgs $eventArgs)
109112
110113 if ($ this ->objectPersister ->handlesObject ($ entity )) {
111114 if ($ this ->isObjectIndexable ($ entity )) {
112- $ this ->scheduledForUpdate [] = $ entity ;
115+ if (!$ entity instanceof ConditionalUpdate || $ entity ->shouldBeUpdated ()) {
116+ $ this ->scheduledForUpdate [] = $ entity ;
117+ }
113118 } else {
114119 // Delete if no longer indexable
115120 $ this ->scheduleForDeletion ($ entity );
You can’t perform that action at this time.
0 commit comments