Index: trunk/phase3/maintenance/deleteArchivedFiles.inc |
— | — | @@ -8,49 +8,37 @@ |
9 | 9 | * @author Aaron Schulz |
10 | 10 | */ |
11 | 11 | |
12 | | -require_once( "$IP/includes/FileStore.php" ); |
13 | 12 | require_once( "$IP/includes/filerepo/File.php" ); |
14 | 13 | |
15 | 14 | function DeleteArchivedFiles( $delete = false ) { |
16 | | - |
17 | 15 | # Data should come off the master, wrapped in a transaction |
18 | 16 | $dbw = wfGetDB( DB_MASTER ); |
19 | | - |
20 | | - $transaction = new FSTransaction(); |
21 | | - if( !FileStore::lock() ) { |
22 | | - wfDebug( __METHOD__.": failed to acquire file store lock, aborting\n" ); |
23 | | - return false; |
24 | | - } |
25 | | - |
26 | 17 | $tbl_arch = $dbw->tableName( 'filearchive' ); |
27 | | - |
| 18 | + $repo = RepoGroup::singleton()->getLocalRepo(); |
28 | 19 | # Get "active" revisions from the filearchive table |
29 | 20 | echo( "Searching for and deleting archived files...\n" ); |
30 | 21 | $res = $dbw->query( "SELECT fa_id,fa_storage_group,fa_storage_key FROM $tbl_arch" ); |
| 22 | + $count = 0; |
31 | 23 | while( $row = $dbw->fetchObject( $res ) ) { |
32 | 24 | $key = $row->fa_storage_key; |
33 | 25 | $group = $row->fa_storage_group; |
34 | 26 | $id = $row->fa_id; |
35 | | - |
36 | | - $store = FileStore::get( $group ); |
37 | | - if( $store ) { |
38 | | - $path = $store->filePath( $key ); |
39 | | - $sha1 = substr( $key, 0, strcspn( $key, '.' ) ); |
40 | | - $inuse = $dbw->selectField( 'oldimage', '1', |
41 | | - array( 'oi_sha1' => $sha1, |
42 | | - 'oi_deleted & '.File::DELETED_FILE => File::DELETED_FILE ), |
43 | | - __METHOD__, array( 'FOR UPDATE' ) ); |
44 | | - if ( $path && file_exists($path) && !$inuse ) { |
45 | | - $transaction->addCommit( FSTransaction::DELETE_FILE, $path ); |
46 | | - $dbw->query( "DELETE FROM $tbl_arch WHERE fa_id = $id" ); |
47 | | - } else { |
48 | | - echo( "Notice - file '$key' not found in group '$group'\n" ); |
49 | | - } |
| 27 | + $path = $repo->getZonePath( 'deleted' ).'/'.$repo->getDeletedHashPath($key).$key; |
| 28 | + $sha1 = substr( $key, 0, strcspn( $key, '.' ) ); |
| 29 | + // Check if the file is used anywhere... |
| 30 | + $inuse = $dbw->selectField( 'oldimage', '1', |
| 31 | + array( 'oi_sha1' => $sha1, |
| 32 | + 'oi_deleted & '.File::DELETED_FILE => File::DELETED_FILE ), |
| 33 | + __METHOD__, |
| 34 | + array( 'FOR UPDATE' ) |
| 35 | + ); |
| 36 | + if ( $path && file_exists($path) && !$inuse ) { |
| 37 | + unlink($path); // delete |
| 38 | + $count++; |
| 39 | + $dbw->query( "DELETE FROM $tbl_arch WHERE fa_id = $id" ); |
50 | 40 | } else { |
51 | | - echo( "Notice - invalid file storage group '$group' for file '$key'\n" ); |
| 41 | + echo( "Notice - file '$key' not found in group '$group'\n" ); |
52 | 42 | } |
53 | 43 | } |
54 | | - echo( "done.\n" ); |
55 | | - |
56 | | - $transaction->commit(); |
| 44 | + echo( "Done! [$count file(s)]\n" ); |
57 | 45 | } |