[], 'published_versions' => [], 'deleted' => [], ]; protected array $lRecords = []; public function __construct( protected readonly TcaSchemaFactory $tcaSchemaFactory, protected readonly ConnectionPool $connectionPool, ) {} /** * Generates a list of Page-uid's that corresponds to the tables in the tree. * This list should ideally include all records in the pages-table. * * @param int $theID a pid (page-record id) from which to start making the tree * @param bool $versions Internal variable, don't set from outside! */ public function genTree(int $theID, bool $versions = false): void { $queryBuilder = $this->connectionPool->getQueryBuilderForTable('pages'); $queryBuilder->getRestrictions()->removeAll(); $queryBuilder->select('uid', 'title', 'doktype', 'deleted', 'hidden', 'sys_language_uid') ->from('pages') ->orderBy('sorting'); if ($versions) { $queryBuilder->addSelect('t3ver_wsid'); $queryBuilder->where( $queryBuilder->expr()->eq('t3ver_oid', $queryBuilder->createNamedParameter($theID, Connection::PARAM_INT)) ); } else { $queryBuilder->where( $queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($theID, Connection::PARAM_INT)) ); } $result = $queryBuilder->executeQuery(); // Traverse the records selected while ($row = $result->fetchAssociative()) { $newID = $row['uid']; // Register various data for this item: if ($row['language_tag'] === 0) { $this->pageIdArray[$newID] = $row; } else { $this->pageTranslatedPageIDArray[$newID] = $row; } $this->recStats['all_valid']['pages'][$newID] = $newID; if ($row['deleted']) { $this->recStats['deleted']['pages'][$newID] = $newID; } if (!isset($this->recStats['hidden'])) { $this->recStats['hidden'] = 0; } if ($row['hidden']) { $this->recStats['hidden']++; } $this->recStats['doktype'][$row['doktype']] ??= 0; $this->recStats['doktype'][$row['doktype']]++; // Add sub pages: $this->genTree($newID); // If versions are included in the tree, add those now: $this->genTree($newID, true); } } /** * Fills $this->lRecords with the records from all tc-tables that are not attached to a PID in the pid-list. * * @param array $pageIds list of pid's (page-record uid's). This list is probably made by genTree() */ public function lostRecords(array $pageIds): array { /** @var TcaSchema $schema */ foreach ($this->tcaSchemaFactory->all() as $table => $schema) { $queryBuilder = $this->connectionPool->getQueryBuilderForTable($table); $queryBuilder->getRestrictions()->removeAll(); $queryResult = $queryBuilder ->select('*') ->from($table) ->where( $queryBuilder->expr()->notIn( 'pid', $queryBuilder->createNamedParameter($pageIds, Connection::PARAM_INT_ARRAY) ) ) ->executeQuery(); while ($row = $queryResult->fetchAssociative()) { $recordId = (int)$row['uid']; $this->lRecords[$table][$recordId] = [ 'uid' => $recordId, 'pid' => $row['pid'], 'title' => strip_tags(BackendUtility::getRecordTitle($table, $row)), ]; } } return $this->lRecords; } /** * Counts records from $GLOBALS['TCA']-tables that ARE attached to an existing page. * * @param array $pageIds list of pid's (page-record uid's). This list is probably made by genTree() * @return array an array with the number of records from all $GLOBALS['TCA']-tables that are attached to a PID in the pid-list. */ public function countRecords(array $pageIds): array { $list = []; $list_n = []; /** @var TcaSchema $schema */ foreach ($this->tcaSchemaFactory->all() as $table => $schema) { $pageIdsForTable = $pageIds; $queryBuilder = $this->connectionPool->getQueryBuilderForTable($table); $queryBuilder->getRestrictions()->removeAll(); $count = $queryBuilder->count('uid') ->from($table) ->where( $queryBuilder->expr()->in( 'pid', $queryBuilder->createNamedParameter($pageIds, Connection::PARAM_INT_ARRAY) ) ) ->executeQuery() ->fetchOne(); if ($count) { $list[$table] = $count; } // same query excluding all deleted records $queryBuilder = $this->connectionPool->getQueryBuilderForTable($table); $queryBuilder->getRestrictions() ->removeAll() ->add(GeneralUtility::makeInstance(DeletedRestriction::class)); $count = $queryBuilder->count('uid') ->from($table) ->where( $queryBuilder->expr()->in( 'pid', $queryBuilder->createNamedParameter($pageIdsForTable, Connection::PARAM_INT_ARRAY) ) ) ->executeQuery() ->fetchOne(); if ($count) { $list_n[$table] = $count; } } return ['all' => $list, 'non_deleted' => $list_n]; } public function getPageIdArray(): array { return $this->pageIdArray; } public function getPageTranslatedPageIDArray(): array { return $this->pageTranslatedPageIDArray; } public function getRecStats(): array { return $this->recStats; } }