public function onFlush(OnFlushEventArgs $args)
 {
     /** @var $om EntityManager */
     $om = $args->getEntityManager();
     $uow = $om->getUnitOfWork();
     $arm = $this->getAutoRouteManager();
     $this->contentResolver->setEntityManager($om);
     $this->insertions = $uow->getScheduledEntityInsertions();
     $scheduledUpdates = $uow->getScheduledEntityUpdates();
     //        $updates = array_merge($scheduledInserts, $scheduledUpdates);
     foreach ($scheduledUpdates as $document) {
         $this->handleInsertOrUpdate($document, $arm, $om, $uow);
     }
     $removes = $uow->getScheduledCollectionDeletions();
     foreach ($removes as $document) {
         if ($this->isAutoRouteable($document)) {
             $referrers = $om->getRepository('Symfony\\Cmf\\Bundle\\RoutingAutoBundle\\Doctrine\\Orm\\AutoRoute')->findBy(array('contentCode' => $this->contentResolver->getContentCode($document)));
             if ($referrers) {
                 foreach ($referrers as $autoRoute) {
                     $uow->scheduleForDelete($autoRoute);
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * @param ManagerRegistry $managerRegistry
  * @param string $managerName
  * @param ContentCodeResolver $contentResolver
  * @internal param string $autoRouteFqcn The FQCN of the AutoRoute document to use
  */
 public function __construct(ManagerRegistry $managerRegistry, $managerName, ContentCodeResolver $contentResolver, $autoRouteFqcn = 'Symfony\\Cmf\\Bundle\\RoutingAutoBundle\\Doctrine\\Orm\\AutoRoute')
 {
     $this->em = $managerRegistry->getManager($managerName);
     $reflection = new \ReflectionClass($autoRouteFqcn);
     if (!$reflection->isSubclassOf('Symfony\\Cmf\\Component\\RoutingAuto\\Model\\AutoRouteInterface')) {
         throw new \InvalidArgumentException(sprintf('AutoRoute documents have to implement the AutoRouteInterface, "%s" does not.', $autoRouteFqcn));
     }
     $this->contentResolver = $contentResolver;
     $this->contentResolver->setEntityManager($this->em);
     $this->autoRouteFqcn = $autoRouteFqcn;
 }