TYPO3 CMS  TYPO3_6-2
DeletedRecordsCommand.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'] = 'deleted -- To find and flush deleted records in the page tree';
36  $this->cli_help['description'] = trim('
37 Traversing page tree and finding deleted records
38 
39 Automatic Repair:
40 Although deleted records are not errors to be repaired, this tool allows you to flush the deleted records completely from the system as an automatic action. Limiting this lookup by --pid and --depth can help you to narrow in the operation to a part of the page tree.
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  'deleted' => array('Index of deleted records', 'These are records from the page tree having the deleted-flag set. The --AUTOFIX option will flush them completely!', 1)
59  ),
60  'deleted' => 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->genTree($startingPoint, $depth, (int)$this->cli_argValue('--echotree'));
65  $resultArray['deleted'] = $this->recStats['deleted'];
66  return $resultArray;
67  }
68 
77  public function main_autoFix($resultArray) {
78  // Putting "tx_templavoila_datastructure" table in the bottom:
79  if (isset($resultArray['deleted']['tx_templavoila_datastructure'])) {
80  $_tx_templavoila_datastructure = $resultArray['deleted']['tx_templavoila_datastructure'];
81  unset($resultArray['deleted']['tx_templavoila_datastructure']);
82  $resultArray['deleted']['tx_templavoila_datastructure'] = $_tx_templavoila_datastructure;
83  }
84  // Putting "pages" table in the bottom:
85  if (isset($resultArray['deleted']['pages'])) {
86  $_pages = $resultArray['deleted']['pages'];
87  unset($resultArray['deleted']['pages']);
88  // To delete sub pages first assuming they are accumulated from top of page tree.
89  $resultArray['deleted']['pages'] = array_reverse($_pages);
90  }
91  // Traversing records:
92  foreach ($resultArray['deleted'] as $table => $list) {
93  echo 'Flushing deleted records from table "' . $table . '":' . LF;
94  foreach ($list as $uid) {
95  echo ' Flushing record "' . $table . ':' . $uid . '": ';
96  if ($bypass = $this->cli_noExecutionCheck($table . ':' . $uid)) {
97  echo $bypass;
98  } else {
99  // Execute CMD array:
100  $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
101  $tce->stripslashes_values = FALSE;
102  $tce->start(array(), array());
103  // Notice, we are deleting pages with no regard to subpages/subrecords - we do this since they
104  // should also be included in the set of deleted pages of course (no un-deleted record can exist
105  // under a deleted page...)
106  $tce->deleteRecord($table, $uid, TRUE, TRUE);
107  // Return errors if any:
108  if (count($tce->errorLog)) {
109  echo ' ERROR from "TCEmain":' . LF . 'TCEmain:' . implode((LF . 'TCEmain:'), $tce->errorLog);
110  } else {
111  echo 'DONE';
112  }
113  }
114  echo LF;
115  }
116  }
117  }
118 
119 }
static forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:32
$uid
Definition: server.php:36
genTree($rootID, $depth=1000, $echoLevel=0, $callBack='')