Documentation TYPO3 par Ameos

class.missing_relations.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00056 class tx_lowlevel_missing_relations extends tx_lowlevel_cleaner_core {
00057 
00058         var $checkRefIndex = TRUE;
00059 
00065         function tx_lowlevel_missing_relations()        {
00066                 parent::tx_lowlevel_cleaner_core();
00067 
00068                         // Setting up help:
00069                 $this->cli_help['name'] = 'missing_relations -- Find all record references pointing to a non-existing record.';
00070                 $this->cli_help['description'] = trim('
00071 Assumptions:
00072 - a perfect integrity of the reference index table (always update the reference index table before using this tool!)
00073 - all database references to check are integers greater than zero
00074 - does not check if a referenced record is inside an offline branch, another workspace etc. which could make the reference useless in reality or otherwise question integrity
00075 Records may be missing for these reasons (except software bugs):
00076 - someone deleted the record which is technically not an error although it might be a mistake that someone did so.
00077 - after flushing published versions and/or deleted-flagged records a number of new missing references might appear; those were pointing to records just flushed.
00078 
00079 Automatic Repair of Errors:
00080 - Only managed references are repaired (TCA-configured).
00081 - Offline Version Records and Non Existing Records: Reference is removed
00082 
00083 Manual repair suggestions:
00084 - For soft references you should investigate each case and edit the content accordingly.
00085 - References to deleted records can theoretically be removed since a deleted record cannot be selected and hence your website should not be affected by removal of the reference. On the other hand it does not hurt to ignore it for now. To have this automatically fixed you must first flush the deleted records after which remaining references will appear as pointing to Non Existing Records and can now be removed with the automatic fix.
00086 
00087 NOTICE: Uses the Reference Index Table (sys_refindex) for analysis. Update it before use!
00088 ');
00089 
00090                 $this->cli_help['examples'] = '/.../cli_dispatch.phpsh lowlevel_cleaner missing_relations -s -r
00091 Reports missing relations';
00092         }
00093 
00094 
00101         function main() {
00102                 global $TYPO3_DB;
00103 
00104                         // Initialize result array:
00105                 $listExplain = ' Shows the missing record as header and underneath a list of record fields in which the references are found. '.$this->label_infoString;
00106                 $resultArray = array(
00107                         'message' => $this->cli_help['name'].chr(10).chr(10).$this->cli_help['description'],
00108                         'headers' => array(
00109                                 'offlineVersionRecords_m' => array('Offline version records (managed)','These records are offline versions having a pid=-1 and references should never occur directly to their uids.'.$listExplain,3),
00110                                 'deletedRecords_m' => array('Deleted-flagged records (managed)','These records are deleted with a flag but references are still pointing at them. Keeping the references is useful if you undelete the referenced records later, otherwise the references are lost completely when the deleted records are flushed at some point. Notice that if those records listed are themselves deleted (marked with "DELETED") it is not a problem.'.$listExplain,2),
00111                                 'nonExistingRecords_m' => array('Non-existing records to which there are references (managed)','These references can safely be removed since there is no record found in the database at all.'.$listExplain,3), // 3 = error
00112                                 'offlineVersionRecords_s' => array('Offline version records (softref)','See above.'.$listExplain,2),
00113                                 'deletedRecords_s' => array('Deleted-flagged records (softref)','See above.'.$listExplain,2),
00114                                 'nonExistingRecords_s' => array('Non-existing records to which there are references (softref)','See above.'.$listExplain,2),
00115                         ),
00116                         'offlineVersionRecords_m' => array(),
00117                         'deletedRecords_m' => array(),
00118                         'nonExistingRecords_m' => array(),
00119                         'offlineVersionRecords_s' => array(),
00120                         'deletedRecords_s' => array(),
00121                         'nonExistingRecords_s' => array(),
00122                 );
00123 
00124                         // Select DB relations from reference table
00125                 $recs = $TYPO3_DB->exec_SELECTgetRows(
00126                         '*',
00127                         'sys_refindex',
00128                         'ref_table!='.$TYPO3_DB->fullQuoteStr('_FILE', 'sys_refindex'). // Assuming that any other key will be a table name!
00129                         ' AND ref_uid>0'.
00130                         $filterClause,
00131                         '',
00132                         'sorting DESC'
00133                 );
00134 
00135                         // Traverse the records
00136                 $tempExists = array();
00137                 if (is_array($recs)) {
00138                         foreach($recs as $rec)  {
00139                                 $suffix = $rec['softref_key']!='' ? '_s' : '_m';
00140                                 $idx = $rec['ref_table'].':'.$rec['ref_uid'];
00141 
00142                                         // Get referenced record:
00143                                 if (!isset($tempExists[$idx]))  {
00144                                         $tempExists[$idx] = t3lib_BEfunc::getRecordRaw($rec['ref_table'],'uid='.intval($rec['ref_uid']),'uid,pid'.($GLOBALS['TCA'][$rec['ref_table']]['ctrl']['delete'] ? ','.$GLOBALS['TCA'][$rec['ref_table']]['ctrl']['delete'] : ''));
00145                                 }
00146 
00147                                         // Compile info string for location of reference:
00148                                 $infoString = $this->infoStr($rec);
00149 
00150                                         // Handle missing file:
00151                                 if ($tempExists[$idx]['uid'])   {
00152                                         if ($tempExists[$idx]['pid']==-1)       {
00153                                                 $resultArray['offlineVersionRecords'.$suffix][$idx][$rec['hash']] = $infoString;
00154                                         } elseif ($GLOBALS['TCA'][$rec['ref_table']]['ctrl']['delete'] && $tempExists[$idx][$GLOBALS['TCA'][$rec['ref_table']]['ctrl']['delete']])      {
00155                                                 $resultArray['deletedRecords'.$suffix][$idx][$rec['hash']] = $infoString;
00156                                         }
00157                                 } else {
00158                                         $resultArray['nonExistingRecords'.$suffix][$idx][$rec['hash']] = $infoString;
00159                                 }
00160                         }
00161                 }
00162 
00163                 return $resultArray;
00164         }
00165 
00173         function main_autoFix($resultArray)     {
00174 
00175                 $trav = array('offlineVersionRecords_m', 'nonExistingRecords_m');
00176                 foreach($trav as $tk)   {
00177                         echo 'Processing managed "'.$tk.'"...'.chr(10);
00178                         foreach($resultArray[$tk] as $key => $value)    {
00179                                 foreach($value as $hash => $recReference)       {
00180                                         echo '  Removing reference to '.$key.' in record "'.$recReference.'": ';
00181                                         if ($bypass = $this->cli_noExecutionCheck($recReference))       {
00182                                                 echo $bypass;
00183                                         } else {
00184                                                 $sysRefObj = t3lib_div::makeInstance('t3lib_refindex');
00185                                                 $error = $sysRefObj->setReferenceValue($hash,NULL);
00186                                                 if ($error)     {
00187                                                         echo '          t3lib_refindex::setReferenceValue(): '.$error.chr(10);
00188                                                 } else echo 'DONE';
00189                                         }
00190                                         echo chr(10);
00191                                 }
00192                         }
00193                 }
00194         }
00195 }
00196 
00197 ?>


Généré par TYPO3 Ameos avec  doxygen 1.4.6