34 parent::__construct();
35 $this->
addDescription(
'Delete old (non-current) revisions from the database' );
36 $this->
addOption(
'delete',
'Actually perform the deletion' );
37 $this->
addOption(
'page_id',
'List of page ids to work on',
false );
41 $this->
output(
"Delete old revisions\n\n" );
45 private function doDelete( $delete =
false, $pageIds = [] ) {
46 # Data should come off the master, wrapped in a transaction
53 # If a list of page_ids was provided, limit results to that set of page_ids
54 if ( count( $pageIds ) > 0 ) {
55 $pageConds[
'page_id'] = $pageIds;
56 $revConds[
'rev_page'] = $pageIds;
57 $this->
output(
"Limiting to page IDs " . implode(
',', $pageIds ) .
"\n" );
60 # Get "active" revisions from the page table
61 $this->
output(
"Searching for active revisions..." );
62 $res = $dbw->newSelectQueryBuilder()
63 ->select(
'page_latest' )
66 ->caller( __METHOD__ )
69 foreach ( $res as $row ) {
70 $latestRevs[] = $row->page_latest;
72 $this->
output(
"done.\n" );
74 # Get all revisions that aren't in this set
75 $this->
output(
"Searching for inactive revisions..." );
76 if ( count( $latestRevs ) > 0 ) {
77 $revConds[] = $dbw->expr(
'rev_id',
'!=', $latestRevs );
79 $res = $dbw->newSelectQueryBuilder()
83 ->caller( __METHOD__ )
86 foreach ( $res as $row ) {
87 $oldRevs[] = $row->rev_id;
89 $this->
output(
"done.\n" );
91 # Inform the user of what we're going to do
92 $count = count( $oldRevs );
93 $this->
output(
"$count old revisions found.\n" );
95 # Delete as appropriate
96 if ( $delete && $count ) {
97 $this->
output(
"Deleting..." );
98 $dbw->newDeleteQueryBuilder()
99 ->deleteFrom(
'revision' )
100 ->where( [
'rev_id' => $oldRevs ] )
101 ->caller( __METHOD__ )->execute();
102 $dbw->newDeleteQueryBuilder()
103 ->deleteFrom(
'ip_changes' )
104 ->where( [
'ipc_rev_id' => $oldRevs ] )
105 ->caller( __METHOD__ )->execute();
106 $this->
output(
"done.\n" );
109 # Purge redundant text records
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
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.
purgeRedundantText( $delete=true)
Support function for cleaning up redundant text records.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.