Example #1
0
 /**
  * Remove a page from databse.
  *
  * @param Page $page
  */
 public function deletePage(Page $page)
 {
     if ($page->hasMainSection()) {
         $this->getEntityManager()->getRepository('BackBee\\NestedNode\\Section')->deleteSection($page->getSection());
     }
     if (null !== $page->getContentSet()) {
         $this->getEntityManager()->createQueryBuilder()->update('BackBee\\NestedNode\\Page', 'p')->set('p._contentset', ':null')->where('p._contentset = :uid')->setParameter('uid', $page->getContentSet()->getUid())->setParameter('null', null)->getQuery()->execute();
         $this->getEntityManager()->getRepository('BackBee\\ClassContent\\AbstractClassContent')->deleteContent($page->getContentSet());
     }
     $this->getEntityManager()->createQueryBuilder()->update('BackBee\\ClassContent\\AbstractClassContent', 'c')->set('c._mainnode', ':null')->where('c._mainnode = :uid')->setParameter('uid', $page->getUid())->setParameter('null', null)->getQuery()->execute();
     $this->getEntityManager()->remove($page);
 }
Example #2
0
 /**
  * Checks for the uniqueness of the URL and postfixe it if need.
  *
  * @param \BackBee\NestedNode\Page $page The page
  * @param string                   &$url The reference of the generated URL
  */
 public function getUniqueness(Page $page, $url)
 {
     if (!$this->preserveUnicity) {
         return $url;
     }
     $pageRepository = $this->application->getEntityManager()->getRepository('BackBee\\NestedNode\\Page');
     if (null === $pageRepository->findOneBy(['_url' => $url, '_root' => $page->getRoot(), '_state' => $page->getUndeletedStates()])) {
         return $url;
     }
     $baseUrl = $url . '-%d';
     $matches = [];
     $existings = [];
     if (preg_match('#(.*)\\/$#', $baseUrl, $matches)) {
         $baseUrl = $matches[1] . '-%d/';
         $existings = $pageRepository->createQueryBuilder('p')->andRootIs($page->getRoot())->andWhere('p._url LIKE :url')->setParameter('url', $matches[1] . '%/')->getQuery()->getResult();
     } else {
         $existings = $this->application->getEntityManager()->getConnection()->executeQuery('SELECT p.uid FROM page p LEFT JOIN section s ON s.uid = p.section_uid WHERE s.root_uid = :root AND p.url REGEXP :regex', ['regex' => str_replace(['+'], ['[+]'], $url) . '(-[0-9]+)?$', 'root' => $page->getRoot()->getUid()])->fetchAll();
         $uids = [];
         foreach ($existings as $existing) {
             $uids[] = $existing['uid'];
         }
         $existings = $pageRepository->findBy(['_uid' => $uids]);
     }
     $existingUrls = [];
     foreach ($existings as $existing) {
         if (!$existing->isDeleted() && $existing->getUid() !== $page->getUid()) {
             $existingUrls[] = $existing->getUrl(false);
         }
     }
     $count = 1;
     while (in_array($url, $existingUrls)) {
         $url = sprintf($baseUrl, $count++);
     }
     return $url;
 }
 /**
  * Remove stored page-content and site-content indexes from a page.
  *
  * @param Page $page
  *
  * @return IndexationRepository
  */
 public function removeIdxPage(Page $page)
 {
     $query = 'DELETE FROM idx_page_content WHERE page_uid = :page';
     $params = array('page' => $page->getUid());
     return $this->removeIdxSite($page)->_executeQuery($query, $params);
 }
Example #4
0
 /**
  * @covers BackBee\NestedNode\Page::__clone
  */
 public function test__clone()
 {
     $child = new Page('child', array('title' => 'child', 'url' => 'url'));
     $revision = new PageRevision();
     $child->setSection($this->page->getSection())->setState(Page::STATE_ONLINE)->getRevisions()->add($revision);
     $clone = clone $child;
     $this->assertNotEquals($child->getContentSet(), $clone->getContentSet());
     $this->assertNotEquals($child->getUid(), $clone->getUid());
     $this->assertEquals(1, $clone->getPosition());
     $this->assertEquals(1, $clone->getLevel());
     $this->assertGreaterThanOrEqual($clone->getCreated()->getTimestamp(), $child->getCreated()->getTimestamp());
     $this->assertGreaterThanOrEqual($clone->getModified()->getTimestamp(), $child->getModified()->getTimestamp());
     $this->assertNull($clone->getMainSection());
     $this->assertEquals(Page::STATE_HIDDEN, $clone->getState());
     $this->assertFalse($clone->isStatic());
     $this->assertEquals($child->getTitle(), $clone->getTitle());
     $this->assertEquals(null, $clone->getUrl());
     $this->assertTrue(is_array($clone->cloningData));
     $this->assertTrue(isset($clone->cloningData['pages']));
     $this->assertTrue(isset($clone->cloningData['pages'][$child->getUid()]));
     $this->assertEquals($clone, $clone->cloningData['pages'][$child->getUid()]);
     $this->assertEquals(0, $clone->getRevisions()->count());
     $clone2 = clone $this->page;
     $this->assertNotEquals($this->page->getMainSection(), $clone2->getMainSection());
     $this->assertEquals($clone2->getSection(), $clone2->getMainSection());
     $this->assertEquals(0, $clone2->getPosition());
     $this->assertEquals(0, $clone2->getLevel());
 }