示例#1
0
    /**
     * @return PageLocalization
     * @throws ResourceNotFoundException if page not found or is inactive
     */
    protected function detectRequestPageLocalization()
    {
        $pathString = trim($this->attributes->get('path'), '/');
        $entityManager = $this->getEntityManager();
        $queryString = sprintf('SELECT l FROM %s l JOIN l.path p WHERE p.path = :path
			AND p.active = true AND p.locale = :locale AND l.publishedRevision IS NOT NULL', PageLocalization::CN());
        $query = $entityManager->createQuery($queryString)->setParameters(array('locale' => $this->getLocale(), 'path' => $pathString));
        $pageLocalization = $query->getOneOrNullResult();
        /* @var $pageData PageLocalization */
        if ($pageLocalization === null) {
            throw new ResourceNotFoundException(sprintf('
					No page found by path [%s] in pages controller.', $pathString));
        }
        if (!$pageLocalization->isActive()) {
            throw new ResourceNotFoundException(sprintf('Page found by path [%s] in pages controller is inactive.'));
        }
        $localeManager = $this->container->getLocaleManager();
        if (!$localeManager->isActive($pageLocalization->getLocaleId())) {
            throw new ResourceNotFoundException(sprintf('Page found by path [%s] in pages controller belongs to inactive locale [%s].', $pathString, $this->getLocale()));
        }
        return $pageLocalization;
    }
 protected function prepareData(ClassMetadata $metadata, array $data)
 {
     foreach ($data as $name => &$entityData) {
         switch ($metadata->name) {
             case Localization::CN():
             case PageLocalization::CN():
             case TemplateLocalization::CN():
             case ApplicationLocalization::CN():
                 $entityData['publishedRevision'] = null;
                 $args = array($entityData['locale']);
                 break;
             case PageLocalizationPath::CN():
                 $args = array(str_ireplace('pageLocalizationPath', '', $name), $entityData['locale']);
                 break;
             case TemplateLayout::CN():
                 $args = array($entityData['media']);
                 break;
             case BlockPropertyMetadata::CN():
                 $args = array($entityData['name'], $entityData['blockProperty']);
                 break;
             case BlockProperty::CN():
                 $args = array($entityData['name']);
                 break;
             case PagePlaceHolder::CN():
             case TemplatePlaceHolder::CN():
                 $args = array($entityData['name']);
                 break;
             default:
                 $constructor = new \ReflectionMethod($metadata->name, '__construct');
                 if ($constructor->getNumberOfRequiredParameters() === 0) {
                     return parent::prepareData($metadata, $data);
                 }
                 throw new \RuntimeException(sprintf('Don\'t know how to build constructor required for [%s].', $metadata->name));
         }
         $entityData = array_merge(array('__construct' => $args), $entityData);
     }
     return parent::prepareData($metadata, $data);
 }
 public static function getLinkReferencedElementUrl(LinkReferencedElement $element, EntityManager $entityManager, LocaleInterface $currenctLocale)
 {
     switch ($element->getResource()) {
         case LinkReferencedElement::RESOURCE_LINK:
             return $element->getHref();
         case LinkReferencedElement::RESOURCE_PAGE:
             $localization = $entityManager->getRepository(PageLocalization::CN())->findOneBy(array('master' => $element->getPageId(), 'locale' => $currenctLocale->getId()));
             /* @var $localization PageLocalization */
             if ($localization !== null) {
                 // @TODO: allow to affect the path somehow?
                 return $localization->getFullPath(Path::FORMAT_LEFT_DELIMITER);
             }
             break;
         case LinkReferencedElement::RESOURCE_FILE:
             // @FIXME: get the filestorage somehow, or use File entity?
             throw new \Exception('Implement me, I have no file storage here.');
             break;
         default:
             throw new \UnexpectedValueException("Unrecognized resource type [{$element->getResource()}].");
     }
     return null;
     // @TODO: 'email' resource type handling?
 }
 /**
  * @return \Doctrine\ORM\QueryBuilder
  */
 protected function doGetQueryBuilder()
 {
     // Clones the query builder for local usage
     $qb = clone $this->pageFinder->getQueryBuilder();
     if ($this->pageFinder instanceof TemplateFinder) {
         $qb->from(TemplateLocalization::CN(), 'l');
         $qb->select('l');
     } else {
         $qb->from(PageLocalization::CN(), 'l');
         $qb->select('l, e2, p');
         $qb->join('l.path', 'p');
         $qb->join('l.master', 'e2');
         //			if ($this->active) {
         //				$qb->andWhere('l.active = true AND p.path IS NOT NULL');
         //			}
         if ($this->public) {
             $qb->andWhere('l.publishedRevision IS NOT NULL');
         }
         if ($this->visibleInSitemap) {
             $qb->andWhere('l.visibleInSitemap = true');
         }
         if ($this->visibleInMenu) {
             $qb->andWhere('l.visibleInMenu = true');
         }
         if (!is_null($this->redirect)) {
             $qb->andWhere('l.redirect IS ' . ($this->redirect ? 'NOT ' : '') . 'NULL');
         }
     }
     $qb->andWhere('l.master = e');
     // Join only to fetch the master
     // It's important to include all or else extra queries will be executed
     //$qb->select('l, e2, p');
     if (!empty($this->locale)) {
         $qb->andWhere('l.locale = :locale')->setParameter('locale', $this->locale);
     }
     return $qb;
 }
示例#5
0
 protected function restorePageVersion()
 {
     //$this->isPostRequest();
     $revisionId = $this->getRequestParameter('revision_id');
     $localizationId = $this->getRequestParameter('page_id');
     $em = $this->container->getDoctrine()->getManager();
     $locale = $this->container->getLocaleManager()->getCurrentLocale();
     $auditManager = $this->container['entity_audit.manager'];
     /* @var $auditManager AuditManager */
     $auditReader = $auditManager->createAuditReader($em);
     //TODO: this is hacky (revisionId - 1) because EA does not take into account DEL revisions
     $localization = $auditReader->find(PageLocalization::CN(), $localizationId, $revisionId - 1);
     /* @var PageLocalization $localization */
     $page = $localization->getMaster();
     /* @var Page $page */
     foreach ($page->getLocalizations() as $localization) {
         //reload templates
         $template = $localization->getTemplate();
         $realTemplate = $em->getRepository('Cms:Template')->find($template->getId());
         if ($realTemplate) {
             $localization->setTemplate($realTemplate);
         } else {
             $em->persist($template);
         }
         //reload localization path
         $localizationPath = $localization->getPathEntity();
         $realLocalizationPath = $em->getRepository('Cms:PageLocalizationPath')->find($localizationPath->getId());
         if ($realLocalizationPath) {
             $localization->setPathEntity($realLocalizationPath);
         } else {
             $em->persist($localizationPath);
         }
         $em->persist($localization);
     }
     //reset nested set node
     $page->setLevel(null);
     $page->setLeftValue(null);
     $page->setRightValue(null);
     $node = new DoctrineNode($em->getRepository($page->getNestedSetRepositoryClassName()));
     $page->setNestedSetNode($node);
     $node->belongsTo($page);
     $em->persist($page);
     $em->flush();
     $parent = $this->getPageByRequestKey('parent_id');
     $reference = $this->getPageByRequestKey('reference');
     try {
         if (!is_null($reference)) {
             $page->moveAsPrevSiblingOf($reference);
         } elseif (!is_null($parent)) {
             $parent->addChild($page);
         }
     } catch (DuplicatePagePathException $uniqueException) {
         $confirmation = $this->getConfirmation('{#sitemap.confirmation.duplicate_path#}');
         if ($confirmation instanceof Response) {
             return $confirmation;
         }
         $localizations = $page->getLocalizations();
         foreach ($localizations as $localization) {
             $pathPart = $localization->getPathPart();
             // some bad solution
             $localization->setPathPart($pathPart . '-' . time());
         }
         if (!is_null($reference)) {
             $page->moveAsPrevSiblingOf($reference);
         } elseif (!is_null($parent)) {
             $parent->addChild($page);
         }
     }
     return new SupraJsonResponse($this->convertPageToArray($page, $this->getCurrentLocale()->getId()));
     //		// We need it so later we can mark it as restored
     //		$pageRevisionData = $draftEm->getRepository(PageRevisionData::CN())
     //			->findOneBy(array('type' => PageRevisionData::TYPE_TRASH, 'id' => $revisionId));
     //
     //		if ( ! ($pageRevisionData instanceof PageRevisionData)) {
     //			throw new CmsException(null, 'Page revision data not found');
     //		}
     //
     //		$masterId = $auditEm->createQuery("SELECT l.master FROM page:Abstraction\Localization l
     //				WHERE l.id = :id AND l.revision = :revision")
     //			->execute(
     //				array('id' => $localizationId, 'revision' => $revisionId), ColumnHydrator::HYDRATOR_ID);
     //
     //		$page = null;
     //
     //		try {
     //			$page = $auditEm->getRepository(AbstractPage::CN())
     //				->findOneBy(array('id' => $masterId, 'revision' => $revisionId));
     //		} catch (MissingResourceOnRestore $missingResource) {
     //			$missingResourceName = $missingResource->getMissingResourceName();
     //			throw new CmsException(null, "Wasn't able to load the page from the history because linked resource {$missingResourceName} is not available anymore.");
     //		}
     //
     //		if (empty($page)) {
     //			throw new CmsException(null, "Cannot find the page");
     //		}
     //
     //		$localeId = $this->getLocale()->getId();
     //		$media = $this->getMedia();
     //
     //		$pageLocalization = $page->getLocalization($localeId);
     //
     //		if (is_null($pageLocalization)) {
     //			throw new CmsException(null, 'This page has no localization for current locale');
     //		}
     //
     //		$request = new HistoryPageRequestEdit($localeId, $media);
     //		$request->setDoctrineEntityManager($draftEm);
     //		$request->setPageLocalization($pageLocalization);
     //
     //		$draftEventManager = $draftEm->getEventManager();
     //		$draftEventManager->dispatchEvent(AuditEvents::pagePreRestoreEvent);
     //
     //		$parent = $this->getPageByRequestKey('parent_id');
     //		$reference = $this->getPageByRequestKey('reference');
     //
     //		// Did not allowed to restore root page. Ask Aigars for details
     ////		if (is_null($parent) && $page instanceof Page) {
     ////			throw new CmsException('sitemap.error.parent_page_not_found');
     ////		}
     //
     //		$draftEm->beginTransaction();
     //		try {
     //			$request->restorePage();
     //
     //			// Read from the draft now
     //			$page = $draftEm->find(AbstractPage::CN(), $page->getId());
     //
     //			/* @var $page AbstractPage */
     //
     //			try {
     //				if ( ! is_null($reference)) {
     //					$page->moveAsPrevSiblingOf($reference);
     //				} elseif ( ! is_null($parent)) {
     //					$parent->addChild($page);
     //				}
     //			} catch (DuplicatePagePathException $uniqueException) {
     //
     //				$this->getConfirmation('{#sitemap.confirmation.duplicate_path#}');
     //
     //				$localizations = $page->getLocalizations();
     //				foreach ($localizations as $localization) {
     //					$pathPart = $localization->getPathPart();
     //
     //					// some bad solution
     //					$localization->setPathPart($pathPart . '-' . time());
     //				}
     //
     //				if ( ! is_null($reference)) {
     //					$page->moveAsPrevSiblingOf($reference);
     //				} elseif ( ! is_null($parent)) {
     //					$parent->addChild($page);
     //				}
     //			}
     //
     //			$pageRevisionData->setType(PageRevisionData::TYPE_RESTORED);
     //			$draftEm->flush();
     //
     //			$localization = $page->getLocalization($localeId);
     //			$this->pageData = $localization;
     //		} catch (\Exception $e) {
     //			$draftEm->rollback();
     //			throw $e;
     //		}
 }
 /**
  * Get list of pages converted to array
  * @param string $entity
  * @return array
  */
 private function loadSitemapTree($entity)
 {
     $em = $this->getEntityManager();
     $input = $this->getRequestInput();
     $localeId = $this->getCurrentLocale()->getId();
     // Parent ID and level
     $levels = null;
     $parentId = null;
     if ($input->has('parent_id')) {
         $parentId = $input->get('parent_id');
         // Special case for root page, need to fetch 2 levels
         if (empty($parentId)) {
             $levels = 2;
         } else {
             $levels = 1;
         }
     } else {
         $levels = 2;
     }
     $parentLocalization = null;
     $filter = null;
     if (!empty($parentId)) {
         if (strpos($parentId, '_') !== false) {
             list($parentId, $filter) = explode('_', $parentId);
         }
         // Find localization, special case for group pages
         if ($entity == Page::CN()) {
             $parentLocalization = $em->find(PageLocalization::CN(), $parentId);
             if (is_null($parentLocalization)) {
                 $rootNode = $em->find($entity, $parentId);
                 if ($rootNode instanceof GroupPage) {
                     $parentLocalization = $rootNode->getLocalization($localeId);
                 }
             }
         } else {
             $parentLocalization = $em->find(TemplateLocalization::CN(), $parentId);
         }
         if (is_null($parentLocalization)) {
             throw new CmsException(null, 'The page the children has been requested for was not found');
         }
     }
     $response = $this->gatherChildrenData($entity, $parentLocalization, $filter, $levels);
     return $response;
 }
示例#7
0
 /**
  * Loads only public children
  * @return ArrayCollection
  */
 public function getPublicChildren()
 {
     $coll = $this->getChildren(PageLocalization::CN());
     foreach ($coll as $key => $child) {
         if (!$child instanceof PageLocalization) {
             $coll->remove($key);
             continue;
         }
         if (!$child->isPublic()) {
             $coll->remove($key);
             continue;
         }
     }
     return $coll;
 }
示例#8
0
 /**
  * @param DeepCopy $deepCopy
  * @param EntityManager $entityManager
  * @return DeepCopy
  */
 private function addDeepCopyCommonFilters(DeepCopy $deepCopy, EntityManager $entityManager)
 {
     $keepFilter = new KeepFilter();
     $nullifyFilter = new SetNullFilter();
     // Matches RedirectTargetPage::$page property.
     // Keeps the $page property redirect target is referencing to.
     $deepCopy->addFilter($keepFilter, new PropertyMatcher(RedirectTargetPage::CN(), 'page'));
     // Matches PageLocalization::$template.
     // Prevents the template to be cloned.
     $deepCopy->addFilter($keepFilter, new PropertyMatcher(PageLocalization::CN(), 'template'));
     // Matches Localization::$path
     // Keeps the value since it is cloned manually (see PageLocalization::__clone());
     $deepCopy->addFilter($keepFilter, new PropertyMatcher(Localization::CN(), 'path'));
     // Matches Block::$blockProperties collection.
     // Replaces with empty collection, since block properties can be obtained via Localization::$blockProperties.
     $deepCopy->addFilter(new DoctrineEmptyCollectionFilter(), new PropertyMatcher(Block::CN(), 'blockProperties'));
     // Matches Localization::$lock.
     // Nullifies editing lock entity.
     $deepCopy->addFilter($nullifyFilter, new PropertyMatcher(Localization::CN(), 'lock'));
     // Matches Localization::$publishedRevision.
     $deepCopy->addFilter($nullifyFilter, new PropertyMatcher(Localization::CN(), 'publishedRevision'));
     // Matches Localization::$publishTime.
     $deepCopy->addFilter($nullifyFilter, new PropertyMatcher(Localization::CN(), 'publishTime'));
     // Matches Entity Collection.
     // Creates Copy and persists the elements in it.
     $deepCopy->addFilter(new DoctrineCollectionFilter($entityManager), new PropertyTypeMatcher('Doctrine\\Common\\Collections\\Collection'));
     // Matches any Entity.
     // Creates copy and persists it.
     $deepCopy->addFilter(new DoctrineEntityFilter($entityManager), new PropertyTypeMatcher(Entity::CN()));
 }
 /**
  * Recurse path regeneration for the localization and all its descendants
  * @param PageLocalization $localization
  * @param boolean $force
  */
 private function pageLocalizationChange(PageLocalization $localization, $force = false)
 {
     $master = $localization->getMaster();
     $pageLocalizationEntity = PageLocalization::CN();
     $dql = "SELECT l FROM {$pageLocalizationEntity} l JOIN l.master m\n\t\t\t\tWHERE m.left >= :left\n\t\t\t\tAND m.right <= :right\n\t\t\t\tAND l.locale = :locale\n\t\t\t\tORDER BY m.left";
     $pageLocalizations = $this->em->createQuery($dql)->setParameters(array('left' => $master->getLeftValue(), 'right' => $master->getRightValue(), 'locale' => $localization->getLocale()))->getResult();
     foreach (array($localization) as $pageLocalization) {
         $this->generatePath($pageLocalization, $force);
     }
 }
 /**
  * Template delete action.
  *
  * @return SupraJsonResponse
  */
 public function deleteAction()
 {
     $page = $this->getPageLocalization()->getMaster();
     $entityManager = $this->getEntityManager();
     $count = (int) $entityManager->createQuery(sprintf('SELECT COUNT(p.id) FROM %s p WHERE p.template = ?0', PageLocalization::CN()))->setParameters(array($page->getId()))->getSingleScalarResult();
     if ($count > 0) {
         throw new CmsException(null, "Cannot remove template, {$count} page(s) still uses it.");
     }
     $entityManager->remove($page);
     $entityManager->flush();
     return new SupraJsonResponse();
 }