2 namespace TYPO3\CMS\Lowlevel;
32 parent::__construct();
34 $this->
cli_help[
'name'] =
'missing_files -- Find all file references from records pointing to a missing (non-existing) file.';
35 $this->
cli_help[
'description'] = trim(
'
37 - a perfect integrity of the reference index table (always update the reference index table before using this tool!)
38 - relevant soft reference parsers applied everywhere file references are used inline
40 Files may be missing for these reasons (except software bugs):
41 - someone manually deleted the file inside fileadmin/ or another user maintained folder. If the reference was a soft reference (opposite to a TCEmain managed file relation from "group" type fields), technically it is not an error although it might be a mistake that someone did so.
42 - someone manually deleted the file inside the uploads/ folder (typically containing managed files) which is an error since no user interaction should take place there.
44 Automatic Repair of Errors:
45 - Managed files (TCA/FlexForm attachments): Will silently remove the reference from the record since the file is missing. For this reason you might prefer a manual approach instead.
46 - Soft References: Requires manual fix if you consider it an error.
48 Manual repair suggestions:
49 - Managed files: You might be able to locate the file and re-insert it in the correct location. However, no automatic fix can do that for you.
50 - Soft References: You should investigate each case and edit the content accordingly. A soft reference to a file could be in an HTML image tag (for example <img src="missing_file.jpg" />) and you would have to either remove the whole tag, change the filename or re-create the missing file.
52 $this->
cli_help[
'examples'] =
'/.../cli_dispatch.phpsh lowlevel_cleaner missing_files -s -r
53 This will show you missing files in the TYPO3 system and only report back if errors were found.';
66 $listExplain =
' Shows the relative filename of missing file as header and under a list of record fields in which the references are found. ' .
$this->label_infoString;
68 'message' => $this->
cli_help[
'name'] . LF . LF . $this->
cli_help[
'description'],
70 'managedFilesMissing' => array(
'List of missing files managed by TCEmain', $listExplain, 3),
71 'softrefFilesMissing' => array(
'List of missing files registered as a soft reference', $listExplain, 2)
73 'managedFilesMissing' => array(),
74 'softrefFilesMissing' => array()
77 $recs =
$GLOBALS[
'TYPO3_DB']->exec_SELECTgetRows(
'*',
'sys_refindex',
'ref_table=' .
$GLOBALS[
'TYPO3_DB']->fullQuoteStr(
'_FILE',
'sys_refindex'),
'',
'sorting DESC');
79 if (is_array($recs)) {
80 foreach ($recs as $rec) {
82 $infoString = $this->
infoStr($rec);
84 if (!@is_file((PATH_site . $rec[
'ref_string']))) {
85 if ((
string)$rec[
'softref_key'] ==
'') {
86 $resultArrayIndex =
'managedFilesMissing';
88 $resultArrayIndex =
'softrefFilesMissing';
90 $resultArray[$resultArrayIndex][$rec[
'ref_string']][$rec[
'hash']] = $infoString;
91 ksort($resultArray[$resultArrayIndex][$rec[
'ref_string']]);
95 ksort($resultArray[
'managedFilesMissing']);
96 ksort($resultArray[
'softrefFilesMissing']);
109 foreach ($resultArray[
'managedFilesMissing'] as $key => $value) {
110 echo
'Processing file: ' . $key . LF;
112 foreach ($value as $hash => $recReference) {
113 echo
' Removing reference in record "' . $recReference .
'": ';
117 $sysRefObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ReferenceIndex::class);
118 $error = $sysRefObj->setReferenceValue($hash, null);
120 echo
' TYPO3\\CMS\\Core\\Database\\ReferenceIndex::setReferenceValue(): ' . $error . LF;
121 echo
'missing_files: exit on error' . LF;