35 parent::__construct();
36 $this->cli_options[] = array(
'--excludePath [path-list]',
'Comma separated list of paths to exclude. Example: "uploads/[path1],uploads/[path2],..."');
38 $this->
cli_help[
'name'] =
'lost_files -- Looking for files in the uploads/ folder which does not have a reference in TYPO3 managed records.';
39 $this->
cli_help[
'description'] = trim(
' 41 - a perfect integrity of the reference index table (always update the reference index table before using this tool!) 42 - that all contents in the uploads folder are files attached to TCA records and exclusively managed by TCEmain through "group" type fields 43 - exceptions are: index.html and .htaccess files (ignored) 44 - exceptions are: RTEmagic* image files (ignored) 45 - files found in deleted records are included (otherwise you would see a false list of lost files) 47 The assumptions are not requirements by the TYPO3 API but reflects the de facto implementation of most TYPO3 installations and therefore a practical approach to cleaning up the uploads/ folder. 48 Therefore, if all "group" type fields in TCA and flexforms are positioned inside the uploads/ folder and if no files inside are managed manually it should be safe to clean out files with no relations found in the system. 49 Under such circumstances there should theoretically be no lost files in the uploads/ folder since TCEmain should have managed relations automatically including adding and deleting files. 50 However, there is at least one reason known to why files might be found lost and that is when FlexForms are used. In such a case a change of/in the Data Structure XML (or the ability of the system to find the Data Structure definition!) used for the flexform could leave lost files behind. This is not unlikely to happen when records are deleted. More details can be found in a note to the function TYPO3\\CMS\\Backend\\Utility\\BackendUtility::getFlexFormDS() 51 Another scenario could of course be de-installation of extensions which managed files in the uploads/ folders. 53 Automatic Repair of Errors: 54 - Simply delete lost files (Warning: First, make sure those files are not used somewhere TYPO3 does not know about! See the assumptions above). 56 $this->
cli_help[
'examples'] =
'/.../cli_dispatch.phpsh lowlevel_cleaner lost_files -s -r 57 Will report lost files.';
75 'message' => $this->
cli_help[
'name'] . LF . LF . $this->
cli_help[
'description'],
77 'managedFiles' => array(
'Files related to TYPO3 records and managed by TCEmain',
'These files you definitely want to keep.', 0),
78 'ignoredFiles' => array(
'Ignored files (index.html, .htaccess etc.)',
'These files are allowed in uploads/ folder', 0),
79 'RTEmagicFiles' => array(
'RTE magic images - those found (and ignored)',
'These files are also allowed in some uploads/ folders as RTEmagic images.', 0),
80 'lostFiles' => array(
'Lost files - those you can delete',
'You can delete these files!', 3),
81 'warnings' => array(
'Warnings picked up',
'', 2)
83 'managedFiles' => array(),
84 'ignoredFiles' => array(),
85 'RTEmagicFiles' => array(),
86 'lostFiles' => array(),
95 foreach ($fileArr as $key => $value) {
97 foreach ($excludePaths as $exclPath) {
102 $shortKey = \TYPO3\CMS\Core\Utility\GeneralUtility::shortmd5($value);
105 if (substr($value, -11) ==
'/index.html' || substr($value, -10) ==
'/.htaccess') {
106 unset($fileArr[$key]);
107 $resultArray[
'ignoredFiles'][$shortKey] = $value;
110 $recs = $TYPO3_DB->exec_SELECTgetRows(
'*',
'sys_refindex',
'ref_table=' . $TYPO3_DB->fullQuoteStr(
'_FILE',
'sys_refindex') .
' AND ref_string=' . $TYPO3_DB->fullQuoteStr($value,
'sys_refindex') .
' AND softref_key=' . $TYPO3_DB->fullQuoteStr(
'',
'sys_refindex'),
'',
'sorting DESC');
113 unset($fileArr[$key]);
114 $resultArray[
'managedFiles'][$shortKey] = $value;
115 if (count($recs) > 1) {
116 $resultArray[
'warnings'][$shortKey] =
'Warning: File "' . $value .
'" had ' . count($recs) .
' references from group-fields, should have only one!';
120 if (preg_match(
'/^RTEmagic[P|C]_/', basename($value))) {
121 unset($fileArr[$key]);
122 $resultArray[
'RTEmagicFiles'][$shortKey] = $value;
125 unset($fileArr[$key]);
126 $resultArray[
'lostFiles'][$shortKey] = $value;
132 asort($resultArray[
'ignoredFiles']);
133 asort($resultArray[
'managedFiles']);
134 asort($resultArray[
'RTEmagicFiles']);
135 asort($resultArray[
'lostFiles']);
136 asort($resultArray[
'warnings']);
150 foreach ($resultArray[
'lostFiles'] as $key => $value) {
152 echo
'Deleting file: "' . $absFileName .
'": ';
156 if ($absFileName && @is_file($absFileName)) {
157 unlink($absFileName);
160 echo
' ERROR: File "' . $absFileName .
'" was not found!';
static getAllFilesAndFoldersInPath(array $fileArr, $path, $extList='', $regDirs=FALSE, $recursivityLevels=99, $excludePattern='')
static isFirstPartOfStr($str, $partStr)
main_autoFix($resultArray)
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
cli_argValue($option, $idx=0)
cli_noExecutionCheck($matchString)
static getFileAbsFileName($filename, $onlyRelative=TRUE, $relToTYPO3_mainDir=FALSE)
static removePrefixPathFromList(array $fileArr, $prefixToRemove)