/**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint)
 {
     if (!$value instanceof PageInterface) {
         $this->context->addViolation('The page is not valid, expected a PageInterface');
         return;
     }
     if (!$value->getSite() instanceof SiteInterface) {
         $this->context->addViolation('The page is not linked to a Site');
         return;
     }
     // do not validated error page
     if ($value->isError()) {
         return;
     }
     $this->manager->fixUrl($value);
     $pages = $this->manager->findBy(array('site' => $value->getSite(), 'url' => $value->getUrl()));
     foreach ($pages as $page) {
         if ($page->isError() || $page->isInternal()) {
             continue;
         }
         if ($page->getUrl() == $value->getUrl() && $page != $value) {
             $this->context->addViolation('error.uniq_url', array('%url%' => $value->getUrl()));
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 public function process(ConsumerEvent $event)
 {
     $pages = $this->pageManager->findBy(array('site' => $event->getMessage()->getValue('siteId')));
     $backend = $event->getMessage()->getValue('mode') === 'async' ? $this->asyncBackend : $this->runtimeBackend;
     $keepSnapshots = $event->getMessage()->getValue('keepSnapshots');
     foreach ($pages as $page) {
         $backend->createAndPublish('sonata.page.cleanup_snapshot', array('pageId' => $page->getId(), 'keepSnapshots' => $keepSnapshots));
     }
 }
Esempio n. 3
0
 /**
  * Retrieves the list of pages (paginated)
  *
  * @ApiDoc(
  *  resource=true,
  *  output={"class"="Sonata\PageBundle\Model\PageInterface", "groups"="sonata_api_read"}
  * )
  *
  * @QueryParam(name="page", requirements="\d+", default="1", description="Page for 'page' list pagination")
  * @QueryParam(name="count", requirements="\d+", default="10", description="Number of pages by page")
  * @QueryParam(name="enabled", requirements="0|1", nullable=true, strict=true, description="Enabled/Disabled pages filter")
  * @QueryParam(name="orderBy", array=true, requirements="ASC|DESC", nullable=true, strict=true, description="Order by array (key is field, value is direction)")
  *
  * @View(serializerGroups="sonata_api_read", serializerEnableMaxDepthChecks=true)
  *
  * @param ParamFetcherInterface $paramFetcher
  *
  * @return PageInterface[]
  */
 public function getPagesAction(ParamFetcherInterface $paramFetcher)
 {
     $supportedFilters = array('enabled' => "");
     $page = $paramFetcher->get('page') - 1;
     $count = $paramFetcher->get('count');
     $orderBy = $paramFetcher->get('orderBy');
     $filters = array_intersect_key($paramFetcher->all(), $supportedFilters);
     foreach ($filters as $key => $value) {
         if (null === $value) {
             unset($filters[$key]);
         }
     }
     return $this->pageManager->findBy($filters, $orderBy, $count, $page);
 }
 /**
  * {@inheritdoc}
  */
 public function execute(BlockContextInterface $blockContext, Response $response = null)
 {
     $pageList = $this->pageManager->findBy(array('routeName' => Page::PAGE_ROUTE_CMS_NAME));
     $systemElements = $this->pageManager->findBy(array('url' => null, 'parent' => null));
     return $this->renderResponse($blockContext->getTemplate(), array('context' => $blockContext, 'block' => $blockContext->getBlock(), 'settings' => $blockContext->getSettings(), 'elements' => $pageList, 'systemElements' => $systemElements), $response);
 }