Skip to content

Commit

Permalink
Adding temporary fix to handle child changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Vison committed Mar 29, 2018
1 parent ae8d4f8 commit a73c8f7
Showing 1 changed file with 44 additions and 6 deletions.
50 changes: 44 additions & 6 deletions EventListener/DoctrineEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,68 @@ public function getSubscribedEvents()
);
}

public function getChangedOids($entities, &$oids) {

foreach($entities as $entity) {

$reflection = new \ReflectionObject($entity);
$methods = $reflection->getMethods();

foreach($methods as $method) {

// Getter must not have a parameter!!
if(strpos($method->getName(), "get") !== false && count($method->getParameters()) <= 0) {
$result = $method->invoke($entity);
if(is_object($result)) {
$reflection2 = new \ReflectionClass(get_class($result));
$annotations = $reflection2->getDocComment();
if(strpos($annotations, '@ORM\Entity') !== false) {
$oid = spl_object_hash($result);
if(method_exists($result, 'setLastTimestamp')) {
$oids[] = $oid;
}
$this->getChangedOids(array($result), $oids);
}
}
}
}
}
}

public function onFlush(OnFlushEventArgs $args)
{
$em = $args->getEntityManager();
$uow = $em->getUnitOfWork();


$oids = array();
$this->getChangedOids($uow->getScheduledEntityUpdates(), $oids);

foreach ($uow->getScheduledEntityUpdates() as $keyEntity => $entity) {

$changes = $uow->getEntityChangeSet($entity);

if(count($changes) == 1 && isset($changes["lastTimestamp"])) {
if (count($changes) == 1 && isset($changes["lastTimestamp"])) {
$oid = spl_object_hash($entity);
$uow->clearEntityChangeSet($oid);
continue;
if(!in_array($oid, $oids)) {
// dump(get_class($entity)." is not really chaning anything...");
$uow->clearEntityChangeSet($oid);
continue;
}
}
$this->handleEntityChange($em, $entity);
}

foreach ($uow->getScheduledEntityInsertions() as $keyEntity => $entity) {
$this->handleEntityChange($em, $entity);
}
//
// dump($oids);
// dump("Finished");
// die;
}

public function preRemove(LifecycleEventArgs $args)
{

public function preRemove(LifecycleEventArgs $args) {
$entity = $args->getEntity();
$class = get_class($entity);
$id = null;
Expand All @@ -72,4 +109,5 @@ private function handleEntityChange(EntityManagerInterface $em, $entity) {
$this->syncService->updateSyncState($em, $class, $timestamp);
}


}

0 comments on commit a73c8f7

Please sign in to comment.