/**
  * Update URL for a page and its descendants according to the application UrlGeneratorInterface.
  *
  * @param BBApplication        $application
  * @param Page                 $page
  * @param AbstractClassContent $maincontent
  */
 private static function updateUrl(BBApplication $application, Page $page, AbstractClassContent $maincontent = null)
 {
     $urlGenerator = $application->getUrlGenerator();
     $em = $application->getEntityManager();
     $uow = $em->getUnitOfWork();
     $changeSet = $uow->getEntityChangeSet($page);
     if (null === $maincontent && 0 < count($urlGenerator->getDiscriminators())) {
         if ($uow->isScheduledForInsert($page)) {
             foreach ($uow->getScheduledEntityInsertions() as $entity) {
                 if ($entity instanceof \BackBee\ClassContent\AbstractClassContent && $page === $entity->getMainNode()) {
                     $maincontent = $entity;
                     break;
                 }
             }
         } else {
             $maincontent = $em->getRepository('BackBee\\ClassContent\\AbstractClassContent')->getLastByMainnode($page, $urlGenerator->getDiscriminators());
         }
     }
     $newUrl = null;
     $url = $page->getUrl(false);
     if (isset($changeSet['_url']) && !empty($url)) {
         $newUrl = $urlGenerator->getUniqueness($page, $page->getUrl());
     } else {
         $force = isset($changeSet['_state']) && !($changeSet['_state'][0] & Page::STATE_ONLINE);
         $newUrl = $urlGenerator->generate($page, $maincontent, $force);
     }
     if ($newUrl !== $page->getUrl(false)) {
         $page->setUrl($newUrl);
         $classMetadata = $em->getClassMetadata('BackBee\\NestedNode\\Page');
         if ($uow->isScheduledForInsert($page) || $uow->isScheduledForUpdate($page)) {
             $uow->recomputeSingleEntityChangeSet($classMetadata, $page);
         } elseif (!$uow->isScheduledForDelete($page)) {
             $uow->computeChangeSet($classMetadata, $page);
         }
         return true;
     }
     return false;
 }
Example #2
0
 /**
  * Update URL for a page and its descendants according to the application UrlGeneratorInterface.
  *
  * @param \BackBee\BBApplication              $application
  * @param \BackBee\NestedNode\Page            $page
  * @param \BackBee\ClassContent\AbstractClassContent $maincontent
  */
 private static function _updateUrl(BBApplication $application, Page $page, AbstractClassContent $maincontent = null)
 {
     $urlGenerator = $application->getUrlGenerator();
     if (!$urlGenerator instanceof UrlGeneratorInterface) {
         return;
     }
     $em = $application->getEntityManager();
     if (null === $maincontent && 0 < count($urlGenerator->getDiscriminators())) {
         $maincontent = $em->getRepository('BackBee\\ClassContent\\AbstractClassContent')->getLastByMainnode($page, $urlGenerator->getDiscriminators());
     }
     $newUrl = $urlGenerator->generate($page, $maincontent);
     if ($page->getUrl() != $newUrl) {
         $page->setUrl($newUrl);
         $uow = $em->getUnitOfWork();
         if ($uow->isScheduledForInsert($page) || $uow->isScheduledForUpdate($page)) {
             $uow->recomputeSingleEntityChangeSet($em->getClassMetadata('BackBee\\NestedNode\\Page'), $page);
         } elseif (!$uow->isScheduledForDelete($page)) {
             $uow->computeChangeSet($em->getClassMetadata('BackBee\\NestedNode\\Page'), $page);
         }
     }
 }