28require_once __DIR__ .
'/Maintenance.php';
38 parent::__construct();
39 $this->
addDescription(
'Delete old (non-current) revisions from the database' );
40 $this->
addOption(
'delete',
'Actually perform the deletion' );
41 $this->
addArg(
'page_id',
'List of page ids to work on',
false,
true );
45 $this->
output(
"Delete old revisions\n\n" );
46 $this->doDelete( $this->
hasOption(
'delete' ), $this->
getArgs(
'page_id' ) );
49 private function doDelete( $delete =
false, $pageIds = [] ) {
50 # Data should come off the master, wrapped in a transaction
57 # If a list of page_ids was provided, limit results to that set of page_ids
58 if ( count( $pageIds ) > 0 ) {
59 $pageConds[
'page_id'] = $pageIds;
60 $revConds[
'rev_page'] = $pageIds;
61 $this->
output(
"Limiting to page IDs " . implode(
',', $pageIds ) .
"\n" );
64 # Get "active" revisions from the page table
65 $this->
output(
"Searching for active revisions..." );
66 $res = $dbw->newSelectQueryBuilder()
67 ->select(
'page_latest' )
70 ->caller( __METHOD__ )
73 foreach ( $res as $row ) {
74 $latestRevs[] = $row->page_latest;
76 $this->
output(
"done.\n" );
78 # Get all revisions that aren't in this set
79 $this->
output(
"Searching for inactive revisions..." );
80 if ( count( $latestRevs ) > 0 ) {
81 $revConds[] = $dbw->expr(
'rev_id',
'!=', $latestRevs );
83 $res = $dbw->newSelectQueryBuilder()
87 ->caller( __METHOD__ )
90 foreach ( $res as $row ) {
91 $oldRevs[] = $row->rev_id;
93 $this->
output(
"done.\n" );
95 # Inform the user of what we're going to do
96 $count = count( $oldRevs );
97 $this->
output(
"$count old revisions found.\n" );
99 # Delete as appropriate
100 if ( $delete && $count ) {
101 $this->
output(
"Deleting..." );
102 $dbw->newDeleteQueryBuilder()
103 ->deleteFrom(
'revision' )
104 ->where( [
'rev_id' => $oldRevs ] )
105 ->caller( __METHOD__ )->execute();
106 $dbw->newDeleteQueryBuilder()
107 ->deleteFrom(
'ip_changes' )
108 ->where( [
'ipc_rev_id' => $oldRevs ] )
109 ->caller( __METHOD__ )->execute();
110 $this->
output(
"done.\n" );
113 # Purge redundant text records
123require_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.
addDescription( $text)
Set the description text.