connectionPool = $connectionPool; } /** * @var OtPageRepository */ protected OtPageRepository $otPageRepository; public function injectOtPageRepository(OtPageRepository $otPageRepository) { $this->otPageRepository = $otPageRepository; } /** * Clear then repopulate the whole index */ public function indexAllRoutes() { $queryBuilder = $this->connectionPool->getQueryBuilderForTable('pages'); $rootPages = $queryBuilder ->select('uid') ->from('pages') ->where($queryBuilder->expr()->eq('is_siteroot', 1)) ->execute() ->fetchAll(); foreach ($rootPages as $rootPage) { $this->indexRoutesForWebsite($rootPage); } } /** * Clear and recreate the index entry for the target website * * @param int $rootUid */ public function indexRoutesForWebsite(int $rootUid) { foreach ($this->otPageRepository->getAllSitePages($rootUid) as $page) { $this->registerIndexEntry( $page['uid'], $page['tx_opentalent_structure_domain'], $page['slug'], $rootUid ); } } public function indexRouteForPage(int $pageUid) { $page = $this->otPageRepository->getPage($pageUid); $rootPage = $this->otPageRepository->getRootPageFor($pageUid); $this->registerIndexEntry( $page['uid'], $page['tx_opentalent_structure_domain'], $page['slug'], $rootPage['uid'] ); } private function registerIndexEntry(int $pageUid, string $domain, string $slug, ?int $rootUid = null) { $queryBuilder = $this->connectionPool->getQueryBuilderForTable(self::INDEX_TABLENAME); $queryBuilder ->delete(self::INDEX_TABLENAME) ->where($queryBuilder->expr()->eq('page_uid', $pageUid)) ->execute(); $entry = [ 'domain' => RouteNormalizer::normalizeDomain($domain), 'root_uid' => $rootUid, 'slug' => RouteNormalizer::normalizeSlug($slug), 'page_uid' => $pageUid, 'last_update' => date('Y-m-d H:i:s') ]; $queryBuilder = $this->connectionPool->getQueryBuilderForTable(self::INDEX_TABLENAME); $queryBuilder ->insert(self::INDEX_TABLENAME) ->values($entry) ->execute(); } }