4 * Support functions for the deleteArchivedFiles script
6 * @addtogroup Maintenance
10 require_once( "$IP/includes/FileStore.php" );
12 function DeleteArchivedFiles( $delete = false ) {
14 # Data should come off the master, wrapped in a transaction
15 $dbw = wfGetDB( DB_MASTER );
18 $transaction = new FSTransaction();
19 if( !FileStore::lock() ) {
20 wfDebug( __METHOD__.": failed to acquire file store lock, aborting\n" );
24 $tbl_arch = $dbw->tableName( 'filearchive' );
26 # Get "active" revisions from the filearchive table
27 echo( "Searching for and deleting archived files...\n" );
28 $res = $dbw->query( "SELECT fa_id,fa_storage_group,fa_storage_key FROM $tbl_arch" );
29 while( $row = $dbw->fetchObject( $res ) ) {
30 $key = $row->fa_storage_key;
31 $group = $row->fa_storage_group;
34 $store = FileStore::get( $group );
36 $path = $store->filePath( $key );
37 if ( $path && file_exists($path) ) {
38 $transaction->addCommit( FSTransaction::DELETE_FILE, $path );
39 $dbw->query( "DELETE FROM $tbl_arch WHERE fa_id = $id" );
41 echo( "Notice - file '$key' not found in group '$group'\n" );
44 echo( "Notice - invalid file storage group '$group'\n" );
49 $transaction->commit();