TYPO3 CMS  TYPO3_7-6
DeletedRecordsCommand.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Lowlevel;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 {
25  public function __construct()
26  {
27  parent::__construct();
28  // Setting up help:
29  $this->cli_options[] = ['--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.'];
30  $this->cli_options[] = ['--pid id', 'Setting start page in page tree. Default is the page tree root, 0 (zero)'];
31  $this->cli_options[] = ['--depth int', 'Setting traversal depth. 0 (zero) will only analyse start page (see --pid), 1 will traverse one level of subpages etc.'];
32  $this->cli_help['name'] = 'deleted -- To find and flush deleted records in the page tree';
33  $this->cli_help['description'] = trim('
34 Traversing page tree and finding deleted records
35 
36 Automatic Repair:
37 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.
38 ');
39  $this->cli_help['examples'] = '';
40  }
41 
48  public function main()
49  {
50  // Initialize result array:
51  $resultArray = [
52  'message' => $this->cli_help['name'] . LF . LF . $this->cli_help['description'],
53  'headers' => [
54  'deleted' => ['Index of deleted records', 'These are records from the page tree having the deleted-flag set. The --AUTOFIX option will flush them completely!', 1]
55  ],
56  'deleted' => []
57  ];
58  $startingPoint = $this->cli_isArg('--pid') ? \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->cli_argValue('--pid'), 0) : 0;
59  $depth = $this->cli_isArg('--depth') ? \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->cli_argValue('--depth'), 0) : 1000;
60  $this->genTree($startingPoint, $depth, (int)$this->cli_argValue('--echotree'));
61  $resultArray['deleted'] = $this->recStats['deleted'];
62  return $resultArray;
63  }
64 
72  public function main_autoFix($resultArray)
73  {
74  // Putting "tx_templavoila_datastructure" table in the bottom:
75  if (isset($resultArray['deleted']['tx_templavoila_datastructure'])) {
76  $_tx_templavoila_datastructure = $resultArray['deleted']['tx_templavoila_datastructure'];
77  unset($resultArray['deleted']['tx_templavoila_datastructure']);
78  $resultArray['deleted']['tx_templavoila_datastructure'] = $_tx_templavoila_datastructure;
79  }
80  // Putting "pages" table in the bottom:
81  if (isset($resultArray['deleted']['pages'])) {
82  $_pages = $resultArray['deleted']['pages'];
83  unset($resultArray['deleted']['pages']);
84  // To delete sub pages first assuming they are accumulated from top of page tree.
85  $resultArray['deleted']['pages'] = array_reverse($_pages);
86  }
87  // Traversing records:
88  foreach ($resultArray['deleted'] as $table => $list) {
89  echo 'Flushing deleted records from table "' . $table . '":' . LF;
90  foreach ($list as $uid) {
91  echo ' Flushing record "' . $table . ':' . $uid . '": ';
92  if ($bypass = $this->cli_noExecutionCheck($table . ':' . $uid)) {
93  echo $bypass;
94  } else {
95  // Execute CMD array:
96  $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
97  $tce->stripslashes_values = false;
98  $tce->start([], []);
99  // Notice, we are deleting pages with no regard to subpages/subrecords - we do this since they
100  // should also be included in the set of deleted pages of course (no un-deleted record can exist
101  // under a deleted page...)
102  $tce->deleteRecord($table, $uid, true, true);
103  // Return errors if any:
104  if (count($tce->errorLog)) {
105  echo ' ERROR from "TCEmain":' . LF . 'TCEmain:' . implode((LF . 'TCEmain:'), $tce->errorLog);
106  } else {
107  echo 'DONE';
108  }
109  }
110  echo LF;
111  }
112  }
113  }
114 }
static forceIntegerInRange($theInt, $min, $max=2000000000, $defaultValue=0)
Definition: MathUtility.php:31
genTree($rootID, $depth=1000, $echoLevel=0, $callBack='')
$uid
Definition: server.php:38