MediaWiki
REL1_19
|
00001 <?php 00028 require_once( dirname( __FILE__ ) . '/Maintenance.php' ); 00029 00030 class UploadStashCleanup extends Maintenance { 00031 00032 public function __construct() { 00033 parent::__construct(); 00034 $this->mDescription = "Clean up abandoned files in temporary uploaded file stash"; 00035 } 00036 00037 public function execute() { 00038 $repo = RepoGroup::singleton()->getLocalRepo(); 00039 00040 $dbr = $repo->getSlaveDb(); 00041 00042 // how far back should this look for files to delete? 00043 global $wgUploadStashMaxAge; 00044 00045 $this->output( "Getting list of files to clean up...\n" ); 00046 $res = $dbr->select( 00047 'uploadstash', 00048 'us_key', 00049 'us_timestamp < ' . $dbr->addQuotes( $dbr->timestamp( time() - $wgUploadStashMaxAge ) ), 00050 __METHOD__ 00051 ); 00052 00053 if( !is_object( $res ) || $res->numRows() == 0 ) { 00054 $this->output( "No files to cleanup!\n" ); 00055 // nothing to do. 00056 return; 00057 } 00058 00059 // finish the read before starting writes. 00060 $keys = array(); 00061 foreach( $res as $row ) { 00062 array_push( $keys, $row->us_key ); 00063 } 00064 00065 $this->output( 'Removing ' . count($keys) . " file(s)...\n" ); 00066 // this could be done some other, more direct/efficient way, but using 00067 // UploadStash's own methods means it's less likely to fall accidentally 00068 // out-of-date someday 00069 $stash = new UploadStash( $repo ); 00070 00071 foreach( $keys as $key ) { 00072 try { 00073 $stash->getFile( $key, true ); 00074 $stash->removeFileNoAuth( $key ); 00075 } catch ( UploadStashBadPathException $ex ) { 00076 $this->output( "Failed removing stashed upload with key: $key\n" ); 00077 } 00078 } 00079 } 00080 } 00081 00082 $maintClass = "UploadStashCleanup"; 00083 require_once( RUN_MAINTENANCE_IF_MAIN );