31require_once __DIR__ .
'/Maintenance.php';
41 parent::__construct();
43 $this->
addOption(
'delete',
'Perform the deletion' );
44 $this->
addOption(
'force',
'Force deletion of rows from filearchive' );
49 $this->
output(
"Use --delete to actually confirm this script\n" );
53 # Data should come off the master, wrapped in a transaction
58 # Get "active" revisions from the filearchive table
59 $this->
output(
"Searching for and deleting archived files...\n" );
60 $res = $dbw->newSelectQueryBuilder()
61 ->select( [
'fa_id',
'fa_storage_group',
'fa_storage_key',
'fa_sha1',
'fa_name' ] )
62 ->from(
'filearchive' )
63 ->caller( __METHOD__ )
67 foreach ( $res as $row ) {
68 $key = $row->fa_storage_key;
70 $this->
output(
"Entry with ID {$row->fa_id} has empty key, skipping\n" );
74 $file = $repo->newFile( $row->fa_name );
75 $status = $file->acquireFileLock( 10 );
76 if ( !$status->isOK() ) {
77 $this->
error(
"Could not acquire lock on '{$row->fa_name}', skipping\n" );
81 $group = $row->fa_storage_group;
83 $path = $repo->getZonePath(
'deleted' ) .
84 '/' . $repo->getDeletedHashPath( $key ) . $key;
85 if ( isset( $row->fa_sha1 ) ) {
86 $sha1 = $row->fa_sha1;
89 $sha1 = LocalRepo::getHashFromKey( $key );
93 $inuse = (bool)$dbw->newSelectQueryBuilder()
98 $dbw->bitAnd(
'oi_deleted', File::DELETED_FILE ) => File::DELETED_FILE
100 ->caller( __METHOD__ )
105 if ( !$repo->fileExists(
$path ) ) {
106 $this->
output(
"Notice - file '$key' not found in group '$group'\n" );
107 } elseif ( $inuse ) {
108 $this->
output(
"Notice - file '$key' is still in use\n" );
109 } elseif ( !$repo->quickPurge(
$path ) ) {
110 $this->
output(
"Unable to remove file $path, skipping\n" );
111 $file->releaseFileLock();
121 $this->
output(
"Got --force, deleting DB entry\n" );
123 $file->releaseFileLock();
129 $dbw->newDeleteQueryBuilder()
130 ->deleteFrom(
'filearchive' )
131 ->where( [
'fa_id' => $id ] )
132 ->caller( __METHOD__ )->execute();
133 $file->releaseFileLock();
137 $this->
output(
"Done! [$count file(s)]\n" );
143require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance script to delete archived (non-current) files from the database.
__construct()
Default constructor.
execute()
Do the actual work.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
commitTransaction(IDatabase $dbw, $fname)
Commit the transaction on a DB handle and wait for replica DB servers to catch up.
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.
beginTransaction(IDatabase $dbw, $fname)
Begin a transaction on a DB handle.
error( $err, $die=0)
Throw an error to the user.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.