00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00056 class tx_lowlevel_rte_images extends tx_lowlevel_cleaner_core {
00057
00058 var $checkRefIndex = TRUE;
00059
00065 function tx_lowlevel_rte_images() {
00066 parent::tx_lowlevel_cleaner_core();
00067
00068
00069 $this->cli_help['name'] = 'rte_images -- Looking up all occurencies of RTEmagic images in the database and check existence of parent and copy files on the file system plus report possibly lost files of this type.';
00070 $this->cli_help['description'] = trim('
00071 Assumptions:
00072 - a perfect integrity of the reference index table (always update the reference index table before using this tool!)
00073 - that all RTEmagic image files in the database are registered with the soft reference parser "images"
00074 - images found in deleted records are included (means that you might find lost RTEmagic images after flushing deleted records)
00075
00076 The assumptions are not requirements by the TYPO3 API but reflects the de facto implementation of most TYPO3 installations.
00077 However, many custom fields using an RTE will probably not have the "images" soft reference parser registered and so the index will be incomplete and not listing all RTEmagic image files.
00078 The consequence of this limitation is that you should be careful if you wish to delete lost RTEmagic images - they could be referenced from a field not parsed by the "images" soft reference parser!
00079 Another limitation: In theory a RTEmagic image should be used from only one record, however TCEmain does not support this (unfortunately!) so when a record is copied or versioned no new version will be produced. This leads to a usage count of more than one for many RTEmagic images which is also shown in the overview. At this point in time its not considered a bug and there is no fix for it.
00080
00081 Automatic Repair of Errors:
00082 - There is currently no automatic repair available
00083
00084 Manual repair suggestions:
00085 - Missing files: Re-insert missing files or edit record where the reference is found.
00086 - Lost files: Delete them if you do not recognize them as used somewhere the system does not know about.
00087 ');
00088
00089 $this->cli_help['examples'] = '/.../cli_dispatch.phpsh lowlevel_cleaner rte_images -s -r
00090 Reports problems with RTE images';
00091 }
00092
00099 function main() {
00100 global $TYPO3_DB;
00101
00102
00103 $resultArray = array(
00104 'message' => $this->cli_help['name'].chr(10).chr(10).$this->cli_help['description'],
00105 'headers' => array(
00106 'completeFileList' => array('Complete list of used RTEmagic files','Both parent and copy are listed here including usage count (which should in theory all be "1"). This list does not exclude files that might be missing.',1),
00107 'RTEmagicFilePairs' => array('Statistical info about RTEmagic files','(copy used as index)',0),
00108 'missingFiles' => array('Missing RTEmagic image files','These files are not found in the file system! Should be corrected!',3),
00109 'lostFiles' => array('Lost RTEmagic files from uploads/','These files you might be able to delete but only if _all_ RTEmagic images are found by the soft reference parser. If you are using the RTE in third-party extensions it is likely that the soft reference parser is not applied correctly to their RTE and thus these "lost" files actually represent valid RTEmagic images, just not registered.',2),
00110 'warnings' => array('Warnings picked up','',2)
00111 ),
00112 'RTEmagicFilePairs' => array(),
00113 'completeFileList' => array(),
00114 'missingFiles' => array(),
00115 'lostFiles' => array(),
00116 'warnings' => array()
00117 );
00118
00119
00120 $recs = $TYPO3_DB->exec_SELECTgetRows(
00121 '*',
00122 'sys_refindex',
00123 'ref_table='.$TYPO3_DB->fullQuoteStr('_FILE', 'sys_refindex').
00124 ' AND ref_string LIKE '.$TYPO3_DB->fullQuoteStr('%/RTEmagic%', 'sys_refindex').
00125 ' AND softref_key='.$TYPO3_DB->fullQuoteStr('images', 'sys_refindex'),
00126 '',
00127 'sorting DESC'
00128 );
00129
00130
00131 if (is_array($recs)) {
00132 foreach($recs as $rec) {
00133 $filename = basename($rec['ref_string']);
00134 if (t3lib_div::isFirstPartOfStr($filename,'RTEmagicC_')) {
00135 $original = 'RTEmagicP_'.ereg_replace('\.[[:alnum:]]+$','',substr($filename,10));
00136 $infoString = $this->infoStr($rec);
00137
00138
00139 $resultArray['RTEmagicFilePairs'][$rec['ref_string']]['exists'] = @is_file(PATH_site.$rec['ref_string']);
00140 $resultArray['RTEmagicFilePairs'][$rec['ref_string']]['original'] = substr($rec['ref_string'],0,-strlen($filename)).$original;
00141 $resultArray['RTEmagicFilePairs'][$rec['ref_string']]['original_exists'] = @is_file(PATH_site.$resultArray['RTEmagicFilePairs'][$rec['ref_string']]['original']);
00142 $resultArray['RTEmagicFilePairs'][$rec['ref_string']]['count']++;
00143 $resultArray['RTEmagicFilePairs'][$rec['ref_string']]['usedIn'][$rec['hash']] = $infoString;
00144
00145 $resultArray['completeFileList'][$resultArray['RTEmagicFilePairs'][$rec['ref_string']]['original']]++;
00146 $resultArray['completeFileList'][$rec['ref_string']]++;
00147
00148
00149 if (!$resultArray['RTEmagicFilePairs'][$rec['ref_string']]['exists']) {
00150 $resultArray['missingFiles'][$rec['ref_string']] = $resultArray['RTEmagicFilePairs'][$rec['ref_string']]['usedIn'];
00151 }
00152 if (!$resultArray['RTEmagicFilePairs'][$rec['ref_string']]['original_exists']) {
00153 $resultArray['missingFiles'][$resultArray['RTEmagicFilePairs'][$rec['ref_string']]['original']] = $resultArray['RTEmagicFilePairs'][$rec['ref_string']]['usedIn'];
00154 }
00155 }
00156 }
00157 }
00158
00159
00160 $cleanerModules = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['lowlevel']['cleanerModules'];
00161 $cleanerMode = &t3lib_div::getUserObj($cleanerModules['lost_files'][0]);
00162 $resLostFiles = $cleanerMode->main(array(),FALSE,TRUE);
00163 if (is_array($resLostFiles['RTEmagicFiles'])) {
00164 foreach($resLostFiles['RTEmagicFiles'] as $fileName) {
00165 if (!isset($resultArray['completeFileList'][$fileName])) {
00166 $resultArray['lostFiles'][] = $fileName;
00167 }
00168 }
00169 }
00170
00171 return $resultArray;
00172 }
00173
00181 function main_autoFix($resultArray) {
00182 echo "There is currently no automatic repair available\n";
00183 }
00184 }
00185
00186 ?>