@@ -29,6 +29,13 @@ class SoftDeleteableListener extends MappedEventSubscriber
2929 */
3030 const POST_SOFT_DELETE = "postSoftDelete " ;
3131
32+ /**
33+ * Objects soft-deleted on flush.
34+ *
35+ * @var array
36+ */
37+ private $ softDeletedObjects = array ();
38+
3239 /**
3340 * {@inheritdoc}
3441 */
@@ -37,6 +44,7 @@ public function getSubscribedEvents()
3744 return array (
3845 'loadClassMetadata ' ,
3946 'onFlush ' ,
47+ 'postFlush '
4048 );
4149 }
4250
@@ -64,7 +72,9 @@ public function onFlush(EventArgs $args)
6472 $ reflProp = $ meta ->getReflectionProperty ($ config ['fieldName ' ]);
6573 $ oldValue = $ reflProp ->getValue ($ object );
6674 $ date = new \DateTime ();
67- if (isset ($ config ['hardDelete ' ]) && $ config ['hardDelete ' ] && $ oldValue instanceof \DateTimeInterface && $ oldValue <= $ date ) {
75+
76+ // Remove `$oldValue instanceof \DateTime` check when PHP version is bumped to >=5.5
77+ if (isset ($ config ['hardDelete ' ]) && $ config ['hardDelete ' ] && ($ oldValue instanceof \DateTime || $ oldValue instanceof \DateTimeInterface) && $ oldValue <= $ date ) {
6878 continue ; // want to hard delete
6979 }
7080
@@ -90,10 +100,32 @@ public function onFlush(EventArgs $args)
90100 self ::POST_SOFT_DELETE ,
91101 $ ea ->createLifecycleEventArgsInstance ($ object , $ om )
92102 );
103+
104+ $ this ->softDeletedObjects [] = $ object ;
93105 }
94106 }
95107 }
96108
109+ /**
110+ * Detach soft-deleted objects from object manager.
111+ *
112+ * @param \Doctrine\Common\EventArgs $args
113+ *
114+ * @return void
115+ *
116+ * @throws \Gedmo\Exception\InvalidArgumentException
117+ */
118+ public function postFlush (EventArgs $ args )
119+ {
120+ $ ea = $ this ->getEventAdapter ($ args );
121+ $ om = $ ea ->getObjectManager ();
122+
123+ foreach ($ this ->softDeletedObjects as $ index => $ object ) {
124+ $ om ->detach ($ object );
125+ unset($ this ->softDeletedObjects [$ index ]);
126+ }
127+ }
128+
97129 /**
98130 * Maps additional metadata
99131 *
0 commit comments