r53528 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53527‎ | r53528 | r53529 >
Date:05:16, 20 July 2009
Author:aaron
Status:resolved
Tags:
Comment:
Update deleteArchivedFiles.inc to use FileRepo (FileStore was removed)
Modified paths:
  • /trunk/phase3/maintenance/deleteArchivedFiles.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/deleteArchivedFiles.inc
@@ -8,49 +8,37 @@
99 * @author Aaron Schulz
1010 */
1111
12 -require_once( "$IP/includes/FileStore.php" );
1312 require_once( "$IP/includes/filerepo/File.php" );
1413
1514 function DeleteArchivedFiles( $delete = false ) {
16 -
1715 # Data should come off the master, wrapped in a transaction
1816 $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 -
2617 $tbl_arch = $dbw->tableName( 'filearchive' );
27 -
 18+ $repo = RepoGroup::singleton()->getLocalRepo();
2819 # Get "active" revisions from the filearchive table
2920 echo( "Searching for and deleting archived files...\n" );
3021 $res = $dbw->query( "SELECT fa_id,fa_storage_group,fa_storage_key FROM $tbl_arch" );
 22+ $count = 0;
3123 while( $row = $dbw->fetchObject( $res ) ) {
3224 $key = $row->fa_storage_key;
3325 $group = $row->fa_storage_group;
3426 $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" );
5040 } else {
51 - echo( "Notice - invalid file storage group '$group' for file '$key'\n" );
 41+ echo( "Notice - file '$key' not found in group '$group'\n" );
5242 }
5343 }
54 - echo( "done.\n" );
55 -
56 - $transaction->commit();
 44+ echo( "Done! [$count file(s)]\n" );
5745 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r60047Remove fixme, done since r53528ialex20:58, 14 December 2009

Status & tagging log