Documentation TYPO3 par Ameos

class.missing_files.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_files extends tx_lowlevel_cleaner_core {
00057 
00058         var $checkRefIndex = TRUE;
00059 
00065         function tx_lowlevel_missing_files()    {
00066                 parent::tx_lowlevel_cleaner_core();
00067 
00068                         // Setting up help:
00069                 $this->cli_help['name'] = 'missing_files -- Find all file references from records pointing to a missing (non-existing) file.';
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 - relevant soft reference parsers applied everywhere file references are used inline
00074 
00075 Files may be missing for these reasons (except software bugs):
00076 - someone manually deleted the file inside fileadmin/ or another user maintained folder. If the reference was a soft reference (opposite to a TCEmain managed file relation from "group" type fields), technically it is not an error although it might be a mistake that someone did so.
00077 - someone manually deleted the file inside the uploads/ folder (typically containing managed files) which is an error since no user interaction should take place there.
00078 
00079 Automatic Repair of Errors:
00080 - Managed files (TCA/FlexForm attachments): Will silently remove the reference from the record since the file is missing. For this reason you might prefer a manual approach instead.
00081 - Soft References: Requires manual fix if you consider it an error.
00082 
00083 Manual repair suggestions:
00084 - Managed files: You might be able to locate the file and re-insert it in the correct location. However, no automatic fix can do that for you.
00085 - Soft References: You should investigate each case and edit the content accordingly. A soft reference to a file could be in an HTML image tag (for example <img src="missing_file.jpg" />) and you would have to either remove the whole tag, change the filename or re-create the missing file.
00086 ');
00087 
00088                 $this->cli_help['examples'] = '/.../cli_dispatch.phpsh lowlevel_cleaner missing_files -s -r
00089 This will show you missing files in the TYPO3 system and only report back if errors were found.';
00090         }
00091 
00098         function main() {
00099                 global $TYPO3_DB;
00100 
00101                         // Initialize result array:
00102                 $listExplain = ' Shows the relative filename of missing file as header and under a list of record fields in which the references are found. '.$this->label_infoString;
00103                 $resultArray = array(
00104                         'message' => $this->cli_help['name'].chr(10).chr(10).$this->cli_help['description'],
00105                         'headers' => array(
00106                                 'managedFilesMissing' => array('List of missing files managed by TCEmain', $listExplain, 3),
00107                                 'softrefFilesMissing' => array('List of missing files registered as a soft reference', $listExplain, 2),
00108                         ),
00109                         'managedFilesMissing' => array(),
00110                         'softrefFilesMissing' => array(),
00111                 );
00112 
00113 
00114                         // Select all files in the reference table
00115                 $recs = $TYPO3_DB->exec_SELECTgetRows(
00116                         '*',
00117                         'sys_refindex',
00118                         'ref_table='.$TYPO3_DB->fullQuoteStr('_FILE', 'sys_refindex'),
00119                         '',
00120                         'sorting DESC'
00121                 );
00122 
00123                         // Traverse the files and put into a large table:
00124                 if (is_array($recs)) {
00125                         foreach($recs as $rec)  {
00126 
00127                                         // Compile info string for location of reference:
00128                                 $infoString = $this->infoStr($rec);
00129 
00130                                         // Handle missing file:
00131                                 if (!@is_file(PATH_site.$rec['ref_string']))    {
00132 
00133                                         if ((string)$rec['softref_key']=='')    {
00134                                                 $resultArrayIndex = 'managedFilesMissing';
00135                                         } else {
00136                                                 $resultArrayIndex = 'softrefFilesMissing';
00137                                         }
00138 
00139                                         $resultArray[$resultArrayIndex][$rec['ref_string']][$rec['hash']] = $infoString;
00140                                 }
00141                         }
00142                 }
00143 
00144                 return $resultArray;
00145         }
00146 
00154         function main_autoFix($resultArray)     {
00155                 foreach($resultArray['managedFilesMissing'] as $key => $value)  {
00156                         echo 'Processing file: '.$key.chr(10);
00157                         $c=0;
00158                         foreach($value as $hash => $recReference)       {
00159                                 echo '  Removing reference in record "'.$recReference.'": ';
00160                                 if ($bypass = $this->cli_noExecutionCheck($recReference))       {
00161                                         echo $bypass;
00162                                 } else {
00163                                         $sysRefObj = t3lib_div::makeInstance('t3lib_refindex');
00164                                         $error = $sysRefObj->setReferenceValue($hash,NULL);
00165                                         if ($error)     {
00166                                                 echo '          t3lib_refindex::setReferenceValue(): '.$error.chr(10);
00167                                                 echo 'missing_files: exit on error'.chr(10);
00168                                                 exit;
00169                                         } else echo "DONE";
00170                                 }
00171                                 echo chr(10);
00172                         }
00173                 }
00174         }
00175 }
00176 
00177 ?>


Généré par Les spécialistes TYPO3 avec  doxygen 1.4.6