MediaWiki
REL1_20
|
00001 <?php 00024 require_once( __DIR__ . '/Maintenance.php' ); 00025 00032 class PurgeDeletedFiles extends Maintenance { 00033 public function __construct() { 00034 parent::__construct(); 00035 $this->mDescription = "Scan the logging table and purge files that where deleted."; 00036 $this->addOption( 'starttime', 'Starting timestamp', false, true ); 00037 $this->addOption( 'endtime', 'Ending timestamp', false, true ); 00038 } 00039 00040 public function execute() { 00041 $this->output( "Purging cache and thumbnails for deleted files...\n" ); 00042 $this->purgeFromLogType( 'delete' ); 00043 $this->output( "...deleted files purged.\n\n" ); 00044 00045 $this->output( "Purging cache and thumbnails for suppressed files...\n" ); 00046 $this->purgeFromLogType( 'suppress' ); 00047 $this->output( "...suppressed files purged.\n" ); 00048 } 00049 00050 protected function purgeFromLogType( $logType ) { 00051 $repo = RepoGroup::singleton()->getLocalRepo(); 00052 $db = $repo->getSlaveDB(); 00053 00054 $conds = array( 00055 'log_namespace' => NS_FILE, 00056 'log_type' => $logType, 00057 'log_action' => array( 'delete', 'revision' ) 00058 ); 00059 $start = $this->getOption( 'starttime' ); 00060 if ( $start ) { 00061 $conds[] = 'log_timestamp >= ' . $db->addQuotes( $db->timestamp( $start ) ); 00062 } 00063 $end = $this->getOption( 'endtime' ); 00064 if ( $end ) { 00065 $conds[] = 'log_timestamp <= ' . $db->addQuotes( $db->timestamp( $end ) ); 00066 } 00067 00068 $res = $db->select( 'logging', array( 'log_title', 'log_timestamp' ), $conds, __METHOD__ ); 00069 foreach ( $res as $row ) { 00070 $file = $repo->newFile( Title::makeTitle( NS_FILE, $row->log_title ) ); 00071 00072 // Purge current version and any versions in oldimage table 00073 $file->purgeCache(); 00074 $file->purgeHistory(); 00075 // Purge items from fileachive table (rows are likely here) 00076 $this->purgeFromArchiveTable( $file ); 00077 00078 $this->output( "Purged file {$row->log_title}; deleted on {$row->log_timestamp}.\n" ); 00079 } 00080 } 00081 00082 protected function purgeFromArchiveTable( LocalFile $file ) { 00083 $db = $file->getRepo()->getSlaveDB(); 00084 $res = $db->select( 'filearchive', 00085 array( 'fa_archive_name' ), 00086 array( 'fa_name' => $file->getName() ), 00087 __METHOD__ 00088 ); 00089 foreach ( $res as $row ) { 00090 $file->purgeOldThumbnails( $row->fa_archive_name ); 00091 } 00092 } 00093 } 00094 00095 $maintClass = "PurgeDeletedFiles"; 00096 require_once( RUN_MAINTENANCE_IF_MAIN );