Update deleteArchivedFiles.inc to use FileRepo (FileStore was removed)
[lhc/web/wiklou.git] / maintenance / deleteArchivedFiles.inc
1 <?php
2
3 /**
4 * Support functions for the deleteArchivedFiles script
5 *
6 * @file
7 * @ingroup Maintenance
8 * @author Aaron Schulz
9 */
10
11 require_once( "$IP/includes/filerepo/File.php" );
12
13 function DeleteArchivedFiles( $delete = false ) {
14 # Data should come off the master, wrapped in a transaction
15 $dbw = wfGetDB( DB_MASTER );
16 $tbl_arch = $dbw->tableName( 'filearchive' );
17 $repo = RepoGroup::singleton()->getLocalRepo();
18 # Get "active" revisions from the filearchive table
19 echo( "Searching for and deleting archived files...\n" );
20 $res = $dbw->query( "SELECT fa_id,fa_storage_group,fa_storage_key FROM $tbl_arch" );
21 $count = 0;
22 while( $row = $dbw->fetchObject( $res ) ) {
23 $key = $row->fa_storage_key;
24 $group = $row->fa_storage_group;
25 $id = $row->fa_id;
26 $path = $repo->getZonePath( 'deleted' ).'/'.$repo->getDeletedHashPath($key).$key;
27 $sha1 = substr( $key, 0, strcspn( $key, '.' ) );
28 // Check if the file is used anywhere...
29 $inuse = $dbw->selectField( 'oldimage', '1',
30 array( 'oi_sha1' => $sha1,
31 'oi_deleted & '.File::DELETED_FILE => File::DELETED_FILE ),
32 __METHOD__,
33 array( 'FOR UPDATE' )
34 );
35 if ( $path && file_exists($path) && !$inuse ) {
36 unlink($path); // delete
37 $count++;
38 $dbw->query( "DELETE FROM $tbl_arch WHERE fa_id = $id" );
39 } else {
40 echo( "Notice - file '$key' not found in group '$group'\n" );
41 }
42 }
43 echo( "Done! [$count file(s)]\n" );
44 }