Fixing SVN directory structure
[Packages/TYPO3.CMS.git] / typo3 / sysext / lowlevel / clmods / clmods / class.cleanflexform.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: cleanflexform
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 * 57: class tx_lowlevel_cleanflexform extends tx_lowlevel_cleaner_core
39 * 64: function tx_lowlevel_cleanflexform()
40 * 89: function main()
41 * 122: function main_parseTreeCallBack($tableName,$uid,$echoLevel,$versionSwapmode,$rootIsVersion)
42 * 154: function main_autoFix($resultArray)
43 *
44 * TOTAL FUNCTIONS: 4
45 * (This index is automatically created/updated by the extension "extdeveval")
46 *
47 */
48
49
50 /**
51 * cleanflexform
52 *
53 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
54 * @package TYPO3
55 * @subpackage tx_lowlevel
56 */
57 class tx_lowlevel_cleanflexform extends tx_lowlevel_cleaner_core {
58
59 /**
60 * Constructor
61 *
62 * @return void
63 */
64 function tx_lowlevel_cleanflexform() {
65 parent::tx_lowlevel_cleaner_core();
66
67 // Setting up help:
68 $this->cli_options[] = array('--echotree level', 'When "level" is set to 1 or higher you will see the page of the page tree outputted as it is traversed. A value of 2 for "level" will show even more information.');
69 $this->cli_options[] = array('--pid id', 'Setting start page in page tree. Default is the page tree root, 0 (zero)');
70 $this->cli_options[] = array('--depth int', 'Setting traversal depth. 0 (zero) will only analyse start page (see --pid), 1 will traverse one level of subpages etc.');
71
72 $this->cli_help['name'] = 'cleanflexform -- Find flexform fields with unclean XML';
73 $this->cli_help['description'] = trim('
74 Traversing page tree and finding records with FlexForm fields with XML that could be cleaned up. This will just remove obsolete data garbage.
75
76 Automatic Repair:
77 Cleaning XML for FlexForm fields.
78 ');
79
80 $this->cli_help['examples'] = '';
81 }
82
83 /**
84 * Find orphan records
85 * VERY CPU and memory intensive since it will look up the whole page tree!
86 *
87 * @return array
88 */
89 function main() {
90 global $TYPO3_DB;
91
92 // Initialize result array:
93 $resultArray = array(
94 'message' => $this->cli_help['name'].chr(10).chr(10).$this->cli_help['description'],
95 'headers' => array(
96 'dirty' => array('','',2),
97 ),
98 'dirty' => array()
99 );
100
101 $startingPoint = $this->cli_isArg('--pid') ? t3lib_div::intInRange($this->cli_argValue('--pid'),0) : 0;
102 $depth = $this->cli_isArg('--depth') ? t3lib_div::intInRange($this->cli_argValue('--depth'),0) : 1000;
103
104 $this->cleanFlexForm_dirtyFields = &$resultArray['dirty'];
105 $this->genTree_traverseDeleted = FALSE; // Do not repair flexform data in deleted records.
106
107 $this->genTree($startingPoint,$depth,(int)$this->cli_argValue('--echotree'),'main_parseTreeCallBack');
108
109 return $resultArray;
110 }
111
112 /**
113 * Call back function for page tree traversal!
114 *
115 * @param string Table name
116 * @param integer UID of record in processing
117 * @param integer Echo level (see calling function
118 * @param string Version swap mode on that level (see calling function
119 * @param integer Is root version (see calling function
120 * @return void
121 */
122 function main_parseTreeCallBack($tableName,$uid,$echoLevel,$versionSwapmode,$rootIsVersion) {
123
124 t3lib_div::loadTCA($tableName);
125 foreach($GLOBALS['TCA'][$tableName]['columns'] as $colName => $config) {
126 if ($config['config']['type']=='flex') {
127 if ($echoLevel>2) echo chr(10).' [cleanflexform:] Field "'.$colName.'" in '.$tableName.':'.$uid.' was a flexform and...';
128
129 $recRow = t3lib_BEfunc::getRecordRaw($tableName,'uid='.intval($uid));
130 $flexObj = t3lib_div::makeInstance('t3lib_flexformtools');
131 if ($recRow[$colName]) {
132
133 // Clean XML:
134 $newXML = $flexObj->cleanFlexFormXML($tableName,$colName,$recRow);
135
136 if (md5($recRow[$colName])!=md5($newXML)) {
137 if ($echoLevel>2) echo ' was DIRTY, needs cleanup!';
138 $this->cleanFlexForm_dirtyFields[] = $tableName.':'.$uid.':'.$colName;
139 } else {
140 if ($echoLevel>2) echo ' was CLEAN';
141 }
142 } else if ($echoLevel>2) echo ' was EMPTY';
143 }
144 }
145 }
146
147 /**
148 * Mandatory autofix function
149 * Will run auto-fix on the result array. Echos status during processing.
150 *
151 * @param array Result array from main() function
152 * @return void
153 */
154 function main_autoFix($resultArray) {
155 foreach($resultArray['dirty'] as $fieldID) {
156 list($table, $uid, $field) = explode(':',$fieldID);
157 echo 'Cleaning XML in "'.$fieldID.'": ';
158 if ($bypass = $this->cli_noExecutionCheck($fieldID)) {
159 echo $bypass;
160 } else {
161
162 // Clean XML:
163 $data = array();
164 $recRow = t3lib_BEfunc::getRecordRaw($table,'uid='.intval($uid));
165 $flexObj = t3lib_div::makeInstance('t3lib_flexformtools');
166 if ($recRow[$field]) {
167 $data[$table][$uid][$field] = $flexObj->cleanFlexFormXML($table,$field,$recRow);
168 }
169
170 // Execute Data array:
171 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
172 $tce->stripslashes_values = FALSE;
173 $tce->dontProcessTransformations = TRUE;
174 $tce->bypassWorkspaceRestrictions = TRUE;
175 $tce->bypassFileHandling = TRUE;
176
177 $tce->start($data,array()); // check has been done previously that there is a backend user which is Admin and also in live workspace
178 $tce->process_datamap();
179
180 // Return errors if any:
181 if (count($tce->errorLog)) {
182 echo ' ERROR from "TCEmain":'.chr(10).'TCEmain:'.implode(chr(10).'TCEmain:',$tce->errorLog);
183 } else echo 'DONE';
184 }
185 echo chr(10);
186 }
187 }
188 }
189
190 ?>