/** * Checks if a whole branch of pages exists * * Tests the branch under $pid (like doesRecordExist). It doesn't test the page with $pid as uid. Use doesRecordExist() for this purpose * Returns an ID-list or "" if OK. Else -1 which means that somewhere there was no permission (eg. to delete). * if $recurse is set, then the function will follow subpages. This MUST be set, if we need the idlist for deleting pages or else we get an incomplete list * * @param string $inList List of page uids, this is added to and outputted in the end * @param int $pid Page ID to select subpages from. * @param int $perms Perms integer to check each page record for. * @param bool $recurse Recursion flag: If set, it will go out through the branch. * @return string List of integers in branch */ public function doesBranchExist($inList, $pid, $perms, $recurse) { $pid = (int) $pid; $perms = (int) $perms; if ($pid >= 0) { $mres = $this->databaseConnection->exec_SELECTquery('uid, perms_userid, perms_groupid, perms_user, perms_group, perms_everybody', 'pages', 'pid=' . (int) $pid . $this->deleteClause('pages'), '', 'sorting'); while ($row = $this->databaseConnection->sql_fetch_assoc($mres)) { // IF admin, then it's OK if ($this->admin || $this->BE_USER->doesUserHaveAccess($row, $perms)) { $inList .= $row['uid'] . ','; if ($recurse) { // Follow the subpages recursively... $inList = $this->doesBranchExist($inList, $row['uid'], $perms, $recurse); if ($inList == -1) { return -1; } } } else { // No permissions return -1; } } $this->databaseConnection->sql_free_result($mres); } return $inList; }
/** * Checks if a whole branch of pages exists * * Tests the branch under $pid (like doesRecordExist). It doesn't test the page with $pid as uid. Use doesRecordExist() for this purpose * Returns an ID-list or "" if OK. Else -1 which means that somewhere there was no permission (eg. to delete). * if $recurse is set, then the function will follow subpages. This MUST be set, if we need the idlist for deleting pages or else we get an incomplete list * * @param string $inList List of page uids, this is added to and outputted in the end * @param int $pid Page ID to select subpages from. * @param int $perms Perms integer to check each page record for. * @param bool $recurse Recursion flag: If set, it will go out through the branch. * @return string List of integers in branch */ public function doesBranchExist($inList, $pid, $perms, $recurse) { $pid = (int) $pid; $perms = (int) $perms; if ($pid >= 0) { $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages'); $this->addDeleteRestriction($queryBuilder->getRestrictions()->removeAll()); $result = $queryBuilder->select('uid', 'perms_userid', 'perms_groupid', 'perms_user', 'perms_group', 'perms_everybody')->from('pages')->where($queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pid, \PDO::PARAM_INT)))->orderBy('sorting')->execute(); while ($row = $result->fetch()) { // IF admin, then it's OK if ($this->admin || $this->BE_USER->doesUserHaveAccess($row, $perms)) { $inList .= $row['uid'] . ','; if ($recurse) { // Follow the subpages recursively... $inList = $this->doesBranchExist($inList, $row['uid'], $perms, $recurse); if ($inList == -1) { return -1; } } } else { // No permissions return -1; } } } return $inList; }