From 9db190c7e736ec8d063187d4241b59feaf7dc2d1 Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Wed, 22 Jun 2011 11:28:20 +0200 Subject: update to MediaWiki 1.17.0 --- maintenance/deleteArchivedFiles.inc | 62 +++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 maintenance/deleteArchivedFiles.inc (limited to 'maintenance/deleteArchivedFiles.inc') diff --git a/maintenance/deleteArchivedFiles.inc b/maintenance/deleteArchivedFiles.inc new file mode 100644 index 00000000..e0ac225e --- /dev/null +++ b/maintenance/deleteArchivedFiles.inc @@ -0,0 +1,62 @@ +begin(); + $tbl_arch = $dbw->tableName( 'filearchive' ); + $repo = RepoGroup::singleton()->getLocalRepo(); + # Get "active" revisions from the filearchive table + $output->handleOutput( "Searching for and deleting archived files...\n" ); + $res = $dbw->query( "SELECT fa_id,fa_storage_group,fa_storage_key FROM $tbl_arch" ); + $count = 0; + foreach ( $res as $row ) { + $key = $row->fa_storage_key; + $group = $row->fa_storage_group; + $id = $row->fa_id; + $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key; + $sha1 = substr( $key, 0, strcspn( $key, '.' ) ); + // Check if the file is used anywhere... + $inuse = $dbw->selectField( 'oldimage', '1', + array( 'oi_sha1' => $sha1, + 'oi_deleted & ' . File::DELETED_FILE => File::DELETED_FILE ), + __METHOD__, + array( 'FOR UPDATE' ) + ); + if ( $path && file_exists( $path ) && !$inuse ) { + unlink( $path ); // delete + $count++; + $dbw->query( "DELETE FROM $tbl_arch WHERE fa_id = $id" ); + } else { + $output->handleOutput( "Notice - file '$key' not found in group '$group'\n" ); + if ( $force ) { + $output->handleOutput( "Got --force, deleting DB entry\n" ); + $dbw->query( "DELETE FROM $tbl_arch WHERE fa_id = $id" ); + } + } + } + $dbw->commit(); + $output->handleOutput( "Done! [$count file(s)]\n" ); + } +} \ No newline at end of file -- cgit v1.2.3-54-g00ecf