17 use Doctrine\DBAL\Types\Types;
92 'published_versions' => [],
122 public function genTree($theID, $depthData =
'', $versions =
false)
124 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(
'pages');
125 $queryBuilder->getRestrictions()->removeAll();
126 if (!$this->genTreeIncludeDeleted) {
127 $queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
129 $queryBuilder->select(
'uid',
'title',
'doktype',
'deleted',
'hidden',
'sys_language_uid')
131 ->orderBy(
'sorting');
133 $queryBuilder->addSelect(
't3ver_wsid',
't3ver_id',
't3ver_count');
134 $queryBuilder->where(
135 $queryBuilder->expr()->eq(
'pid', $queryBuilder->createNamedParameter(-1, \PDO::PARAM_INT)),
136 $queryBuilder->expr()->eq(
't3ver_oid', $queryBuilder->createNamedParameter($theID, \PDO::PARAM_INT))
139 $queryBuilder->where(
140 $queryBuilder->expr()->eq(
'pid', $queryBuilder->createNamedParameter($theID, \PDO::PARAM_INT))
143 $result = $queryBuilder->execute();
145 while ($row = $result->fetch()) {
146 $newID = $row[
'uid'];
148 if ($row[
'sys_language_uid'] === 0) {
149 $this->pageIdArray[$newID] = $row;
151 $this->pageTranslatedPageIDArray[$newID] = $row;
153 $this->recStats[
'all_valid'][
'pages'][$newID] = $newID;
154 if ($row[
'deleted']) {
155 $this->recStats[
'deleted'][
'pages'][$newID] = $newID;
157 if ($versions && $row[
't3ver_count'] >= 1) {
158 $this->recStats[
'published_versions'][
'pages'][$newID] = $newID;
160 if ($row[
'deleted']) {
161 $this->recStats[
'deleted']++;
163 if ($row[
'hidden']) {
164 $this->recStats[
'hidden']++;
166 $this->recStats[
'doktype'][$row[
'doktype']]++;
168 if ($this->genTreeIncludeRecords) {
169 foreach (
$GLOBALS[
'TCA'] as $tableName => $cfg) {
170 if ($tableName !==
'pages') {
178 if ($this->genTreeIncludeVersions) {
190 public function genTree_records($theID, $_ =
'', $table =
'', $versions =
false): void
192 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
193 $queryBuilder->getRestrictions()->removeAll();
194 if (!$this->genTreeIncludeDeleted) {
195 $queryBuilder->getRestrictions()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
203 $queryBuilder->where(
204 $queryBuilder->expr()->eq(
'pid', $queryBuilder->createNamedParameter(-1, \PDO::PARAM_INT)),
205 $queryBuilder->expr()->eq(
't3ver_oid', $queryBuilder->createNamedParameter($theID, \PDO::PARAM_INT))
208 $queryBuilder->where(
209 $queryBuilder->expr()->eq(
'pid', $queryBuilder->createNamedParameter($theID, \PDO::PARAM_INT))
212 $queryResult = $queryBuilder->execute();
214 while ($row = $queryResult->fetch()) {
215 $newID = $row[
'uid'];
217 $this->recIdArray[$table][$newID] = $row;
218 $this->recStats[
'all_valid'][$table][$newID] = $newID;
219 if ($row[
'deleted']) {
220 $this->recStats[
'deleted'][$table][$newID] = $newID;
222 if ($versions && $row[
't3ver_count'] >= 1 && $row[
't3ver_wsid'] == 0) {
223 $this->recStats[
'published_versions'][$table][$newID] = $newID;
226 if ($this->genTreeIncludeVersions &&
$GLOBALS[
'TCA'][$table][
'ctrl'][
'versioningWS']) {
239 $this->lostPagesList =
'';
240 $pageIds = GeneralUtility::intExplode(
',', $pid_list);
241 if (is_array($pageIds)) {
242 foreach (
$GLOBALS[
'TCA'] as $table => $tableConf) {
243 $pageIdsForTable = $pageIds;
246 $pageIdsForTable = array_combine($pageIdsForTable, $pageIdsForTable);
247 unset($pageIdsForTable[-1]);
249 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
250 $queryBuilder->getRestrictions()->removeAll();
251 $selectFields = [
'uid',
'pid'];
252 if (!empty(
$GLOBALS[
'TCA'][$table][
'ctrl'][
'label'])) {
253 $selectFields[] =
$GLOBALS[
'TCA'][$table][
'ctrl'][
'label'];
255 $queryResult = $queryBuilder->select(...$selectFields)
258 $queryBuilder->expr()->notIn(
260 $queryBuilder->createNamedParameter($pageIdsForTable, Connection::PARAM_INT_ARRAY)
265 while ($row = $queryResult->fetch()) {
266 $this->lRecords[$table][$row[
'uid']] = [
267 'uid' => $row[
'uid'],
268 'pid' => $row[
'pid'],
271 $lostIdList[] = $row[
'uid'];
273 if ($table ===
'pages') {
274 $this->lostPagesList = implode(
',', $lostIdList);
290 if ($table &&
$GLOBALS[
'TCA'][$table] && $uid && is_array($this->lRecords[$table][$uid]) &&
$GLOBALS[
'BE_USER']->isAdmin()) {
295 if (
$GLOBALS[
'TCA'][$table][
'ctrl'][
'enablecolumns'][
'disabled']) {
296 $updateFields[
$GLOBALS[
'TCA'][$table][
'ctrl'][
'enablecolumns'][
'disabled']] = 1;
298 GeneralUtility::makeInstance(ConnectionPool::class)
299 ->getConnectionForTable($table)
300 ->update($table, $updateFields, [
'uid' => (
int)$uid]);
316 $pageIds = GeneralUtility::intExplode(
',', $pid_list);
317 if (!empty($pageIds)) {
318 foreach (
$GLOBALS[
'TCA'] as $table => $tableConf) {
319 $pageIdsForTable = $pageIds;
322 $pageIdsForTable = array_combine($pageIdsForTable, $pageIdsForTable);
323 unset($pageIdsForTable[-1]);
325 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
326 $queryBuilder->getRestrictions()->removeAll();
327 $count = $queryBuilder->count(
'uid')
330 $queryBuilder->expr()->in(
332 $queryBuilder->createNamedParameter($pageIds, Connection::PARAM_INT_ARRAY)
338 $list[$table] = $count;
342 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
343 $queryBuilder->getRestrictions()
345 ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
346 $count = $queryBuilder->count(
'uid')
349 $queryBuilder->expr()->in(
351 $queryBuilder->createNamedParameter($pageIdsForTable, Connection::PARAM_INT_ARRAY)
357 $list_n[$table] = $count;
361 return [
'all' => $list,
'non_deleted' => $list_n];
373 foreach (
$GLOBALS[
'TCA'] as $table => $tableConf) {
374 $cols =
$GLOBALS[
'TCA'][$table][
'columns'];
375 foreach ($cols as $field => $config) {
376 if ($config[
'config'][
'type'] ===
'group') {
377 if ((!$mode || $mode ===
'file') && $config[
'config'][
'internal_type'] ===
'file' || (!$mode || $mode ===
'db') && $config[
'config'][
'internal_type'] ===
'db') {
378 $result[$table][] = $field;
381 if ((!$mode || $mode ===
'db') && $config[
'config'][
'type'] ===
'select' && $config[
'config'][
'foreign_table']) {
382 $result[$table][] = $field;
385 if ($result[$table]) {
386 $result[$table] = implode(
',', $result[$table]);
401 foreach (
$GLOBALS[
'TCA'] as $table => $tableConf) {
402 $cols =
$GLOBALS[
'TCA'][$table][
'columns'];
403 foreach ($cols as $field => $config) {
404 if ($config[
'config'][
'type'] ===
'group' && $config[
'config'][
'internal_type'] ===
'file' && $config[
'config'][
'uploadfolder'] == $uploadfolder) {
405 $result[] = [$table, $field];
421 foreach (
$GLOBALS[
'TCA'] as $table => $tableConf) {
422 $cols =
$GLOBALS[
'TCA'][$table][
'columns'];
423 foreach ($cols as $field => $config) {
424 if ($config[
'config'][
'type'] ===
'group' && $config[
'config'][
'internal_type'] ===
'db') {
425 if (trim($config[
'config'][
'allowed']) ===
'*' || strstr($config[
'config'][
'allowed'], $theSearchTable)) {
426 $result[] = [$table, $field];
428 } elseif ($config[
'config'][
'type'] ===
'select' && $config[
'config'][
'foreign_table'] == $theSearchTable) {
429 $result[] = [$table, $field];
444 if (is_array($fkey_arrays)) {
445 $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
446 foreach ($fkey_arrays as $table => $field_list) {
447 if (
$GLOBALS[
'TCA'][$table] && trim($field_list)) {
448 $connection = $connectionPool->getConnectionForTable($table);
449 $schemaManager = $connection->getSchemaManager();
450 $tableColumns = $schemaManager->listTableColumns($table);
452 $queryBuilder = $connectionPool->getQueryBuilderForTable($table);
453 $queryBuilder->getRestrictions()->removeAll();
455 $fields = GeneralUtility::trimExplode(
',', $field_list,
true);
457 $queryBuilder->select(
'uid')
464 $column = $tableColumns[strtolower($fieldName)]
465 ?? $tableColumns[$connection->quoteIdentifier(strtolower($fieldName))];
469 throw new \RuntimeException(
470 'Field ' . $fieldName .
' for table ' . $table .
' has been defined in TCA, but does not exist in DB',
474 $fieldType = $column->getType()->getName();
477 [Types::BIGINT, Types::INTEGER, Types::SMALLINT, Types::DECIMAL, Types::FLOAT],
480 $whereClause[] = $queryBuilder->expr()->andX(
481 $queryBuilder->expr()->isNotNull($fieldName),
482 $queryBuilder->expr()->neq(
484 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
487 } elseif (in_array($fieldType, [Types::STRING, Types::TEXT],
true)) {
488 $whereClause[] = $queryBuilder->expr()->andX(
489 $queryBuilder->expr()->isNotNull($fieldName),
490 $queryBuilder->expr()->neq(
492 $queryBuilder->createNamedParameter(
'', \PDO::PARAM_STR)
495 } elseif ($fieldType === Types::BLOB) {
496 $whereClause[] = $queryBuilder->expr()->andX(
497 $queryBuilder->expr()->isNotNull($fieldName),
498 $queryBuilder->expr()
500 $queryBuilder->expr()->length($fieldName),
502 $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
507 $queryResult = $queryBuilder->orWhere(...$whereClause)->execute();
509 while ($row = $queryResult->fetch()) {
511 if (trim($row[$field])) {
512 $fieldConf =
$GLOBALS[
'TCA'][$table][
'columns'][$field][
'config'];
513 if ($fieldConf[
'type'] ===
'group') {
514 if ($fieldConf[
'internal_type'] ===
'file') {
516 if ($fieldConf[
'MM']) {
518 $dbAnalysis = GeneralUtility::makeInstance(RelationHandler::class);
519 $dbAnalysis->start(
'',
'files', $fieldConf[
'MM'], $row[
'uid']);
520 foreach ($dbAnalysis->itemArray as $somekey => $someval) {
521 if ($someval[
'id']) {
522 $tempArr[] = $someval[
'id'];
526 $tempArr = explode(
',', trim($row[$field]));
528 foreach ($tempArr as $file) {
531 $this->checkFileRefs[$fieldConf[
'uploadfolder']][$file] += 1;
535 if ($fieldConf[
'internal_type'] ===
'db') {
536 $dbAnalysis = GeneralUtility::makeInstance(RelationHandler::class);
539 $fieldConf[
'allowed'],
545 foreach ($dbAnalysis->itemArray as $tempArr) {
546 $this->checkGroupDBRefs[$tempArr[
'table']][$tempArr[
'id']] += 1;
550 if ($fieldConf[
'type'] ===
'select' && $fieldConf[
'foreign_table']) {
551 $dbAnalysis = GeneralUtility::makeInstance(RelationHandler::class);
554 $fieldConf[
'foreign_table'],
560 foreach ($dbAnalysis->itemArray as $tempArr) {
561 if ($tempArr[
'id'] > 0) {
562 $this->checkGroupDBRefs[$fieldConf[
'foreign_table']][$tempArr[
'id']] += 1;
583 $newCheckFileRefs = [];
584 foreach ($this->checkFileRefs as $folder => $files) {
586 if ($folder !==
'') {
587 $newCheckFileRefs[$folder] = $files;
590 foreach ($files as $file => $references) {
592 if ($references > 1) {
597 if ($directory !==
'') {
602 $this->checkFileRefs = $newCheckFileRefs;
603 foreach ($this->checkFileRefs as $folder => $fileArr) {
605 if (@is_dir($path) && @is_readable($path)) {
607 while ($entry = $d->read()) {
608 if (@is_file($path .
'/' . $entry)) {
609 if (isset($fileArr[$entry])) {
610 if ($fileArr[$entry] > 1) {
613 foreach ($temp as $inf) {
614 $tempList .=
'[' . $inf[
'table'] .
'][' . $inf[
'uid'] .
'][' . $inf[
'field'] .
'] (pid:' . $inf[
'pid'] .
') - ';
616 $output[
'moreReferences'][] = [$path, $entry, $fileArr[$entry], $tempList];
618 unset($fileArr[$entry]);
621 if (!strstr($entry,
'index.htm') && !preg_match(
'/^' . preg_quote(
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'fileadminDir'],
'/') .
'/', $folder)) {
622 $output[
'noReferences'][] = [$path, $entry];
629 foreach ($fileArr as $file => $value) {
631 if (preg_match(
'/^' . preg_quote(
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'fileadminDir'],
'/') .
'/', $folder)) {
632 $file = $folder .
'/' . $file;
638 foreach ($temp as $inf) {
639 $tempList .=
'[' . $inf[
'table'] .
'][' . $inf[
'uid'] .
'][' . $inf[
'field'] .
'] (pid:' . $inf[
'pid'] .
') - ';
642 $output[
'noFile'][substr($path, -3) .
'_' . substr($file, 0, 3) .
'_' . $tempCounter] = [$path, $file, $tempList];
660 foreach ($theArray as $table => $dbArr) {
662 $ids = array_keys($dbArr);
664 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
665 ->getQueryBuilderForTable($table);
666 $queryBuilder->getRestrictions()
668 ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
669 $queryResult = $queryBuilder
673 $queryBuilder->expr()->in(
675 $queryBuilder->createNamedParameter($ids, Connection::PARAM_INT_ARRAY)
679 while ($row = $queryResult->fetch()) {
680 if (isset($dbArr[$row[
'uid']])) {
681 unset($dbArr[$row[
'uid']]);
683 $result .=
'Strange Error. ...<br />';
686 foreach ($dbArr as $theId => $theC) {
687 $result .=
'There are ' . $theC .
' records pointing to this missing or deleted record; [' . $table .
'][' . $theId .
']<br />';
691 $result .=
'Codeerror. Table is not a table...<br />';
709 foreach ($fileFields as $info) {
710 list($table, $field) = $info;
711 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
712 $queryBuilder->getRestrictions()->removeAll();
713 $queryResult = $queryBuilder
714 ->select(
'uid',
'pid',
$GLOBALS[
'TCA'][$table][
'ctrl'][
'label'], $field)
717 $queryBuilder->expr()->like(
719 $queryBuilder->createNamedParameter(
'%' . $queryBuilder->escapeLikeWildcards($id) .
'%')
724 while ($row = $queryResult->fetch()) {
727 $fieldConf =
$GLOBALS[
'TCA'][$table][
'columns'][$field][
'config'];
728 $allowedTables = $fieldConf[
'type'] ===
'group' ? $fieldConf[
'allowed'] : $fieldConf[
'foreign_table'];
729 $dbAnalysis = GeneralUtility::makeInstance(RelationHandler::class);
730 $dbAnalysis->start($row[$field], $allowedTables, $fieldConf[
'MM'], $row[
'uid'], $table, $fieldConf);
731 foreach ($dbAnalysis->itemArray as $tempArr) {
732 if ($tempArr[
'table'] == $searchTable && $tempArr[
'id'] == $id) {
735 'uid' => $row[
'uid'],
743 return $theRecordList;
758 foreach ($fileFields as $info) {
759 list($table, $field) = $info;
760 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
761 $queryBuilder->getRestrictions()->removeAll();
762 $queryResult = $queryBuilder
763 ->select(
'uid',
'pid',
$GLOBALS[
'TCA'][$table][
'ctrl'][
'label'], $field)
766 $queryBuilder->expr()->like(
768 $queryBuilder->createNamedParameter(
'%' . $queryBuilder->escapeLikeWildcards($filename) .
'%')
772 while ($row = $queryResult->fetch()) {
775 $tempArr = explode(
',', trim($row[$field]));
776 foreach ($tempArr as $file) {
778 if ($file == $filename) {
781 'uid' => $row[
'uid'],
789 return $theRecordList;