TYPO3 CMS  TYPO3_6-2
CleanFlexformCommand.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Lowlevel;
3 
23 
29  public function __construct() {
30  parent::__construct();
31  // Setting up help:
32  $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.');
33  $this->cli_options[] = array('--pid id', 'Setting start page in page tree. Default is the page tree root, 0 (zero)');
34  $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.');
35  $this->cli_help['name'] = 'cleanflexform -- Find flexform fields with unclean XML';
36  $this->cli_help['description'] = trim('
37 Traversing page tree and finding records with FlexForm fields with XML that could be cleaned up. This will just remove obsolete data garbage.
38 
39 Automatic Repair:
40 Cleaning XML for FlexForm fields.
41 ');
42  $this->cli_help['examples'] = '';
43  }
44 
52  public function main() {
53  global $TYPO3_DB;
54  // Initialize result array:
55  $resultArray = array(
56  'message' => $this->cli_help['name'] . LF . LF . $this->cli_help['description'],
57  'headers' => array(
58  'dirty' => array('', '', 2)
59  ),
60  'dirty' => array()
61  );
62  $startingPoint = $this->cli_isArg('--pid') ? \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->cli_argValue('--pid'), 0) : 0;
63  $depth = $this->cli_isArg('--depth') ? \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->cli_argValue('--depth'), 0) : 1000;
64  $this->cleanFlexForm_dirtyFields = &$resultArray['dirty'];
65  // Do not repair flexform data in deleted records.
66  $this->genTree_traverseDeleted = FALSE;
67  $this->genTree($startingPoint, $depth, (int)$this->cli_argValue('--echotree'), 'main_parseTreeCallBack');
68  asort($resultArray);
69  return $resultArray;
70  }
71 
83  public function main_parseTreeCallBack($tableName, $uid, $echoLevel, $versionSwapmode, $rootIsVersion) {
84  foreach ($GLOBALS['TCA'][$tableName]['columns'] as $colName => $config) {
85  if ($config['config']['type'] == 'flex') {
86  if ($echoLevel > 2) {
87  echo LF . ' [cleanflexform:] Field "' . $colName . '" in ' . $tableName . ':' . $uid . ' was a flexform and...';
88  }
89  $recRow = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordRaw($tableName, 'uid=' . (int)$uid);
90  $flexObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\FlexForm\\FlexFormTools');
91  if ($recRow[$colName]) {
92  // Clean XML:
93  $newXML = $flexObj->cleanFlexFormXML($tableName, $colName, $recRow);
94  if (md5($recRow[$colName]) != md5($newXML)) {
95  if ($echoLevel > 2) {
96  echo ' was DIRTY, needs cleanup!';
97  }
98  $this->cleanFlexForm_dirtyFields[\TYPO3\CMS\Core\Utility\GeneralUtility::shortMd5($tableName . ':' . $uid . ':' . $colName)] = $tableName . ':' . $uid . ':' . $colName;
99  } else {
100  if ($echoLevel > 2) {
101  echo ' was CLEAN';
102  }
103  }
104  } elseif ($echoLevel > 2) {
105  echo ' was EMPTY';
106  }
107  }
108  }
109  }
110 
119  public function main_autoFix($resultArray) {
120  foreach ($resultArray['dirty'] as $fieldID) {
121  list($table, $uid, $field) = explode(':', $fieldID);
122  echo 'Cleaning XML in "' . $fieldID . '": ';
123  if ($bypass = $this->cli_noExecutionCheck($fieldID)) {
124  echo $bypass;
125  } else {
126  // Clean XML:
127  $data = array();
128  $recRow = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordRaw($table, 'uid=' . (int)$uid);
129  $flexObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\FlexForm\\FlexFormTools');
130  if ($recRow[$field]) {
131  $data[$table][$uid][$field] = $flexObj->cleanFlexFormXML($table, $field, $recRow);
132  }
133  // Execute Data array:
134  $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
135  $tce->stripslashes_values = FALSE;
136  $tce->dontProcessTransformations = TRUE;
137  $tce->bypassWorkspaceRestrictions = TRUE;
138  $tce->bypassFileHandling = TRUE;
139  // Check has been done previously that there is a backend user which is Admin and also in live workspace
140  $tce->start($data, array());
141  $tce->process_datamap();
142  // Return errors if any:
143  if (count($tce->errorLog)) {
144  echo ' ERROR from "TCEmain":' . LF . 'TCEmain:' . implode((LF . 'TCEmain:'), $tce->errorLog);
145  } else {
146  echo 'DONE';
147  }
148  }
149  echo LF;
150  }
151  }
152 
153 }
static forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:32
$uid
Definition: server.php:36
main_parseTreeCallBack($tableName, $uid, $echoLevel, $versionSwapmode, $rootIsVersion)
static getRecordRaw($table, $where='', $fields=' *')
genTree($rootID, $depth=1000, $echoLevel=0, $callBack='')
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]