[TASK] Clean up phpDoc comments in typo3/sysext/
[Packages/TYPO3.CMS.git] / typo3 / sysext / lowlevel / clmods / class.missing_files.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Cleaner module: Missing files
29 * User function called from tx_lowlevel_cleaner_core configured in ext_localconf.php
30 *
31 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
32 */
33
34 /**
35 * Looking for missing files.
36 *
37 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
38 * @package TYPO3
39 * @subpackage tx_lowlevel
40 */
41 class tx_lowlevel_missing_files extends tx_lowlevel_cleaner_core {
42
43 var $checkRefIndex = TRUE;
44
45 /**
46 * Constructor
47 */
48 function __construct() {
49 parent::__construct();
50
51 // Setting up help:
52 $this->cli_help['name'] = 'missing_files -- Find all file references from records pointing to a missing (non-existing) file.';
53 $this->cli_help['description'] = trim('
54 Assumptions:
55 - a perfect integrity of the reference index table (always update the reference index table before using this tool!)
56 - relevant soft reference parsers applied everywhere file references are used inline
57
58 Files may be missing for these reasons (except software bugs):
59 - 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.
60 - 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.
61
62 Automatic Repair of Errors:
63 - 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.
64 - Soft References: Requires manual fix if you consider it an error.
65
66 Manual repair suggestions:
67 - 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.
68 - 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.
69 ');
70
71 $this->cli_help['examples'] = '/.../cli_dispatch.phpsh lowlevel_cleaner missing_files -s -r
72 This will show you missing files in the TYPO3 system and only report back if errors were found.';
73 }
74
75 /**
76 * Find file references that points to non-existing files in system
77 * Fix methods: API in t3lib_refindex that allows to change the value of a reference (or remove it)
78 *
79 * @return array
80 */
81 function main() {
82 global $TYPO3_DB;
83
84 // Initialize result array:
85 $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;
86 $resultArray = array(
87 'message' => $this->cli_help['name'].LF.LF.$this->cli_help['description'],
88 'headers' => array(
89 'managedFilesMissing' => array('List of missing files managed by TCEmain', $listExplain, 3),
90 'softrefFilesMissing' => array('List of missing files registered as a soft reference', $listExplain, 2),
91 ),
92 'managedFilesMissing' => array(),
93 'softrefFilesMissing' => array(),
94 );
95
96
97 // Select all files in the reference table
98 $recs = $TYPO3_DB->exec_SELECTgetRows(
99 '*',
100 'sys_refindex',
101 'ref_table='.$TYPO3_DB->fullQuoteStr('_FILE', 'sys_refindex'),
102 '',
103 'sorting DESC'
104 );
105
106 // Traverse the files and put into a large table:
107 if (is_array($recs)) {
108 foreach ($recs as $rec) {
109
110 // Compile info string for location of reference:
111 $infoString = $this->infoStr($rec);
112
113 // Handle missing file:
114 if (!@is_file(PATH_site.$rec['ref_string'])) {
115
116 if ((string)$rec['softref_key']=='') {
117 $resultArrayIndex = 'managedFilesMissing';
118 } else {
119 $resultArrayIndex = 'softrefFilesMissing';
120 }
121
122 $resultArray[$resultArrayIndex][$rec['ref_string']][$rec['hash']] = $infoString;
123 ksort($resultArray[$resultArrayIndex][$rec['ref_string']]); // Sort by array key.
124 }
125 }
126 }
127
128 ksort($resultArray['managedFilesMissing']);
129 ksort($resultArray['softrefFilesMissing']);
130
131 return $resultArray;
132 }
133
134 /**
135 * Mandatory autofix function
136 * Will run auto-fix on the result array. Echos status during processing.
137 *
138 * @param array $resultArray Result array from main() function
139 * @return void
140 */
141 function main_autoFix($resultArray) {
142 foreach ($resultArray['managedFilesMissing'] as $key => $value) {
143 echo 'Processing file: '.$key.LF;
144 $c = 0;
145 foreach ($value as $hash => $recReference) {
146 echo ' Removing reference in record "'.$recReference.'": ';
147 if ($bypass = $this->cli_noExecutionCheck($recReference)) {
148 echo $bypass;
149 } else {
150 $sysRefObj = t3lib_div::makeInstance('t3lib_refindex');
151 $error = $sysRefObj->setReferenceValue($hash, NULL);
152 if ($error) {
153 echo ' t3lib_refindex::setReferenceValue(): '.$error.LF;
154 echo 'missing_files: exit on error'.LF;
155 exit;
156 } else echo "DONE";
157 }
158 echo LF;
159 }
160 }
161 }
162 }
163
164 ?>