29require_once __DIR__ .
'/Maintenance.php';
42 parent::__construct();
44 $this->
addOption(
'delete',
'Perform the deletion' );
45 $this->
addOption(
'filename',
'File name',
false,
true );
46 $this->
addOption(
'filekey',
'File storage key (with extension) or "*"',
true,
true );
51 $this->
output(
"Use --delete to actually confirm this script\n" );
55 $filename = $this->
getOption(
'filename' );
57 if ( $filekey ===
'*' ) {
59 if ( $filename ===
null || $filename ===
'' ) {
60 $this->
fatalError(
"Missing --filename parameter." );
66 $queryBuilder = FileSelectQueryBuilder::newForArchivedFile( $dbw );
67 $queryBuilder->where( [
'fa_storage_group' =>
'deleted',
'fa_storage_key' => $filekey ] );
68 $row = $queryBuilder->caller( __METHOD__ )->fetchRow();
71 $this->
fatalError(
"No deleted file exists with key '$filekey'." );
73 $filename = $row->fa_name;
74 $afile = ArchivedFile::newFromRow( $row );
78 if ( $file->exists() ) {
79 $this->
fatalError(
"File '$filename' is still a public file, use the delete form.\n" );
82 $this->
output(
"Purging all thumbnails for file '$filename'..." );
84 $this->
output(
"done.\n" );
89 $this->
output(
"Finding deleted versions of file '$filename'...\n" );
97 $queryBuilder = FileSelectQueryBuilder::newForArchivedFile( $dbw );
98 $queryBuilder->where( [
'fa_name' => $name,
'fa_storage_group' =>
'deleted' ] );
99 $res = $queryBuilder->caller( __METHOD__ )->fetchResultSet();
100 foreach ( $res as $row ) {
101 $this->
scrubVersion( ArchivedFile::newFromRow( $row ) );
107 $name = $archivedFile->
getName();
110 $path = $repo->getZonePath(
'deleted' ) .
'/' . $repo->getDeletedHashPath( $key ) . $key;
112 $status = $repo->getBackend()->delete( [
'src' =>
$path ] );
113 if ( $status->isOK() ) {
114 $this->
output(
"Deleted version '$key' ($ts) of file '$name'\n" );
116 $this->
output(
"Failed to delete version '$key' ($ts) of file '$name'\n" );
117 $this->
error( $status );
120 $this->
output(
"Would delete version '{$key}' ({$ts}) of file '$name'\n" );
127require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance script to delete archived (non-current) files from storage.
scrubVersion(ArchivedFile $archivedFile)
scrubAllVersions(string $name)
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.