cade063324f9b77ecf0ecbd2b7b02225934915a9
[Packages/TYPO3.CMS.git] / typo3 / sysext / integrity / Classes / DeletedRecordsCommand.php
1 <?php
2 namespace TYPO3\CMS\Integrity;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 /**
30 * Cleaner module: Deleted records
31 * User function called from tx_lowlevel_cleaner_core configured in ext_localconf.php
32 *
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
34 */
35 /**
36 * Looking for Deleted records
37 *
38 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
39 * @package TYPO3
40 * @subpackage tx_lowlevel
41 */
42 class DeletedRecordsCommand extends \TYPO3\CMS\Integrity\CleanerCommand {
43
44 /**
45 * Constructor
46 *
47 * @todo Define visibility
48 */
49 public function __construct() {
50 parent::__construct();
51 // Setting up help:
52 $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.');
53 $this->cli_options[] = array('--pid id', 'Setting start page in page tree. Default is the page tree root, 0 (zero)');
54 $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.');
55 $this->cli_help['name'] = 'deleted -- To find and flush deleted records in the page tree';
56 $this->cli_help['description'] = trim('
57 Traversing page tree and finding deleted records
58
59 Automatic Repair:
60 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.
61 ');
62 $this->cli_help['examples'] = '';
63 }
64
65 /**
66 * Find orphan records
67 * VERY CPU and memory intensive since it will look up the whole page tree!
68 *
69 * @return array
70 * @todo Define visibility
71 */
72 public function main() {
73 global $TYPO3_DB;
74 // Initialize result array:
75 $resultArray = array(
76 'message' => $this->cli_help['name'] . LF . LF . $this->cli_help['description'],
77 'headers' => array(
78 '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)
79 ),
80 'deleted' => array()
81 );
82 $startingPoint = $this->cli_isArg('--pid') ? \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->cli_argValue('--pid'), 0) : 0;
83 $depth = $this->cli_isArg('--depth') ? \TYPO3\CMS\Core\Utility\MathUtility::forceIntegerInRange($this->cli_argValue('--depth'), 0) : 1000;
84 $this->genTree($startingPoint, $depth, (int) $this->cli_argValue('--echotree'));
85 $resultArray['deleted'] = $this->recStats['deleted'];
86 return $resultArray;
87 }
88
89 /**
90 * Mandatory autofix function
91 * Will run auto-fix on the result array. Echos status during processing.
92 *
93 * @param array $resultArray Result array from main() function
94 * @return void
95 * @todo Define visibility
96 */
97 public function main_autoFix($resultArray) {
98 // Putting "tx_templavoila_datastructure" table in the bottom:
99 if (isset($resultArray['deleted']['tx_templavoila_datastructure'])) {
100 $_tx_templavoila_datastructure = $resultArray['deleted']['tx_templavoila_datastructure'];
101 unset($resultArray['deleted']['tx_templavoila_datastructure']);
102 $resultArray['deleted']['tx_templavoila_datastructure'] = $_tx_templavoila_datastructure;
103 }
104 // Putting "pages" table in the bottom:
105 if (isset($resultArray['deleted']['pages'])) {
106 $_pages = $resultArray['deleted']['pages'];
107 unset($resultArray['deleted']['pages']);
108 // To delete sub pages first assuming they are accumulated from top of page tree.
109 $resultArray['deleted']['pages'] = array_reverse($_pages);
110 }
111 // Traversing records:
112 foreach ($resultArray['deleted'] as $table => $list) {
113 echo 'Flushing deleted records from table "' . $table . '":' . LF;
114 foreach ($list as $uid) {
115 echo ' Flushing record "' . $table . ':' . $uid . '": ';
116 if ($bypass = $this->cli_noExecutionCheck($table . ':' . $uid)) {
117 echo $bypass;
118 } else {
119 // Execute CMD array:
120 $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
121 $tce->stripslashes_values = FALSE;
122 $tce->start(array(), array());
123 // Notice, we are deleting pages with no regard to subpages/subrecords - we do this since they
124 // should also be included in the set of deleted pages of course (no un-deleted record can exist
125 // under a deleted page...)
126 $tce->deleteRecord($table, $uid, TRUE, TRUE);
127 // Return errors if any:
128 if (count($tce->errorLog)) {
129 echo ' ERROR from "TCEmain":' . LF . 'TCEmain:' . implode((LF . 'TCEmain:'), $tce->errorLog);
130 } else {
131 echo 'DONE';
132 }
133 }
134 echo LF;
135 }
136 }
137 }
138
139 }
140
141
142 ?>