Documentation TYPO3 par Ameos |
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com) 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * A copy is found in the textfile GPL.txt and important notices to the license 00017 * from the author is found in LICENSE.txt distributed with these scripts. 00018 * 00019 * 00020 * This script is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * This copyright notice MUST APPEAR in all copies of the script! 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 // Setting up help: 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 // Initialize result array: 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; // Do not repair flexform data in deleted records. 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 // Clean XML: 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 // Clean XML: 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 // Execute Data array: 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()); // check has been done previously that there is a backend user which is Admin and also in live workspace 00178 $tce->process_datamap(); 00179 00180 // Return errors if any: 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 ?>