[TASK] Remove last references to _cli_lowlevel
[Packages/TYPO3.CMS.git] / typo3 / sysext / lowlevel / README.rst
1 INTRODUCTION
2 ============
3
4 For various reasons your TYPO3 installation may over time accumulate data with integrity problems or data you wish
5 to delete completely. For instance, why keep old versions of published content? Keep that in your backup - don't load
6 your running website with that overhead!
7
8 Or what about deleted records? Why not flush them - they also fill up your database and filesystem and most likely you
9 can rely on your backups in case of an emergency recovery?
10
11 Also, relations between records and files inside TYPO3 may be lost over time for various reasons.
12
13 If your website runs as it should such "integrity problems" are mostly easy to automatically repair by simply removing
14 the references pointing to a missing record or file.
15
16 However, it might also be "soft references" from eg. typolinks (``<link 123>...</link>``) or a file references in a
17 TypoScript template (``something.file = fileadmin/template/miss_me.jpg``) which are missing. Those cannot be automatically
18 repaired but the cleanup script incorporates warnings that will tell you about these problems if they exist and you
19 can manually fix them.
20
21 This script provides solutions to these problems by offering an array of tools that can analyze your TYPO3 installation
22 for various problems and in some cases offer fixes for them. Also third party extensions can plug additional
23 functionality into the script.
24
25
26
27 PREPARATIONS
28 ============
29
30 THERE IS ABSOLUTELY NO WARRANTY associated with this script! It is completely on your OWN RISK that you run it.
31 It may cause accidental data loss due to software bugs or circumstances that it does not know about yet - or data
32 loss might happen due to misuse!
33
34 ALWAYS make a complete backup of your website! That means:
35
36 * Dump the complete database to an SQL file. This can usually be done from the command line like this::
37
38 mysqldump [database name] -u [database user] -p --add-drop-table > ./mywebsite.sql
39
40 * Save all files in the webroot of your site. I usually do this from the command line like this::
41
42 tar czf ./mywebsite.tgz [webroot directory of your site]
43
44 Before running with the ``--AUTOFIX`` option ALWAYS make sure to add the parameter ``--dryrun`` to see what would be fixed.
45
46 Also, NEVER BYPASS the REFERENCE INDEX CHECK if ``--AUTOFIX`` is used for those tools which require a clean reference index.
47
48 It could be a good idea to run a myisamchk on your database just to make sure MySQL has everything pulled together right.
49
50 Something like this will do::
51
52 myisamchk [path_to_mysql_databases]/[database_name]/*.MYI -s -r
53
54
55
56 RUNNING the SCRIPT
57 ==================
58
59 The "[base command]" is::
60
61 [typo3_site_directory]/typo3/cli_dispatch.phpsh lowlevel_cleaner
62
63 Try this first. If it all works out you should see a help-screen. Otherwise there will be instructions about what to do.
64
65 You can use the script entirely by following the help screens. However, through this document you get some idea about
66 the best order of events since they may affect each other.
67
68 For each of the tools in the test you can see a help screen by running::
69
70 [base command] [toolkey]
71
72 Example with the tool "orphan_records"::
73
74 [typo3_site_directory]/typo3/cli_dispatch.phpsh lowlevel_cleaner orphan_records
75
76
77
78 SUGGESTED ORDER OF CLEAN UP
79 ---------------------------
80
81 The suggested order below assumes that you are interested in running all these tests. Maybe you are not! So you should
82 check the description of each one and if there is any of the tests you wish not to run, just leave it out.
83
84 It kind of gets simpler that way since the complexity mostly is when you wish to run all tests successively in which
85 case there is an optimal order that ensures you don't have to run the tests all over again.
86
87 - ``[base command] orphan_records -r --AUTOFIX```
88
89 - As a beginning, get all orphaned records out of the system since you probably want to. Since orphan records may
90 keep some missing relations from being detected it's a good idea to get them out immediately.
91
92 - ``[base command] versions -r --AUTOFIX``
93
94 - Flush all published versions now if you like. Published versions may also keep references to records which could
95 affect other tests, hence do it now if you want to.
96
97 - ``[base command] tx_templavoila_unusedce -r --AUTOFIX``
98
99 - (Assumes usage of "TemplaVoila" extension!)
100 - This should be done AFTER flushing published versions (since versions could reference elements that might be
101 safe to remove)
102 - This should be done BEFORE flushing deleted versions (since this tool will create new deleted records), given
103 that you want to completely flush them of course.
104 - You should run it over again until there remains no more unused elements. You need to do this because deleting
105 elements might generate new unused elements if the now-deleted elements had references.
106
107 - ``[base command] double_files -r --AUTOFIX```
108
109 - Fix any files referenced twice or more before you delete records (which could potentially delete a file that is
110 referenced by another file).
111
112 - ``[base command] deleted -r --AUTOFIX``
113
114 - Flush deleted records. As a rule of thumb, tools that create deleted records should be run before this one so
115 the deleted records they create are also flushed (if you like to of course)
116
117 - ``[base command] missing_relations -r --AUTOFIX``
118
119 - Remove missing relations at this point.
120 - If you get an error like this; "\TYPO3\CMS\Core\Database\ReferenceIndex::setReferenceValue(): ERROR: No reference
121 record with hash="132ddb399c0b15593f0d95a58159439f" was found!" just run the test again until no errors occur.
122 The reason is that another fixed reference in the same record and field changed the reference index hash. Running
123 the test again will find the new hash string which will then work for you.
124
125 - ``[base command] cleanflexform -r --AUTOFIX``
126
127 - After the "deleted" tool since we cannot clean-up deleted records and to make sure nothing unimportant
128 is cleaned up.
129
130 - ``[base command] rte_images -r --AUTOFIX``
131
132 - Will be affected by flushed deleted records, versions and orphans so must be run after any of those tests.
133
134
135
136 EXECUTED ANYTIME
137 ----------------
138
139 These can be executed anytime, however you should wait till all deleted records and versions are flushed so you don't
140 waste system resources on fixing deleted records.
141
142 ::
143
144 [base command] missing_files -r --AUTOFIX
145 [base command] lost_files -r --AUTOFIX
146
147
148
149 NIGHTLY REPORTS OF PROBLEMS IN THE SYSTEM
150 -----------------------------------------
151
152 If you wish to scan your TYPO3 installations for problems with a cronjob or so, a shell script that outputs a
153 report could look like this::
154
155 #!/bin/sh
156 /[WEBROOT_ABS_PATH]/typo3/cli_dispatch.phpsh lowlevel_cleaner orphan_records -r -v 2 -s
157 /[WEBROOT_ABS_PATH]/typo3/cli_dispatch.phpsh lowlevel_cleaner versions -r -v 2 -s
158 /[WEBROOT_ABS_PATH]/typo3/cli_dispatch.phpsh lowlevel_cleaner tx_templavoila_unusedce -r --refindex update -v 2 -s
159 /[WEBROOT_ABS_PATH]/typo3/cli_dispatch.phpsh lowlevel_cleaner double_files -r --refindex update -v 2 -s
160 /[WEBROOT_ABS_PATH]/typo3/cli_dispatch.phpsh lowlevel_cleaner deleted -r -v 1 -s
161 /[WEBROOT_ABS_PATH]/typo3/cli_dispatch.phpsh lowlevel_cleaner missing_relations -r --refindex update -v 2 -s
162 /[WEBROOT_ABS_PATH]/typo3/cli_dispatch.phpsh lowlevel_cleaner cleanflexform -r -v 2 -s
163 /[WEBROOT_ABS_PATH]/typo3/cli_dispatch.phpsh lowlevel_cleaner rte_images -r --refindex update -v 2 -s
164 /[WEBROOT_ABS_PATH]/typo3/cli_dispatch.phpsh lowlevel_cleaner missing_files -r --refindex update -v 2 -s
165 /[WEBROOT_ABS_PATH]/typo3/cli_dispatch.phpsh lowlevel_cleaner lost_files -r --refindex update -v 2 -s
166
167
168 You may wish to set the verbosity level (``-v``) to "3" instead of "2" as in the case above, depending on how important
169 you consider the warnings.
170
171 You might also wish to disable tests like "deleted" which would report deleted records - something that might not
172 warrant a warning, frankly speaking...
173
174 If you append ``--AUTOFIX --YES`` to each test it will actually perform clean up operations after checking, however it is
175 NOT RECOMMENDED to do that as a nightly cron-job! In addition you should study what repair operations each test does
176 to your system before using it!
177
178
179 EXAMPLE SCRIPT FOR CHECKING YOUR INSTALLATION
180 ---------------------------------------------
181
182 ::
183
184 #!/bin/sh
185 ./cli_dispatch.phpsh lowlevel_cleaner missing_files -r -v 2 -s --refindex check
186 ./cli_dispatch.phpsh lowlevel_cleaner double_files -r -v 2 -s --refindex ignore
187 ./cli_dispatch.phpsh lowlevel_cleaner lost_files -r -v 2 -s --refindex ignore
188 ./cli_dispatch.phpsh lowlevel_cleaner orphan_records -r -v 2 -s
189 ./cli_dispatch.phpsh lowlevel_cleaner versions -r -v 2 -s
190 ./cli_dispatch.phpsh lowlevel_cleaner deleted -r -v 1 -s
191 ./cli_dispatch.phpsh lowlevel_cleaner missing_relations -r -v 2 -s --refindex ignore
192 ./cli_dispatch.phpsh lowlevel_cleaner cleanflexform -r -v 2 -s
193 ./cli_dispatch.phpsh lowlevel_cleaner rte_images -r -v 2 -s --refindex ignore
194
195
196 EXAMPLE SCRIPT FOR CLEANING YOUR INSTALLATION
197 ---------------------------------------------
198
199 ::
200
201 #!/bin/sh
202 ./cli_dispatch.phpsh lowlevel_cleaner missing_files -r -v 2 -s --AUTOFIX --YES --refindex update
203 ./cli_dispatch.phpsh lowlevel_cleaner double_files -r -v 2 -s --AUTOFIX --YES --refindex update
204 ./cli_dispatch.phpsh lowlevel_cleaner lost_files -r -v 2 -s --AUTOFIX --YES --refindex update
205 ./cli_dispatch.phpsh lowlevel_cleaner orphan_records -r -v 2 -s --AUTOFIX --YES
206 ./cli_dispatch.phpsh lowlevel_cleaner versions -r -v 2 -s --AUTOFIX --YES
207 ./cli_dispatch.phpsh lowlevel_cleaner deleted -r -v 1 -s --AUTOFIX --YES
208 ./cli_dispatch.phpsh lowlevel_cleaner missing_relations -r -v 2 -s --AUTOFIX --YES --refindex update
209 ./cli_dispatch.phpsh lowlevel_cleaner cleanflexform -r -v 2 -s --AUTOFIX --YES
210 ./cli_dispatch.phpsh lowlevel_cleaner rte_images -r -v 2 -s --refindex ignore
211
212
213 ADDING YOUR OWN TOOLS TO THE TEST
214 =================================
215
216 You can plug additional analysis tools into the cleaner script. All you need to do is create a class with a few specific
217 functions and configure the cleaner to use it. You should encapsulate your class in an extension (as always).
218
219 In the steps below, substitute these strings with corresponding values:
220
221 - YOUREXTKEYNOUS = Your extension key, no underscores!
222 - YOUREXTKEY = Your full extension key
223 - CLEANERTOOL = Name prefix for your cleaner module
224
225 STEP1: Set up your class as a tool for the cleaner
226 --------------------------------------------------
227
228 - In the :file:`ext_localconf.php` file of your extension, add this::
229
230 $TYPO3_CONF_VARS['EXTCONF']['lowlevel']['cleanerModules']['tx_YOUREXTKEYNOUS_CLEANERTOOL'] =
231 array('EXT:YOUREXTKEY/class.YOUREXTKEYNOUS_CLEANERTOOL.php:tx_YOUREXTKEYNOUS_CLEANERTOOL');
232
233 - In your extension, create a PHP file ``YOUREXTKEY/class.YOUREXTKEYNOUS_CLEANERTOOL.php``
234
235 - Finally, make sure to "Clear cache in typo3conf/" after having done this!
236
237 STEP2: Build your cleaner class
238 -------------------------------
239
240 - In the new PHP file, create a class with these basic functions::
241
242 class YOUREXTKEYNOUS_CLEANERTOOL extends \TYPO3\CMS\Lowlevel\CleanerCommand {
243
244 /**
245 * Constructor
246 */
247 public function __construct() {
248 parent::__construct()();
249
250 // Setting up help:
251 $this->cli_options[] = array('--option1 value', 'Description...');
252 $this->cli_options[] = array('--option2 value', 'Description...');
253
254 $this->cli_help['name'] = 'YOUREXTKEYNOUS_CLEANERTOOL -- DESCRIPTION HERE!';
255 $this->cli_help['description'] = trim('LONG DESCRIPTION HERE');
256
257 $this->cli_help['examples'] = 'EXAMPLES HERE';
258 }
259
260 /**
261 * Analyze and return result
262 */
263 public function main() {
264
265 // Initialize result array:
266 $resultArray = array(
267 'message' => $this->cli_help['name'].
268 LF.LF.
269 $this->cli_help['description'],
270 'headers' => array(
271 'SOME_ANALYSIS_1' => array('HEADER','DESCRIPTION',VERBOSITY_LEVEL 0-3),
272 'SOME_ANALYSIS_2' => array('HEADER','DESCRIPTION',VERBOSITY_LEVEL 0-3),
273 'SOME_ANALYSIS_...' => array('HEADER','DESCRIPTION',VERBOSITY_LEVEL 0-3),
274 ),
275 'SOME_ANALYSIS_1' => array(),
276 'SOME_ANALYSIS_2' => array(),
277 'SOME_ANALYSIS_...' => array(),
278 );
279
280 // HERE you run your analysis and put result into
281 // $resultArray['SOME_ANALYSIS_1']
282 // $resultArray['SOME_ANALYSIS_2']
283 // $resultArray['SOME_ANALYSIS_...']
284
285 return $resultArray;
286 }
287
288 /**
289 * Mandatory autofix function
290 */
291 public function main_autoFix($resultArray) {
292 // HERE you traverse the result array and AUTOFIX what can be fixed
293 // Make sure to use $this->cli_noExecutionCheck() - see examples from bundled tools
294 }
295 }
296
297 STEP3: Develop your tool to do something
298 ----------------------------------------
299
300 - You should now be able to see your tool appear in the list of tools and you should see output from it when you
301 choose it.
302 - Make sure to study the bundled tools from EXT:lowlevel/. Try to deliver the same high quality of documentation and
303 coding style from there. In particular how the constructor is used to set help-message information.
304 - Also, take a look at ``\TYPO3\CMS\Backend\Clipboard\Clipboard`` which is the very base class - you can use the functions
305 in there in your script.