35 parent::__construct();
37 $this->
cli_help[
'name'] =
'missing_relations -- Find all record references pointing to a non-existing record.';
38 $this->
cli_help[
'description'] = trim(
' 40 - a perfect integrity of the reference index table (always update the reference index table before using this tool!) 41 - all database references to check are integers greater than zero 42 - does not check if a referenced record is inside an offline branch, another workspace etc. which could make the reference useless in reality or otherwise question integrity 43 Records may be missing for these reasons (except software bugs): 44 - someone deleted the record which is technically not an error although it might be a mistake that someone did so. 45 - after flushing published versions and/or deleted-flagged records a number of new missing references might appear; those were pointing to records just flushed. 47 Automatic Repair of Errors: 48 - Only managed references are repaired (TCA-configured). 49 - Offline Version Records and Non Existing Records: Reference is removed 51 Manual repair suggestions: 52 - For soft references you should investigate each case and edit the content accordingly. 53 - References to deleted records can theoretically be removed since a deleted record cannot be selected and hence your website should not be affected by removal of the reference. On the other hand it does not hurt to ignore it for now. To have this automatically fixed you must first flush the deleted records after which remaining references will appear as pointing to Non Existing Records and can now be removed with the automatic fix. 55 NOTICE: Uses the Reference Index Table (sys_refindex) for analysis. Update it before use! 57 $this->
cli_help[
'examples'] =
'/.../cli_dispatch.phpsh lowlevel_cleaner missing_relations -s -r 58 Reports missing relations';
72 $listExplain =
' Shows the missing record as header and underneath a list of record fields in which the references are found. ' .
$this->label_infoString;
74 'message' => $this->
cli_help[
'name'] . LF . LF . $this->
cli_help[
'description'],
76 'offlineVersionRecords_m' => array(
'Offline version records (managed)',
'These records are offline versions having a pid=-1 and references should never occur directly to their uids.' . $listExplain, 3),
77 'deletedRecords_m' => array(
'Deleted-flagged records (managed)',
'These records are deleted with a flag but references are still pointing at them. Keeping the references is useful if you undelete the referenced records later, otherwise the references are lost completely when the deleted records are flushed at some point. Notice that if those records listed are themselves deleted (marked with "DELETED") it is not a problem.' . $listExplain, 2),
78 'nonExistingRecords_m' => array(
'Non-existing records to which there are references (managed)',
'These references can safely be removed since there is no record found in the database at all.' . $listExplain, 3),
80 'offlineVersionRecords_s' => array(
'Offline version records (softref)',
'See above.' . $listExplain, 2),
81 'deletedRecords_s' => array(
'Deleted-flagged records (softref)',
'See above.' . $listExplain, 2),
82 'nonExistingRecords_s' => array(
'Non-existing records to which there are references (softref)',
'See above.' . $listExplain, 2)
84 'offlineVersionRecords_m' => array(),
85 'deletedRecords_m' => array(),
86 'nonExistingRecords_m' => array(),
87 'offlineVersionRecords_s' => array(),
88 'deletedRecords_s' => array(),
89 'nonExistingRecords_s' => array()
92 $recs = $TYPO3_DB->exec_SELECTgetRows(
'*',
'sys_refindex',
'ref_table<>' . $TYPO3_DB->fullQuoteStr(
'_FILE',
'sys_refindex') .
' AND ref_uid>0' . $filterClause,
'',
'sorting DESC');
94 $tempExists = array();
95 if (is_array($recs)) {
96 foreach ($recs as $rec) {
97 $suffix = $rec[
'softref_key'] !=
'' ?
'_s' :
'_m';
98 $idx = $rec[
'ref_table'] .
':' . $rec[
'ref_uid'];
100 if (!isset($tempExists[$idx])) {
104 $infoString = $this->
infoStr($rec);
106 if ($tempExists[$idx][
'uid']) {
107 if ($tempExists[$idx][
'pid'] == -1) {
108 $resultArray[
'offlineVersionRecords' . $suffix][$idx][$rec[
'hash']] = $infoString;
109 ksort($resultArray[
'offlineVersionRecords' . $suffix][$idx]);
110 } elseif (
$GLOBALS[
'TCA'][$rec[
'ref_table']][
'ctrl'][
'delete'] && $tempExists[$idx][
$GLOBALS[
'TCA'][$rec[
'ref_table']][
'ctrl'][
'delete']]) {
111 $resultArray[
'deletedRecords' . $suffix][$idx][$rec[
'hash']] = $infoString;
112 ksort($resultArray[
'deletedRecords' . $suffix][$idx]);
115 $resultArray[
'nonExistingRecords' . $suffix][$idx][$rec[
'hash']] = $infoString;
116 ksort($resultArray[
'nonExistingRecords' . $suffix][$idx]);
120 ksort($resultArray[
'offlineVersionRecords_m']);
121 ksort($resultArray[
'deletedRecords_m']);
122 ksort($resultArray[
'nonExistingRecords_m']);
123 ksort($resultArray[
'offlineVersionRecords_s']);
124 ksort($resultArray[
'deletedRecords_s']);
125 ksort($resultArray[
'nonExistingRecords_s']);
138 $trav = array(
'offlineVersionRecords_m',
'nonExistingRecords_m');
139 foreach ($trav as $tk) {
140 echo
'Processing managed "' . $tk .
'"...' . LF;
141 foreach ($resultArray[$tk] as $key => $value) {
142 foreach ($value as $hash => $recReference) {
143 echo
' Removing reference to ' . $key .
' in record "' . $recReference .
'": ';
148 $error = $sysRefObj->setReferenceValue($hash, NULL);
150 echo
' TYPO3\\CMS\\Core\\Database\\ReferenceIndex::setReferenceValue(): ' . $error . LF;
static makeInstance($className)
main_autoFix($resultArray)
cli_noExecutionCheck($matchString)
static getRecordRaw($table, $where='', $fields=' *')
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]