|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 1999-2011 Kasper Skårhøj (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 ***************************************************************/ 00027 /** 00028 * Cleaner module: cleanflexform 00029 * User function called from tx_lowlevel_cleaner_core configured in ext_localconf.php 00030 * 00031 * @author Kasper Skårhøj <kasperYYYY@typo3.com> 00032 */ 00033 /** 00034 * [CLASS/FUNCTION INDEX of SCRIPT] 00035 * 00036 * 00037 * 00038 * 57: class tx_lowlevel_cleanflexform extends tx_lowlevel_cleaner_core 00039 * 64: function tx_lowlevel_cleanflexform() 00040 * 89: function main() 00041 * 122: function main_parseTreeCallBack($tableName,$uid,$echoLevel,$versionSwapmode,$rootIsVersion) 00042 * 154: function main_autoFix($resultArray) 00043 * 00044 * TOTAL FUNCTIONS: 4 00045 * (This index is automatically created/updated by the extension "extdeveval") 00046 * 00047 */ 00048 00049 00050 /** 00051 * cleanflexform 00052 * 00053 * @author Kasper Skårhøj <kasperYYYY@typo3.com> 00054 * @package TYPO3 00055 * @subpackage tx_lowlevel 00056 */ 00057 class tx_lowlevel_cleanflexform extends tx_lowlevel_cleaner_core { 00058 00059 /** 00060 * Constructor 00061 * 00062 * @return void 00063 */ 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 00083 /** 00084 * Find orphan records 00085 * VERY CPU and memory intensive since it will look up the whole page tree! 00086 * 00087 * @return array 00088 */ 00089 function main() { 00090 global $TYPO3_DB; 00091 00092 // Initialize result array: 00093 $resultArray = array( 00094 'message' => $this->cli_help['name'].LF.LF.$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 asort($resultArray); 00110 return $resultArray; 00111 } 00112 00113 /** 00114 * Call back function for page tree traversal! 00115 * 00116 * @param string Table name 00117 * @param integer UID of record in processing 00118 * @param integer Echo level (see calling function 00119 * @param string Version swap mode on that level (see calling function 00120 * @param integer Is root version (see calling function 00121 * @return void 00122 */ 00123 function main_parseTreeCallBack($tableName,$uid,$echoLevel,$versionSwapmode,$rootIsVersion) { 00124 00125 t3lib_div::loadTCA($tableName); 00126 foreach($GLOBALS['TCA'][$tableName]['columns'] as $colName => $config) { 00127 if ($config['config']['type']=='flex') { 00128 if ($echoLevel>2) echo LF.' [cleanflexform:] Field "'.$colName.'" in '.$tableName.':'.$uid.' was a flexform and...'; 00129 00130 $recRow = t3lib_BEfunc::getRecordRaw($tableName,'uid='.intval($uid)); 00131 $flexObj = t3lib_div::makeInstance('t3lib_flexformtools'); 00132 if ($recRow[$colName]) { 00133 00134 // Clean XML: 00135 $newXML = $flexObj->cleanFlexFormXML($tableName,$colName,$recRow); 00136 00137 if (md5($recRow[$colName])!=md5($newXML)) { 00138 if ($echoLevel>2) echo ' was DIRTY, needs cleanup!'; 00139 $this->cleanFlexForm_dirtyFields[t3lib_div::shortMd5($tableName.':'.$uid.':'.$colName)] = $tableName.':'.$uid.':'.$colName; 00140 } else { 00141 if ($echoLevel>2) echo ' was CLEAN'; 00142 } 00143 } else if ($echoLevel>2) echo ' was EMPTY'; 00144 } 00145 } 00146 } 00147 00148 /** 00149 * Mandatory autofix function 00150 * Will run auto-fix on the result array. Echos status during processing. 00151 * 00152 * @param array Result array from main() function 00153 * @return void 00154 */ 00155 function main_autoFix($resultArray) { 00156 foreach($resultArray['dirty'] as $fieldID) { 00157 list($table, $uid, $field) = explode(':',$fieldID); 00158 echo 'Cleaning XML in "'.$fieldID.'": '; 00159 if ($bypass = $this->cli_noExecutionCheck($fieldID)) { 00160 echo $bypass; 00161 } else { 00162 00163 // Clean XML: 00164 $data = array(); 00165 $recRow = t3lib_BEfunc::getRecordRaw($table,'uid='.intval($uid)); 00166 $flexObj = t3lib_div::makeInstance('t3lib_flexformtools'); 00167 if ($recRow[$field]) { 00168 $data[$table][$uid][$field] = $flexObj->cleanFlexFormXML($table,$field,$recRow); 00169 } 00170 00171 // Execute Data array: 00172 $tce = t3lib_div::makeInstance('t3lib_TCEmain'); 00173 $tce->stripslashes_values = FALSE; 00174 $tce->dontProcessTransformations = TRUE; 00175 $tce->bypassWorkspaceRestrictions = TRUE; 00176 $tce->bypassFileHandling = TRUE; 00177 00178 $tce->start($data,array()); // check has been done previously that there is a backend user which is Admin and also in live workspace 00179 $tce->process_datamap(); 00180 00181 // Return errors if any: 00182 if (count($tce->errorLog)) { 00183 echo ' ERROR from "TCEmain":'.LF.'TCEmain:'.implode(LF.'TCEmain:',$tce->errorLog); 00184 } else echo 'DONE'; 00185 } 00186 echo LF; 00187 } 00188 } 00189 } 00190 00191 ?>
1.8.0