2 namespace TYPO3\CMS\Core\Integrity;
78 'allValid' => array(),
79 'published_versions' => array(),
102 public function genTree($theID, $depthData =
'', $versions =
false)
105 $res =
$GLOBALS[
'TYPO3_DB']->exec_SELECTquery(
'uid,title,doktype,deleted,t3ver_wsid,t3ver_id,t3ver_count,hidden',
'pages',
'pid=-1 AND t3ver_oid=' . (
int)$theID .
' ' . (!$this->genTree_includeDeleted ?
'AND deleted=0' :
'') . $this->perms_clause,
'',
'sorting');
107 $res =
$GLOBALS[
'TYPO3_DB']->exec_SELECTquery(
'uid,title,doktype,deleted,hidden',
'pages',
'pid=' . (
int)$theID .
' ' . (!$this->genTree_includeDeleted ?
'AND deleted=0' :
'') . $this->perms_clause,
'',
'sorting');
111 while ($row =
$GLOBALS[
'TYPO3_DB']->sql_fetch_assoc($res)) {
113 $newID = $row[
'uid'];
115 $this->page_idArray[$newID] = $row;
116 $this->recStats[
'all_valid'][
'pages'][$newID] = $newID;
117 if ($row[
'deleted']) {
118 $this->recStats[
'deleted'][
'pages'][$newID] = $newID;
120 if ($versions && $row[
't3ver_count'] >= 1) {
121 $this->recStats[
'published_versions'][
'pages'][$newID] = $newID;
123 if ($row[
'deleted']) {
124 $this->recStats[
'deleted']++;
126 if ($row[
'hidden']) {
127 $this->recStats[
'hidden']++;
129 $this->recStats[
'doktype'][$row[
'doktype']]++;
131 if ($this->genTree_includeRecords) {
132 foreach (
$GLOBALS[
'TCA'] as $tableName => $cfg) {
133 if ($tableName !=
'pages') {
141 if ($this->genTree_includeVersions) {
142 $this->
genTree($newID,
'',
true);
145 $GLOBALS[
'TYPO3_DB']->sql_free_result($res);
159 $res =
$GLOBALS[
'TYPO3_DB']->exec_SELECTquery(
166 $res =
$GLOBALS[
'TYPO3_DB']->exec_SELECTquery(
174 while ($row =
$GLOBALS[
'TYPO3_DB']->sql_fetch_assoc($res)) {
176 $newID = $row[
'uid'];
178 $this->rec_idArray[$table][$newID] = $row;
179 $this->recStats[
'all_valid'][$table][$newID] = $newID;
180 if ($row[
'deleted']) {
181 $this->recStats[
'deleted'][$table][$newID] = $newID;
183 if ($versions && $row[
't3ver_count'] >= 1 && $row[
't3ver_wsid'] == 0) {
184 $this->recStats[
'published_versions'][$table][$newID] = $newID;
187 if ($this->genTree_includeVersions &&
$GLOBALS[
'TCA'][$table][
'ctrl'][
'versioningWS']) {
191 $GLOBALS[
'TYPO3_DB']->sql_free_result($res);
202 $this->lostPagesList =
'';
204 foreach (
$GLOBALS[
'TCA'] as $table => $tableConf) {
205 $pid_list_tmp = $pid_list;
206 if (!isset(
$GLOBALS[
'TCA'][$table][
'ctrl'][
'versioningWS']) || !
$GLOBALS[
'TCA'][$table][
'ctrl'][
'versioningWS']) {
208 $pid_list_tmp = preg_replace(
'/^\\-1,/',
'', $pid_list_tmp);
210 $garbage =
$GLOBALS[
'TYPO3_DB']->exec_SELECTquery(
'uid,pid,' .
$GLOBALS[
'TCA'][$table][
'ctrl'][
'label'], $table,
'pid NOT IN (' . $pid_list_tmp .
')');
211 $lostIdList = array();
212 while ($row =
$GLOBALS[
'TYPO3_DB']->sql_fetch_assoc($garbage)) {
213 $this->lRecords[$table][$row[
'uid']] = array(
214 'uid' => $row[
'uid'],
215 'pid' => $row[
'pid'],
218 $lostIdList[] = $row[
'uid'];
220 $GLOBALS[
'TYPO3_DB']->sql_free_result($garbage);
221 if ($table ==
'pages') {
222 $this->lostPagesList = implode(
',', $lostIdList);
238 if ($table &&
$GLOBALS[
'TCA'][$table] && $uid && is_array($this->lRecords[$table][$uid]) &&
$GLOBALS[
'BE_USER']->user[
'admin']) {
239 $updateFields = array();
240 $updateFields[
'pid'] = 0;
242 if (
$GLOBALS[
'TCA'][$table][
'ctrl'][
'enablecolumns'][
'disabled']) {
243 $updateFields[
$GLOBALS[
'TCA'][$table][
'ctrl'][
'enablecolumns'][
'disabled']] = 1;
245 $GLOBALS[
'TYPO3_DB']->exec_UPDATEquery($table,
'uid=' . (
int)$uid, $updateFields);
263 foreach (
$GLOBALS[
'TCA'] as $table => $tableConf) {
264 $pid_list_tmp = $pid_list;
265 if (!isset(
$GLOBALS[
'TCA'][$table][
'ctrl'][
'versioningWS']) || !
$GLOBALS[
'TCA'][$table][
'ctrl'][
'versioningWS']) {
267 $pid_list_tmp = preg_replace(
'/^\\-1,/',
'', $pid_list_tmp);
269 $count =
$GLOBALS[
'TYPO3_DB']->exec_SELECTcountRows(
'uid', $table,
'pid IN (' . $pid_list_tmp .
')');
271 $list[$table] = $count;
275 $list_n[$table] = $count;
279 return array(
'all' =>
$list,
'non_deleted' => $list_n);
291 foreach (
$GLOBALS[
'TCA'] as $table => $tableConf) {
292 $cols =
$GLOBALS[
'TCA'][$table][
'columns'];
293 foreach ($cols as $field => $config) {
294 if ($config[
'config'][
'type'] ==
'group') {
295 if ((!$mode || $mode ==
'file') && $config[
'config'][
'internal_type'] ==
'file' || (!$mode || $mode ==
'db') && $config[
'config'][
'internal_type'] ==
'db') {
296 $result[$table][] = $field;
299 if ((!$mode || $mode ==
'db') && $config[
'config'][
'type'] ==
'select' && $config[
'config'][
'foreign_table']) {
300 $result[$table][] = $field;
303 if ($result[$table]) {
304 $result[$table] = implode(
',', $result[$table]);
319 foreach (
$GLOBALS[
'TCA'] as $table => $tableConf) {
320 $cols =
$GLOBALS[
'TCA'][$table][
'columns'];
321 foreach ($cols as $field => $config) {
322 if ($config[
'config'][
'type'] ==
'group' && $config[
'config'][
'internal_type'] ==
'file' && $config[
'config'][
'uploadfolder'] == $uploadfolder) {
323 $result[] = array($table, $field);
339 foreach (
$GLOBALS[
'TCA'] as $table => $tableConf) {
340 $cols =
$GLOBALS[
'TCA'][$table][
'columns'];
341 foreach ($cols as $field => $config) {
342 if ($config[
'config'][
'type'] ==
'group' && $config[
'config'][
'internal_type'] ==
'db') {
343 if (trim($config[
'config'][
'allowed']) ==
'*' || strstr($config[
'config'][
'allowed'], $theSearchTable)) {
344 $result[] = array($table, $field);
346 }
elseif ($config[
'config'][
'type'] ==
'select' && $config[
'config'][
'foreign_table'] == $theSearchTable) {
347 $result[] = array($table, $field);
361 public function selectNonEmptyRecordsWithFkeys($fkey_arrays)
363 if (is_array($fkey_arrays)) {
364 foreach ($fkey_arrays as $table => $field_list) {
365 if (
$GLOBALS[
'TCA'][$table] && trim($field_list)) {
366 $fieldArr = explode(
',', $field_list);
367 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded(
'dbal')) {
368 $fields =
$GLOBALS[
'TYPO3_DB']->admin_get_fields($table);
369 $field = array_shift($fieldArr);
370 $cl_fl =
$GLOBALS[
'TYPO3_DB']->MetaType($fields[$field][
'type'], $table) ==
'I' ||
$GLOBALS[
'TYPO3_DB']->MetaType($fields[$field][
'type'], $table) ==
'N' ||
$GLOBALS[
'TYPO3_DB']->MetaType($fields[$field][
'type'], $table) ==
'R' ? $field .
'<>0' : $field .
'<>\'\'';
371 foreach ($fieldArr as $field) {
372 $cl_fl .=
$GLOBALS[
'TYPO3_DB']->MetaType($fields[$field][
'type'], $table) ==
'I' ||
$GLOBALS[
'TYPO3_DB']->MetaType($fields[$field][
'type'], $table) ==
'N' ||
$GLOBALS[
'TYPO3_DB']->MetaType($fields[$field][
'type'], $table) ==
'R' ?
' OR ' . $field .
'<>0' :
' OR ' . $field .
'<>\'\'';
376 $cl_fl = implode(
'<>\'\' OR ', $fieldArr) .
'<>\'\'';
378 $mres =
$GLOBALS[
'TYPO3_DB']->exec_SELECTquery(
'uid,' . $field_list, $table, $cl_fl);
379 while ($row =
$GLOBALS[
'TYPO3_DB']->sql_fetch_assoc($mres)) {
380 foreach ($fieldArr as $field) {
381 if (trim($row[$field])) {
382 $fieldConf =
$GLOBALS[
'TCA'][$table][
'columns'][$field][
'config'];
383 if ($fieldConf[
'type'] ==
'group') {
384 if ($fieldConf[
'internal_type'] ==
'file') {
386 if ($fieldConf[
'MM']) {
389 $dbAnalysis = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\RelationHandler::class);
390 $dbAnalysis->start(
'',
'files', $fieldConf[
'MM'], $row[
'uid']);
391 foreach ($dbAnalysis->itemArray as $somekey => $someval) {
392 if ($someval[
'id']) {
393 $tempArr[] = $someval[
'id'];
397 $tempArr = explode(
',', trim($row[$field]));
399 foreach ($tempArr as $file) {
402 $this->checkFileRefs[$fieldConf[
'uploadfolder']][$file] += 1;
406 if ($fieldConf[
'internal_type'] ==
'db') {
408 $dbAnalysis = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\RelationHandler::class);
409 $dbAnalysis->start($row[$field], $fieldConf[
'allowed'], $fieldConf[
'MM'], $row[
'uid'], $table, $fieldConf);
410 foreach ($dbAnalysis->itemArray as $tempArr) {
411 $this->checkGroupDBRefs[$tempArr[
'table']][$tempArr[
'id']] += 1;
415 if ($fieldConf[
'type'] ==
'select' && $fieldConf[
'foreign_table']) {
417 $dbAnalysis = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\RelationHandler::class);
418 $dbAnalysis->start($row[$field], $fieldConf[
'foreign_table'], $fieldConf[
'MM'], $row[
'uid'], $table, $fieldConf);
419 foreach ($dbAnalysis->itemArray as $tempArr) {
420 if ($tempArr[
'id'] > 0) {
421 $this->checkGroupDBRefs[$fieldConf[
'foreign_table']][$tempArr[
'id']] += 1;
428 $GLOBALS[
'TYPO3_DB']->sql_free_result($mres);
443 $newCheckFileRefs = array();
444 foreach ($this->checkFileRefs as $folder => $files) {
446 if ($folder !==
'') {
447 $newCheckFileRefs[$folder] = $files;
450 foreach ($files as $file => $references) {
452 if ($references > 1) {
456 $directory = dirname($file);
457 if ($directory !==
'') {
458 $newCheckFileRefs[$directory][basename($file)] = $references;
462 $this->checkFileRefs = $newCheckFileRefs;
463 foreach ($this->checkFileRefs as $folder => $fileArr) {
464 $path = PATH_site . $folder;
465 if (@is_dir($path) && @is_readable($path)) {
467 while ($entry = $d->read()) {
468 if (@is_file(($path .
'/' . $entry))) {
469 if (isset($fileArr[$entry])) {
470 if ($fileArr[$entry] > 1) {
473 foreach ($temp as $inf) {
474 $tempList .=
'[' . $inf[
'table'] .
'][' . $inf[
'uid'] .
'][' . $inf[
'field'] .
'] (pid:' . $inf[
'pid'] .
') - ';
476 $output[
'moreReferences'][] = array($path, $entry, $fileArr[$entry], $tempList);
478 unset($fileArr[$entry]);
481 if (!strstr($entry,
'index.htm') && !preg_match((
'/^' . preg_quote(
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'fileadminDir'],
'/') .
'/'), $folder)) {
482 $output[
'noReferences'][] = array($path, $entry);
489 foreach ($fileArr as $file => $value) {
491 if (preg_match(
'/^' . preg_quote(
$GLOBALS[
'TYPO3_CONF_VARS'][
'BE'][
'fileadminDir'],
'/') .
'/', $folder)) {
492 $file = $folder .
'/' . $file;
494 $path = substr(PATH_site, 0, -1);
498 foreach ($temp as $inf) {
499 $tempList .=
'[' . $inf[
'table'] .
'][' . $inf[
'uid'] .
'][' . $inf[
'field'] .
'] (pid:' . $inf[
'pid'] .
') - ';
502 $output[
'noFile'][substr($path, -3) .
'_' . substr($file, 0, 3) .
'_' . $tempCounter] = array($path, $file, $tempList);
505 $output[
'error'][] = array($path);
520 foreach ($theArray as $table => $dbArr) {
522 $idlist = array_keys($dbArr);
523 $theList = implode(
',', $idlist);
526 while ($row =
$GLOBALS[
'TYPO3_DB']->sql_fetch_assoc($mres)) {
527 if (isset($dbArr[$row[
'uid']])) {
528 unset($dbArr[$row[
'uid']]);
530 $result .=
'Strange Error. ...<br />';
533 $GLOBALS[
'TYPO3_DB']->sql_free_result($mres);
534 foreach ($dbArr as $theId => $theC) {
535 $result .=
'There are ' . $theC .
' records pointing to this missing or deleted record; [' . $table .
'][' . $theId .
']<br />';
539 $result .=
'Codeerror. Table is not a table...<br />';
552 public function whereIsRecordReferenced($searchTable, $id)
556 $theRecordList = array();
557 foreach ($fileFields as $info) {
560 $mres =
$GLOBALS[
'TYPO3_DB']->exec_SELECTquery(
'uid,pid,' .
$GLOBALS[
'TCA'][$table][
'ctrl'][
'label'] .
',' . $field, $table, $field .
' LIKE \'%' .
$GLOBALS[
'TYPO3_DB']->quoteStr($id, $table) .
'%\'');
561 while ($row =
$GLOBALS[
'TYPO3_DB']->sql_fetch_assoc($mres)) {
563 $fieldConf =
$GLOBALS[
'TCA'][$table][
'columns'][$field][
'config'];
564 $allowedTables = $fieldConf[
'type'] ==
'group' ? $fieldConf[
'allowed'] : $fieldConf[
'foreign_table'];
566 $dbAnalysis = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\RelationHandler::class);
567 $dbAnalysis->start($row[$field], $allowedTables, $fieldConf[
'MM'], $row[
'uid'], $table, $fieldConf);
568 foreach ($dbAnalysis->itemArray as $tempArr) {
569 if ($tempArr[
'table'] == $searchTable && $tempArr[
'id'] == $id) {
570 $theRecordList[] = array(
'table' => $table,
'uid' => $row[
'uid'],
'field' => $field,
'pid' => $row[
'pid']);
574 $GLOBALS[
'TYPO3_DB']->sql_free_result($mres);
576 return $theRecordList;
590 $theRecordList = array();
591 foreach ($fileFields as $info) {
594 $mres =
$GLOBALS[
'TYPO3_DB']->exec_SELECTquery(
'uid,pid,' .
$GLOBALS[
'TCA'][$table][
'ctrl'][
'label'] .
',' . $field, $table, $field .
' LIKE \'%' .
$GLOBALS[
'TYPO3_DB']->quoteStr(
$filename, $table) .
'%\'');
595 while ($row =
$GLOBALS[
'TYPO3_DB']->sql_fetch_assoc($mres)) {
598 $tempArr = explode(
',', trim($row[$field]));
599 foreach ($tempArr as $file) {
602 $theRecordList[] = array(
'table' => $table,
'uid' => $row[
'uid'],
'field' => $field,
'pid' => $row[
'pid']);
606 $GLOBALS[
'TYPO3_DB']->sql_free_result($mres);
608 return $theRecordList;