/** * Checks for the uniqueness of the URL and postfixe it if need. * * @param \BackBee\CoreDomain\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\\CoreDomain\\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 bb_page p LEFT JOIN bb_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); }