MediaWiki  1.23.8
deleteArchivedFiles.inc
Go to the documentation of this file.
1 <?php
30  public static function doDelete( $output, $force ) {
31  # Data should come off the master, wrapped in a transaction
32  $dbw = wfGetDB( DB_MASTER );
33  $dbw->begin( __METHOD__ );
34  $tbl_arch = $dbw->tableName( 'filearchive' );
35  $repo = RepoGroup::singleton()->getLocalRepo();
36  # Get "active" revisions from the filearchive table
37  $output->handleOutput( "Searching for and deleting archived files...\n" );
38  $res = $dbw->query( "SELECT fa_id,fa_storage_group,fa_storage_key,fa_sha1 FROM $tbl_arch" );
39  $count = 0;
40  foreach ( $res as $row ) {
41  $key = $row->fa_storage_key;
42  $group = $row->fa_storage_group;
43  $id = $row->fa_id;
44  $path = $repo->getZonePath( 'deleted' ) . '/' . $repo->getDeletedHashPath( $key ) . $key;
45  if ( isset( $row->fa_sha1 ) ) {
46  $sha1 = $row->fa_sha1;
47  } else {
48  // old row, populate from key
49  $sha1 = LocalRepo::getHashFromKey( $key );
50  }
51  // Check if the file is used anywhere...
52  $inuse = $dbw->selectField( 'oldimage', '1',
53  array( 'oi_sha1' => $sha1,
54  'oi_deleted & ' . File::DELETED_FILE => File::DELETED_FILE ),
55  __METHOD__,
56  array( 'FOR UPDATE' )
57  );
58  if ( $path && $repo->fileExists( $path ) && !$inuse ) {
59  if ( $repo->quickPurge( $path ) ) {
60  $count++;
61  $dbw->query( "DELETE FROM $tbl_arch WHERE fa_id = $id" );
62  } else {
63  $output->handleOutput( "Unable to remove file $path, skipping\n" );
64  }
65  } else {
66  $output->handleOutput( "Notice - file '$key' not found in group '$group'\n" );
67  if ( $force ) {
68  $output->handleOutput( "Got --force, deleting DB entry\n" );
69  $dbw->query( "DELETE FROM $tbl_arch WHERE fa_id = $id" );
70  }
71  }
72  }
73  $dbw->commit( __METHOD__ );
74  $output->handleOutput( "Done! [$count file(s)]\n" );
75  }
76 }
DB_MASTER
const DB_MASTER
Definition: Defines.php:56
RepoGroup\singleton
static singleton()
Get a RepoGroup instance.
Definition: RepoGroup.php:53
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3659
LocalRepo\getHashFromKey
static getHashFromKey( $key)
Gets the SHA1 hash from a storage key.
Definition: LocalRepo.php:156
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
DeleteArchivedFilesImplementation
Core functions for deleteArchivedFiles.php.
Definition: deleteArchivedFiles.inc:29
DeleteArchivedFilesImplementation\doDelete
static doDelete( $output, $force)
Definition: deleteArchivedFiles.inc:30
$count
$count
Definition: UtfNormalTest2.php:96
$output
& $output
Definition: hooks.txt:375
$path
$path
Definition: NoLocalSettings.php:35
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
File\DELETED_FILE
const DELETED_FILE
Definition: File.php:52
$res
$res
Definition: database.txt:21