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 $res = $dbw->newSelectQueryBuilder()
53 ->select(
'page_latest' )
56 ->caller( __METHOD__ )
59 foreach ( $res as $row ) {
60 $latestRevs[] = $row->page_latest;
62 $this->
output(
"done.\n" );
64 # Get all revisions that aren't in this set
65 $this->
output(
"Searching for inactive revisions..." );
66 if ( count( $latestRevs ) > 0 ) {
67 $revConds[] = $dbw->expr(
'rev_id',
'!=', $latestRevs );
69 $res = $dbw->newSelectQueryBuilder()
73 ->caller( __METHOD__ )
76 foreach ( $res as $row ) {
77 $oldRevs[] = $row->rev_id;
79 $this->
output(
"done.\n" );
81 # Inform the user of what we're going to do
82 $count = count( $oldRevs );
83 $this->
output(
"$count old revisions found.\n" );
85 # Delete as appropriate
86 if ( $delete && $count ) {
87 $this->
output(
"Deleting..." );
88 $dbw->newDeleteQueryBuilder()
89 ->deleteFrom(
'revision' )
90 ->where( [
'rev_id' => $oldRevs ] )
91 ->caller( __METHOD__ )->execute();
92 $dbw->newDeleteQueryBuilder()
93 ->deleteFrom(
'ip_changes' )
94 ->where( [
'ipc_rev_id' => $oldRevs ] )
95 ->caller( __METHOD__ )->execute();
96 $this->
output(
"done.\n" );
99 # Purge redundant text records
109require_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.
commitTransaction(IDatabase $dbw, $fname)
Commit the transaction on a DB handle and wait for replica DB servers to catch up.
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.
purgeRedundantText( $delete=true)
Support function for cleaning up redundant text records.
beginTransaction(IDatabase $dbw, $fname)
Begin a transaction on a DB handle.
getPrimaryDB(string|false $virtualDomain=false)
addDescription( $text)
Set the description text.