26 require_once __DIR__ .
'/Maintenance.php';
38 parent::__construct();
40 $this->
addOption(
'delete',
'Perform the deletion' );
41 $this->
addOption(
'filename',
'File name',
false,
true );
42 $this->
addOption(
'filekey',
'File storage key (with extension) or "*"',
true,
true );
47 $this->
output(
"Use --delete to actually confirm this script\n" );
51 $filename = $this->
getOption(
'filename' );
53 if ( $filekey ===
'*' ) {
55 if ( !strlen( $filename ) ) {
56 $this->
fatalError(
"Missing --filename parameter." );
63 $row = $dbw->newSelectQueryBuilder()
64 ->select( $fileQuery[
'fields'] )
65 ->tables( $fileQuery[
'tables'] )
67 'fa_storage_group' =>
'deleted',
68 'fa_storage_key' => $filekey
70 ->joinConds( $fileQuery[
'joins'] )
71 ->caller( __METHOD__ )
75 $this->
fatalError(
"No deleted file exists with key '$filekey'." );
77 $filename = $row->fa_name;
81 $file = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()->newFile( $filename );
82 if (
$file->exists() ) {
83 $this->
fatalError(
"File '$filename' is still a public file, use the delete form.\n" );
86 $this->
output(
"Purging all thumbnails for file '$filename'..." );
88 $this->
output(
"done.\n" );
93 $this->
output(
"Finding deleted versions of file '$filename'...\n" );
102 $res = $dbw->newSelectQueryBuilder()
103 ->select( $fileQuery[
'fields'] )
104 ->tables( $fileQuery[
'tables'] )
107 'fa_storage_group' =>
'deleted'
109 ->joinConds( $fileQuery[
'joins'] )
110 ->caller( __METHOD__ )
112 foreach (
$res as $row ) {
119 $name = $archivedFile->
getName();
121 $repo = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo();
122 $path = $repo->getZonePath(
'deleted' ) .
'/' . $repo->getDeletedHashPath( $key ) . $key;
124 $status = $repo->getBackend()->delete( [
'src' =>
$path ] );
125 if ( $status->isOK() ) {
126 $this->
output(
"Deleted version '$key' ($ts) of file '$name'\n" );
128 $this->
output(
"Failed to delete version '$key' ($ts) of file '$name'\n" );
132 $this->
output(
"Would delete version '{$key}' ({$ts}) of file '$name'\n" );
138 require_once RUN_MAINTENANCE_IF_MAIN;
Deleted file in the 'filearchive' table.
getTimestamp()
Return upload timestamp.
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new archivedfile object.
static newFromRow( $row)
Loads a file object from the filearchive table.
getStorageKey()
Return the FileStore key (overriding base File class)
getName()
Return the file name.
Maintenance script to delete archived (non-current) files from storage.
scrubVersion(ArchivedFile $archivedFile)
execute()
Do the actual work.
__construct()
Default constructor.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
static wrap( $sv)
Succinct helper method to wrap a StatusValue.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.