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
00057 class tx_lowlevel_cleanflexform extends tx_lowlevel_cleaner_core {
00058
00064 function tx_lowlevel_cleanflexform() {
00065 parent::tx_lowlevel_cleaner_core();
00066
00067
00068 $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.');
00069 $this->cli_options[] = array('--pid id', 'Setting start page in page tree. Default is the page tree root, 0 (zero)');
00070 $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.');
00071
00072 $this->cli_help['name'] = 'cleanflexform -- Find flexform fields with unclean XML';
00073 $this->cli_help['description'] = trim('
00074 Traversing page tree and finding records with FlexForm fields with XML that could be cleaned up. This will just remove obsolete data garbage.
00075
00076 Automatic Repair:
00077 Cleaning XML for FlexForm fields.
00078 ');
00079
00080 $this->cli_help['examples'] = '';
00081 }
00082
00089 function main() {
00090 global $TYPO3_DB;
00091
00092
00093 $resultArray = array(
00094 'message' => $this->cli_help['name'].chr(10).chr(10).$this->cli_help['description'],
00095 'headers' => array(
00096 'dirty' => array('','',2),
00097 ),
00098 'dirty' => array()
00099 );
00100
00101 $startingPoint = $this->cli_isArg('--pid') ? t3lib_div::intInRange($this->cli_argValue('--pid'),0) : 0;
00102 $depth = $this->cli_isArg('--depth') ? t3lib_div::intInRange($this->cli_argValue('--depth'),0) : 1000;
00103
00104 $this->cleanFlexForm_dirtyFields = &$resultArray['dirty'];
00105 $this->genTree_traverseDeleted = FALSE;
00106
00107 $this->genTree($startingPoint,$depth,(int)$this->cli_argValue('--echotree'),'main_parseTreeCallBack');
00108
00109 return $resultArray;
00110 }
00111
00122 function main_parseTreeCallBack($tableName,$uid,$echoLevel,$versionSwapmode,$rootIsVersion) {
00123
00124 t3lib_div::loadTCA($tableName);
00125 foreach($GLOBALS['TCA'][$tableName]['columns'] as $colName => $config) {
00126 if ($config['config']['type']=='flex') {
00127 if ($echoLevel>2) echo chr(10).' [cleanflexform:] Field "'.$colName.'" in '.$tableName.':'.$uid.' was a flexform and...';
00128
00129 $recRow = t3lib_BEfunc::getRecordRaw($tableName,'uid='.intval($uid));
00130 $flexObj = t3lib_div::makeInstance('t3lib_flexformtools');
00131 if ($recRow[$colName]) {
00132
00133
00134 $newXML = $flexObj->cleanFlexFormXML($tableName,$colName,$recRow);
00135
00136 if (md5($recRow[$colName])!=md5($newXML)) {
00137 if ($echoLevel>2) echo ' was DIRTY, needs cleanup!';
00138 $this->cleanFlexForm_dirtyFields[] = $tableName.':'.$uid.':'.$colName;
00139 } else {
00140 if ($echoLevel>2) echo ' was CLEAN';
00141 }
00142 } else if ($echoLevel>2) echo ' was EMPTY';
00143 }
00144 }
00145 }
00146
00154 function main_autoFix($resultArray) {
00155 foreach($resultArray['dirty'] as $fieldID) {
00156 list($table, $uid, $field) = explode(':',$fieldID);
00157 echo 'Cleaning XML in "'.$fieldID.'": ';
00158 if ($bypass = $this->cli_noExecutionCheck($fieldID)) {
00159 echo $bypass;
00160 } else {
00161
00162
00163 $data = array();
00164 $recRow = t3lib_BEfunc::getRecordRaw($table,'uid='.intval($uid));
00165 $flexObj = t3lib_div::makeInstance('t3lib_flexformtools');
00166 if ($recRow[$field]) {
00167 $data[$table][$uid][$field] = $flexObj->cleanFlexFormXML($table,$field,$recRow);
00168 }
00169
00170
00171 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
00172 $tce->stripslashes_values = FALSE;
00173 $tce->dontProcessTransformations = TRUE;
00174 $tce->bypassWorkspaceRestrictions = TRUE;
00175 $tce->bypassFileHandling = TRUE;
00176
00177 $tce->start($data,array());
00178 $tce->process_datamap();
00179
00180
00181 if (count($tce->errorLog)) {
00182 echo ' ERROR from "TCEmain":'.chr(10).'TCEmain:'.implode(chr(10).'TCEmain:',$tce->errorLog);
00183 } else echo 'DONE';
00184 }
00185 echo chr(10);
00186 }
00187 }
00188 }
00189
00190 ?>