00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00056 class tx_lowlevel_versions extends tx_lowlevel_cleaner_core {
00057
00063 function tx_lowlevel_versions() {
00064 parent::tx_lowlevel_cleaner_core();
00065
00066
00067 $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.');
00068 $this->cli_options[] = array('--pid id', 'Setting start page in page tree. Default is the page tree root, 0 (zero)');
00069 $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.');
00070
00071 $this->cli_options[] = array('--flush-live', 'If set, not only published versions from Live workspace are flushed, but ALL versions from Live workspace (which are offline of course)');
00072
00073 $this->cli_help['name'] = 'versions -- To find information about versions and workspaces in the system';
00074 $this->cli_help['description'] = trim('
00075 Traversing page tree and finding versions, categorizing them by various properties.
00076 Published versions from the Live workspace are registered. So are all offline versions from Live workspace in general. Further, versions in non-existing workspaces are found.
00077
00078 Automatic Repair:
00079 - Deleting (completely) published versions from LIVE workspace OR _all_ offline versions from Live workspace (toogle by --flush-live)
00080 - Resetting workspace for versions where workspace is deleted. (You might want to run this tool again after this operation to clean out those new elements in the Live workspace)
00081 - Deleting unused placeholders
00082 ');
00083
00084 $this->cli_help['examples'] = '';
00085 }
00086
00093 function main() {
00094 global $TYPO3_DB;
00095
00096
00097 $resultArray = array(
00098 'message' => $this->cli_help['name'].chr(10).chr(10).$this->cli_help['description'],
00099 'headers' => array(
00100 'versions' => array('All versions','Showing all versions of records found',0),
00101 'versions_published' => array('All published versions','This is all records that has been published and can therefore be removed permanently',1),
00102 'versions_liveWS' => array('All versions in Live workspace','This is all records that are offline versions in the Live workspace. You may wish to flush these if you only use workspaces for versioning since then you might find lots of versions piling up in the live workspace which have simply been disconnected from the workspace before they were published.',1),
00103 'versions_lost_workspace' => array('Versions outside a workspace','Versions that has lost their connection to a workspace in TYPO3.',3),
00104 'versions_inside_versioned_page' => array('Versions in versions','Versions inside an already versioned page. Something that is confusing to users and therefore should not happen but is technically possible.',2),
00105 'versions_unused_placeholders' => array('Unused placeholder records','Placeholder records which are not used anymore by offline versions.',2)
00106 ),
00107 'versions' => array(),
00108 );
00109
00110 $startingPoint = $this->cli_isArg('--pid') ? t3lib_div::intInRange($this->cli_argValue('--pid'),0) : 0;
00111 $depth = $this->cli_isArg('--depth') ? t3lib_div::intInRange($this->cli_argValue('--depth'),0) : 1000;
00112 $this->genTree($startingPoint,$depth,(int)$this->cli_argValue('--echotree'));
00113
00114 $resultArray['versions'] = $this->recStats['versions'];
00115 $resultArray['versions_published'] = $this->recStats['versions_published'];
00116 $resultArray['versions_liveWS'] = $this->recStats['versions_liveWS'];
00117 $resultArray['versions_lost_workspace'] = $this->recStats['versions_lost_workspace'];
00118 $resultArray['versions_inside_versioned_page'] = $this->recStats['versions_inside_versioned_page'];
00119
00120
00121 $resultArray['versions_unused_placeholders'] = array();
00122 foreach($GLOBALS['TCA'] as $table => $cfg) {
00123 if ($cfg['ctrl']['versioningWS']) {
00124 $placeHolders = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid,pid',$table,'t3ver_state=1 AND pid>=0'.t3lib_BEfunc::deleteClause($table));
00125 foreach($placeHolders as $phrec) {
00126 if (count(t3lib_BEfunc::selectVersionsOfRecord($table, $phrec['uid'], 'uid'))<=1) {
00127 $resultArray['versions_unused_placeholders'][] = $table.':'.$phrec['uid'];
00128 }
00129 }
00130 }
00131 }
00132
00133 return $resultArray;
00134 }
00135
00143 function main_autoFix($resultArray) {
00144
00145 $kk = $this->cli_isArg('--flush-live') ? 'versions_liveWS' : 'versions_published';
00146
00147
00148 if (isset($resultArray[$kk]['pages'])) {
00149 $_pages = $resultArray[$kk]['pages'];
00150 unset($resultArray[$kk]['pages']);
00151 $resultArray[$kk]['pages'] = $_pages;
00152 }
00153
00154
00155 foreach($resultArray[$kk] as $table => $list) {
00156 echo 'Flushing published records from table "'.$table.'":'.chr(10);
00157 foreach($list as $uid) {
00158 echo ' Flushing record "'.$table.':'.$uid.'": ';
00159
00160 if ($bypass = $this->cli_noExecutionCheck($table.':'.$uid)) {
00161 echo $bypass;
00162 } else {
00163
00164
00165 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
00166 $tce->stripslashes_values = FALSE;
00167 $tce->start(array(),array());
00168 $tce->deleteEl($table,$uid, TRUE, TRUE);
00169
00170
00171 if (count($tce->errorLog)) {
00172 echo ' ERROR from "TCEmain":'.chr(10).'TCEmain:'.implode(chr(10).'TCEmain:',$tce->errorLog);
00173 } else echo 'DONE';
00174 }
00175 echo chr(10);
00176 }
00177 }
00178
00179
00180 foreach($resultArray['versions_lost_workspace'] as $table => $list) {
00181 echo 'Resetting workspace to zero for records from table "'.$table.'":'.chr(10);
00182 foreach($list as $uid) {
00183 echo ' Flushing record "'.$table.':'.$uid.'": ';
00184 if ($bypass = $this->cli_noExecutionCheck($table.':'.$uid)) {
00185 echo $bypass;
00186 } else {
00187 $fields_values = array(
00188 't3ver_wsid' => 0
00189 );
00190 $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table,'uid='.intval($uid),$fields_values);
00191 echo 'DONE';
00192 }
00193 echo chr(10);
00194 }
00195 }
00196
00197
00198 foreach($resultArray['versions_unused_placeholders'] as $recID) {
00199 list($table,$uid) = explode(':',$recID);
00200 echo 'Deleting unused placeholder (soft) "'.$table.':'.$uid.'": ';
00201 if ($bypass = $this->cli_noExecutionCheck($table.':'.$uid)) {
00202 echo $bypass;
00203 } else {
00204
00205
00206 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
00207 $tce->stripslashes_values = FALSE;
00208 $tce->start(array(),array());
00209 $tce->deleteAction($table, $uid);
00210
00211
00212 if (count($tce->errorLog)) {
00213 echo ' ERROR from "TCEmain":'.chr(10).'TCEmain:'.implode(chr(10).'TCEmain:',$tce->errorLog);
00214 } else echo 'DONE';
00215 }
00216 echo chr(10);
00217 }
00218 }
00219 }
00220
00221 ?>