00001 <?php 00002 00011 require_once( "$IP/includes/FileStore.php" ); 00012 require_once( "$IP/includes/filerepo/File.php" ); 00013 00014 function DeleteArchivedFiles( $delete = false ) { 00015 00016 # Data should come off the master, wrapped in a transaction 00017 $dbw = wfGetDB( DB_MASTER ); 00018 00019 $transaction = new FSTransaction(); 00020 if( !FileStore::lock() ) { 00021 wfDebug( __METHOD__.": failed to acquire file store lock, aborting\n" ); 00022 return false; 00023 } 00024 00025 $tbl_arch = $dbw->tableName( 'filearchive' ); 00026 00027 # Get "active" revisions from the filearchive table 00028 echo( "Searching for and deleting archived files...\n" ); 00029 $res = $dbw->query( "SELECT fa_id,fa_storage_group,fa_storage_key FROM $tbl_arch" ); 00030 while( $row = $dbw->fetchObject( $res ) ) { 00031 $key = $row->fa_storage_key; 00032 $group = $row->fa_storage_group; 00033 $id = $row->fa_id; 00034 00035 $store = FileStore::get( $group ); 00036 if( $store ) { 00037 $path = $store->filePath( $key ); 00038 $sha1 = substr( $key, 0, strcspn( $key, '.' ) ); 00039 $inuse = $dbw->selectField( 'oldimage', '1', 00040 array( 'oi_sha1' => $sha1, 00041 'oi_deleted & '.File::DELETED_FILE => File::DELETED_FILE ), 00042 __METHOD__, array( 'FOR UPDATE' ) ); 00043 if ( $path && file_exists($path) && !$inuse ) { 00044 $transaction->addCommit( FSTransaction::DELETE_FILE, $path ); 00045 $dbw->query( "DELETE FROM $tbl_arch WHERE fa_id = $id" ); 00046 } else { 00047 echo( "Notice - file '$key' not found in group '$group'\n" ); 00048 } 00049 } else { 00050 echo( "Notice - invalid file storage group '$group' for file '$key'\n" ); 00051 } 00052 } 00053 echo( "done.\n" ); 00054 00055 $transaction->commit(); 00056 }