27 require_once __DIR__ .
'/Maintenance.php';
39 parent::__construct();
41 $this->
addOption(
'delete',
'Perform the deletion' );
42 $this->
addOption(
'filename',
'File name',
false,
true );
43 $this->
addOption(
'filekey',
'File storage key (with extension) or "*"',
true,
true );
48 $this->
output(
"Use --delete to actually confirm this script\n" );
52 $filename = $this->
getOption(
'filename' );
54 if ( $filekey ===
'*' ) {
56 if ( !strlen( $filename ) ) {
57 $this->
fatalError(
"Missing --filename parameter." );
63 $queryBuilder = FileSelectQueryBuilder::newForArchivedFile( $dbw );
64 $queryBuilder->where( [
'fa_storage_group' =>
'deleted',
'fa_storage_key' => $filekey ] );
65 $row = $queryBuilder->caller( __METHOD__ )->fetchRow();
68 $this->
fatalError(
"No deleted file exists with key '$filekey'." );
70 $filename = $row->fa_name;
75 if (
$file->exists() ) {
76 $this->
fatalError(
"File '$filename' is still a public file, use the delete form.\n" );
79 $this->
output(
"Purging all thumbnails for file '$filename'..." );
81 $this->
output(
"done.\n" );
86 $this->
output(
"Finding deleted versions of file '$filename'...\n" );
94 $queryBuilder = FileSelectQueryBuilder::newForArchivedFile( $dbw );
95 $queryBuilder->where( [
'fa_name' => $name,
'fa_storage_group' =>
'deleted' ] );
96 $res = $queryBuilder->caller( __METHOD__ )->fetchResultSet();
97 foreach ( $res as $row ) {
104 $name = $archivedFile->
getName();
107 $path = $repo->getZonePath(
'deleted' ) .
'/' . $repo->getDeletedHashPath( $key ) . $key;
109 $status = $repo->getBackend()->delete( [
'src' =>
$path ] );
110 if ( $status->isOK() ) {
111 $this->
output(
"Deleted version '$key' ($ts) of file '$name'\n" );
113 $this->
output(
"Failed to delete version '$key' ($ts) of file '$name'\n" );
114 $this->
output( print_r( Status::wrap( $status )->getErrorsArray(),
true ) );
117 $this->
output(
"Would delete version '{$key}' ({$ts}) of file '$name'\n" );
123 require_once RUN_MAINTENANCE_IF_MAIN;
Deleted file in the 'filearchive' table.
getTimestamp()
Return upload timestamp.
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.
getServiceContainer()
Returns the main service container.
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.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.