26 require_once __DIR__ .
'/Maintenance.php';
35 parent::__construct();
37 $this->
addOption(
'delete',
'Perform the deletion' );
38 $this->
addOption(
'force',
'Force deletion of rows from filearchive' );
43 $this->
output(
"Use --delete to actually confirm this script\n" );
47 # Data should come off the master, wrapped in a transaction
52 # Get "active" revisions from the filearchive table
53 $this->
output(
"Searching for and deleting archived files...\n" );
54 $res = $dbw->newSelectQueryBuilder()
55 ->select( [
'fa_id',
'fa_storage_group',
'fa_storage_key',
'fa_sha1',
'fa_name' ] )
56 ->from(
'filearchive' )
57 ->caller( __METHOD__ )
61 foreach ( $res as $row ) {
62 $key = $row->fa_storage_key;
63 if ( !strlen( $key ) ) {
64 $this->
output(
"Entry with ID {$row->fa_id} has empty key, skipping\n" );
68 $file = $repo->newFile( $row->fa_name );
69 $status =
$file->acquireFileLock( 10 );
70 if ( !$status->isOK() ) {
71 $this->
error(
"Could not acquire lock on '{$row->fa_name}', skipping\n" );
75 $group = $row->fa_storage_group;
77 $path = $repo->getZonePath(
'deleted' ) .
78 '/' . $repo->getDeletedHashPath( $key ) . $key;
79 if ( isset( $row->fa_sha1 ) ) {
80 $sha1 = $row->fa_sha1;
87 $inuse = (bool)$dbw->newSelectQueryBuilder()
94 ->caller( __METHOD__ )
99 if ( !$repo->fileExists(
$path ) ) {
100 $this->
output(
"Notice - file '$key' not found in group '$group'\n" );
101 } elseif ( $inuse ) {
102 $this->
output(
"Notice - file '$key' is still in use\n" );
103 } elseif ( !$repo->quickPurge(
$path ) ) {
104 $this->
output(
"Unable to remove file $path, skipping\n" );
105 $file->releaseFileLock();
115 $this->
output(
"Got --force, deleting DB entry\n" );
117 $file->releaseFileLock();
123 $dbw->delete(
'filearchive', [
'fa_id' => $id ], __METHOD__ );
124 $file->releaseFileLock();
128 $this->
output(
"Done! [$count file(s)]\n" );
133 require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance script to delete archived (non-current) files from the database.
__construct()
Default constructor.
execute()
Do the actual work.
static getHashFromKey( $key)
Gets the SHA1 hash from a storage key.
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.
error( $err, $die=0)
Throw an error to the user.
beginTransaction(IDatabase $dbw, $fname)
Begin a transaction on a DB.
commitTransaction(IDatabase $dbw, $fname)
Commit the transaction on a DB handle and wait for replica DBs to catch up.
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.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.