14require_once __DIR__ .
'/Maintenance.php';
24 parent::__construct();
25 $this->
addDescription(
'Delete old (non-current) revisions from the database' );
26 $this->
addOption(
'delete',
'Actually perform the deletion' );
27 $this->
addArg(
'page_id',
'List of page ids to work on',
false,
true );
31 $this->
output(
"Delete old revisions\n\n" );
32 $this->doDelete( $this->
hasOption(
'delete' ), $this->
getArgs(
'page_id' ) );
35 private function doDelete(
bool $delete =
false, array $pageIds = [] ) {
36 # Data should come off the master, wrapped in a transaction
43 # If a list of page_ids was provided, limit results to that set of page_ids
44 if ( count( $pageIds ) > 0 ) {
45 $pageConds[
'page_id'] = $pageIds;
46 $revConds[
'rev_page'] = $pageIds;
47 $this->
output(
"Limiting to page IDs " . implode(
',', $pageIds ) .
"\n" );
50 # Get "active" revisions from the page table
51 $this->
output(
"Searching for active revisions..." );
52 $latestRevs = $dbw->newSelectQueryBuilder()
53 ->select(
'page_latest' )
56 ->caller( __METHOD__ )
58 $this->
output(
"done.\n" );
60 # Get all revisions that aren't in this set
61 $this->
output(
"Searching for inactive revisions..." );
62 if ( count( $latestRevs ) > 0 ) {
63 $revConds[] = $dbw->expr(
'rev_id',
'!=', $latestRevs );
65 $oldRevs = $dbw->newSelectQueryBuilder()
69 ->caller( __METHOD__ )
71 $this->
output(
"done.\n" );
73 # Inform the user of what we're going to do
74 $count = count( $oldRevs );
75 $this->
output(
"$count old revisions found.\n" );
77 # Delete as appropriate
78 if ( $delete && $count ) {
79 $this->
output(
"Deleting..." );
80 $dbw->newDeleteQueryBuilder()
81 ->deleteFrom(
'revision' )
82 ->where( [
'rev_id' => $oldRevs ] )
83 ->caller( __METHOD__ )->execute();
84 $dbw->newDeleteQueryBuilder()
85 ->deleteFrom(
'ip_changes' )
86 ->where( [
'ipc_rev_id' => $oldRevs ] )
87 ->caller( __METHOD__ )->execute();
88 $this->
output(
"done.\n" );
91 # Purge redundant text records
101require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance script that deletes old (non-current) revisions from the database.
execute()
Do the actual work.
__construct()
Default constructor.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
addArg( $arg, $description, $required=true, $multi=false)
Add some args that are needed.
output( $out, $channel=null)
Throw some output to the user.
getArgs( $offset=0)
Get arguments.
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.
commitTransactionRound( $fname)
Commit a transactional batch of DB operations and wait for replica DB servers to catch up.
purgeRedundantText( $delete=true)
Support function for cleaning up redundant text records.
beginTransactionRound( $fname)
Start a transactional batch of DB operations.
getPrimaryDB(string|false $virtualDomain=false)
addDescription( $text)
Set the description text.