When saving preferences, check hook and authentication plugin, and actually save...
[mediawiki.git] / maintenance / deleteArchivedFiles.inc
blob32ddf4c82a2ad645a18b062fd3593e46b5ecf8fc
1 <?php
3 /**
4  * Support functions for the deleteArchivedFiles script
5  *
6  * @addtogroup Maintenance
7  * @author Aaron Schulz
8  */
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 );
16         $dbw->begin();
17         
18         $transaction = new FSTransaction();
19         if( !FileStore::lock() ) {
20                 wfDebug( __METHOD__.": failed to acquire file store lock, aborting\n" );
21                 return false;
22         }
23         
24         $tbl_arch = $dbw->tableName( 'filearchive' );
25         
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;
32                 $id = $row->fa_id;
33                 
34                 $store = FileStore::get( $group );
35                 if ( $store ) {
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" );
40                         } else {
41                                 echo( "Notice - file '$key' not found in group '$group'\n" );
42                         }
43                 } else {
44                         echo( "Notice - invalid file storage group '$group'\n" );
45                 }
46         }
47         echo( "done.\n" );
48         
49         $transaction->commit();
50         
51         # This bit's done
52         $dbw->commit();