TYPO3 CMS  TYPO3_6-2
MissingFilesCommand.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Lowlevel;
3 
23 
27  public $checkRefIndex = TRUE;
28 
34  public function __construct() {
35  parent::__construct();
36  // Setting up help:
37  $this->cli_help['name'] = 'missing_files -- Find all file references from records pointing to a missing (non-existing) file.';
38  $this->cli_help['description'] = trim('
39 Assumptions:
40 - a perfect integrity of the reference index table (always update the reference index table before using this tool!)
41 - relevant soft reference parsers applied everywhere file references are used inline
42 
43 Files may be missing for these reasons (except software bugs):
44 - 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.
45 - 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.
46 
47 Automatic Repair of Errors:
48 - 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.
49 - Soft References: Requires manual fix if you consider it an error.
50 
51 Manual repair suggestions:
52 - 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.
53 - 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.
54 ');
55  $this->cli_help['examples'] = '/.../cli_dispatch.phpsh lowlevel_cleaner missing_files -s -r
56 This will show you missing files in the TYPO3 system and only report back if errors were found.';
57  }
58 
67  public function main() {
68  global $TYPO3_DB;
69  // Initialize result array:
70  $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;
71  $resultArray = array(
72  'message' => $this->cli_help['name'] . LF . LF . $this->cli_help['description'],
73  'headers' => array(
74  'managedFilesMissing' => array('List of missing files managed by TCEmain', $listExplain, 3),
75  'softrefFilesMissing' => array('List of missing files registered as a soft reference', $listExplain, 2)
76  ),
77  'managedFilesMissing' => array(),
78  'softrefFilesMissing' => array()
79  );
80  // Select all files in the reference table
81  $recs = $TYPO3_DB->exec_SELECTgetRows('*', 'sys_refindex', 'ref_table=' . $TYPO3_DB->fullQuoteStr('_FILE', 'sys_refindex'), '', 'sorting DESC');
82  // Traverse the files and put into a large table:
83  if (is_array($recs)) {
84  foreach ($recs as $rec) {
85  // Compile info string for location of reference:
86  $infoString = $this->infoStr($rec);
87  // Handle missing file:
88  if (!@is_file((PATH_site . $rec['ref_string']))) {
89  if ((string) $rec['softref_key'] == '') {
90  $resultArrayIndex = 'managedFilesMissing';
91  } else {
92  $resultArrayIndex = 'softrefFilesMissing';
93  }
94  $resultArray[$resultArrayIndex][$rec['ref_string']][$rec['hash']] = $infoString;
95  ksort($resultArray[$resultArrayIndex][$rec['ref_string']]);
96  }
97  }
98  }
99  ksort($resultArray['managedFilesMissing']);
100  ksort($resultArray['softrefFilesMissing']);
101  return $resultArray;
102  }
103 
112  public function main_autoFix($resultArray) {
113  foreach ($resultArray['managedFilesMissing'] as $key => $value) {
114  echo 'Processing file: ' . $key . LF;
115  $c = 0;
116  foreach ($value as $hash => $recReference) {
117  echo ' Removing reference in record "' . $recReference . '": ';
118  if ($bypass = $this->cli_noExecutionCheck($recReference)) {
119  echo $bypass;
120  } else {
121  $sysRefObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Database\\ReferenceIndex');
122  $error = $sysRefObj->setReferenceValue($hash, NULL);
123  if ($error) {
124  echo ' TYPO3\\CMS\\Core\\Database\\ReferenceIndex::setReferenceValue(): ' . $error . LF;
125  echo 'missing_files: exit on error' . LF;
126  die;
127  } else {
128  echo 'DONE';
129  }
130  }
131  echo LF;
132  }
133  }
134  }
135 
136 }
die
Definition: index.php:6