28require_once __DIR__ .
'/Maintenance.php';
41 parent::__construct();
43 $this->
addOption(
'delete',
'Perform the deletion' );
44 $this->
addOption(
'filename',
'File name',
false,
true );
45 $this->
addOption(
'filekey',
'File storage key (with extension) or "*"',
true,
true );
50 $this->
output(
"Use --delete to actually confirm this script\n" );
54 $filename = $this->
getOption(
'filename' );
56 if ( $filekey ===
'*' ) {
58 if ( $filename ===
null || $filename ===
'' ) {
59 $this->
fatalError(
"Missing --filename parameter." );
65 $queryBuilder = FileSelectQueryBuilder::newForArchivedFile( $dbw );
66 $queryBuilder->where( [
'fa_storage_group' =>
'deleted',
'fa_storage_key' => $filekey ] );
67 $row = $queryBuilder->caller( __METHOD__ )->fetchRow();
70 $this->
fatalError(
"No deleted file exists with key '$filekey'." );
72 $filename = $row->fa_name;
73 $afile = ArchivedFile::newFromRow( $row );
77 if ( $file->exists() ) {
78 $this->
fatalError(
"File '$filename' is still a public file, use the delete form.\n" );
81 $this->
output(
"Purging all thumbnails for file '$filename'..." );
83 $this->
output(
"done.\n" );
88 $this->
output(
"Finding deleted versions of file '$filename'...\n" );
96 $queryBuilder = FileSelectQueryBuilder::newForArchivedFile( $dbw );
97 $queryBuilder->where( [
'fa_name' => $name,
'fa_storage_group' =>
'deleted' ] );
98 $res = $queryBuilder->caller( __METHOD__ )->fetchResultSet();
99 foreach ( $res as $row ) {
100 $this->
scrubVersion( ArchivedFile::newFromRow( $row ) );
106 $name = $archivedFile->
getName();
109 $path = $repo->getZonePath(
'deleted' ) .
'/' . $repo->getDeletedHashPath( $key ) . $key;
111 $status = $repo->getBackend()->delete( [
'src' =>
$path ] );
112 if ( $status->isOK() ) {
113 $this->
output(
"Deleted version '$key' ($ts) of file '$name'\n" );
115 $this->
output(
"Failed to delete version '$key' ($ts) of file '$name'\n" );
116 $this->
error( $status );
119 $this->
output(
"Would delete version '{$key}' ({$ts}) of file '$name'\n" );
126require_once RUN_MAINTENANCE_IF_MAIN;
Deleted file in the 'filearchive' table.
getTimestamp()
Return upload timestamp.
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...
output( $out, $channel=null)
Throw some output to the user.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
error( $err, $die=0)
Throw an error to the user.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.