Example #1
0
File: Router.php Project: busaev/s3
 /**
  * Эвент, выполняемый после обновления записи
  * Если у записи есть routePath - Обновляем Route
  * 
  * @param LifecycleEventArgs $args
  */
 public function postUpdate(LifecycleEventArgs $args)
 {
     $entity = $args->getEntity();
     if ($this->skipCondition($entity) && is_callable(array($entity, 'getRoutePath'))) {
         $em = $args->getEntityManager();
         $entities = $this->container->get('app.entities');
         $router = $this->container->get('app.route');
         $path = $entity->getRoutePath();
         if ('' == $path) {
             return;
         }
         $entityCode = $entities->getEntityCode($entity)->getCode();
         $action = $router->getLogicalAction($entity, $entityCode);
         $route = $em->getRepository('AppBundle:Core\\Route')->findOneBy(['entityCode' => $entityCode, 'entryId' => $entity->getId()]);
         if (null !== $route) {
             $route->setPath($path);
             $route->setAction($action);
             $em->persist($route);
             $em->flush();
         } else {
             $route = new Route();
             $route->setEntityCode($entityCode);
             $route->setPath($path);
             $route->setAction($action);
             $route->setEntryId($entity->getId());
             $em->persist($route);
             $em->flush();
         }
         $fs = new Filesystem();
         $fs->remove($this->container->getParameter('kernel.cache_dir'));
     }
 }