Fixing SVN directory structure
[Packages/TYPO3.CMS.git] / typo3 / sysext / lowlevel / clmods / clmods / class.rte_images.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2005 Kasper Skaarhoj (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: RTE magicc images
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 * [CLASS/FUNCTION INDEX of SCRIPT]
35 *
36 *
37 *
38 * 56: class tx_lowlevel_rte_images extends tx_lowlevel_cleaner_core
39 * 65: function tx_lowlevel_rte_images()
40 * 99: function main()
41 * 181: function main_autoFix($resultArray)
42 *
43 * TOTAL FUNCTIONS: 3
44 * (This index is automatically created/updated by the extension "extdeveval")
45 *
46 */
47
48
49 /**
50 * Looking for RTE images integrity
51 *
52 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
53 * @package TYPO3
54 * @subpackage tx_lowlevel
55 */
56 class tx_lowlevel_rte_images extends tx_lowlevel_cleaner_core {
57
58 var $checkRefIndex = TRUE;
59
60 /**
61 * Constructor
62 *
63 * @return void
64 */
65 function tx_lowlevel_rte_images() {
66 parent::tx_lowlevel_cleaner_core();
67
68 // Setting up help:
69 $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.';
70 $this->cli_help['description'] = trim('
71 Assumptions:
72 - a perfect integrity of the reference index table (always update the reference index table before using this tool!)
73 - that all RTEmagic image files in the database are registered with the soft reference parser "images"
74 - images found in deleted records are included (means that you might find lost RTEmagic images after flushing deleted records)
75
76 The assumptions are not requirements by the TYPO3 API but reflects the de facto implementation of most TYPO3 installations.
77 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.
78 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!
79 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.
80
81 Automatic Repair of Errors:
82 - There is currently no automatic repair available
83
84 Manual repair suggestions:
85 - Missing files: Re-insert missing files or edit record where the reference is found.
86 - Lost files: Delete them if you do not recognize them as used somewhere the system does not know about.
87 ');
88
89 $this->cli_help['examples'] = '/.../cli_dispatch.phpsh lowlevel_cleaner rte_images -s -r
90 Reports problems with RTE images';
91 }
92
93 /**
94 * Analyse situation with RTE magic images. (still to define what the most useful output is).
95 * Fix methods: API in t3lib_refindex that allows to change the value of a reference (we could copy the files) or remove reference
96 *
97 * @return array
98 */
99 function main() {
100 global $TYPO3_DB;
101
102 // Initialize result array:
103 $resultArray = array(
104 'message' => $this->cli_help['name'].chr(10).chr(10).$this->cli_help['description'],
105 'headers' => array(
106 '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),
107 'RTEmagicFilePairs' => array('Statistical info about RTEmagic files','(copy used as index)',0),
108 'missingFiles' => array('Missing RTEmagic image files','These files are not found in the file system! Should be corrected!',3),
109 '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),
110 'warnings' => array('Warnings picked up','',2)
111 ),
112 'RTEmagicFilePairs' => array(),
113 'completeFileList' => array(),
114 'missingFiles' => array(),
115 'lostFiles' => array(),
116 'warnings' => array()
117 );
118
119 // Select all RTEmagic files in the reference table (only from soft references of course)
120 $recs = $TYPO3_DB->exec_SELECTgetRows(
121 '*',
122 'sys_refindex',
123 'ref_table='.$TYPO3_DB->fullQuoteStr('_FILE', 'sys_refindex').
124 ' AND ref_string LIKE '.$TYPO3_DB->fullQuoteStr('%/RTEmagic%', 'sys_refindex').
125 ' AND softref_key='.$TYPO3_DB->fullQuoteStr('images', 'sys_refindex'),
126 '',
127 'sorting DESC'
128 );
129
130 // Traverse the files and put into a large table:
131 if (is_array($recs)) {
132 foreach($recs as $rec) {
133 $filename = basename($rec['ref_string']);
134 if (t3lib_div::isFirstPartOfStr($filename,'RTEmagicC_')) {
135 $original = 'RTEmagicP_'.ereg_replace('\.[[:alnum:]]+$','',substr($filename,10));
136 $infoString = $this->infoStr($rec);
137
138 // Build index:
139 $resultArray['RTEmagicFilePairs'][$rec['ref_string']]['exists'] = @is_file(PATH_site.$rec['ref_string']);
140 $resultArray['RTEmagicFilePairs'][$rec['ref_string']]['original'] = substr($rec['ref_string'],0,-strlen($filename)).$original;
141 $resultArray['RTEmagicFilePairs'][$rec['ref_string']]['original_exists'] = @is_file(PATH_site.$resultArray['RTEmagicFilePairs'][$rec['ref_string']]['original']);
142 $resultArray['RTEmagicFilePairs'][$rec['ref_string']]['count']++;
143 $resultArray['RTEmagicFilePairs'][$rec['ref_string']]['usedIn'][$rec['hash']] = $infoString;
144
145 $resultArray['completeFileList'][$resultArray['RTEmagicFilePairs'][$rec['ref_string']]['original']]++;
146 $resultArray['completeFileList'][$rec['ref_string']]++;
147
148 // Missing files:
149 if (!$resultArray['RTEmagicFilePairs'][$rec['ref_string']]['exists']) {
150 $resultArray['missingFiles'][$rec['ref_string']] = $resultArray['RTEmagicFilePairs'][$rec['ref_string']]['usedIn'];
151 }
152 if (!$resultArray['RTEmagicFilePairs'][$rec['ref_string']]['original_exists']) {
153 $resultArray['missingFiles'][$resultArray['RTEmagicFilePairs'][$rec['ref_string']]['original']] = $resultArray['RTEmagicFilePairs'][$rec['ref_string']]['usedIn'];
154 }
155 }
156 }
157 }
158
159 // Now, ask for RTEmagic files inside uploads/ folder:
160 $cleanerModules = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['lowlevel']['cleanerModules'];
161 $cleanerMode = &t3lib_div::getUserObj($cleanerModules['lost_files'][0]);
162 $resLostFiles = $cleanerMode->main(array(),FALSE,TRUE);
163 if (is_array($resLostFiles['RTEmagicFiles'])) {
164 foreach($resLostFiles['RTEmagicFiles'] as $fileName) {
165 if (!isset($resultArray['completeFileList'][$fileName])) {
166 $resultArray['lostFiles'][] = $fileName;
167 }
168 }
169 }
170
171 return $resultArray;
172 }
173
174 /**
175 * Mandatory autofix function
176 * Will run auto-fix on the result array. Echos status during processing.
177 *
178 * @param array Result array from main() function
179 * @return void
180 */
181 function main_autoFix($resultArray) {
182 echo "There is currently no automatic repair available\n";
183 }
184 }
185
186 ?>