36 parent::__construct();
37 $this->
addDescription(
'Delete old (non-current) revisions from the database' );
38 $this->
addOption(
'delete',
'Actually perform the deletion' );
39 $this->
addArg(
'page_id',
'List of page ids to work on',
false,
true );
43 $this->
output(
"Delete old revisions\n\n" );
44 $this->doDelete( $this->
hasOption(
'delete' ), $this->
getArgs(
'page_id' ) );
47 private function doDelete( $delete =
false, $pageIds = [] ) {
48 # Data should come off the master, wrapped in a transaction
55 # If a list of page_ids was provided, limit results to that set of page_ids
56 if ( count( $pageIds ) > 0 ) {
57 $pageConds[
'page_id'] = $pageIds;
58 $revConds[
'rev_page'] = $pageIds;
59 $this->
output(
"Limiting to page IDs " . implode(
',', $pageIds ) .
"\n" );
62 # Get "active" revisions from the page table
63 $this->
output(
"Searching for active revisions..." );
64 $res = $dbw->newSelectQueryBuilder()
65 ->select(
'page_latest' )
68 ->caller( __METHOD__ )
71 foreach ( $res as $row ) {
72 $latestRevs[] = $row->page_latest;
74 $this->
output(
"done.\n" );
76 # Get all revisions that aren't in this set
77 $this->
output(
"Searching for inactive revisions..." );
78 if ( count( $latestRevs ) > 0 ) {
79 $revConds[] = $dbw->expr(
'rev_id',
'!=', $latestRevs );
81 $res = $dbw->newSelectQueryBuilder()
85 ->caller( __METHOD__ )
88 foreach ( $res as $row ) {
89 $oldRevs[] = $row->rev_id;
91 $this->
output(
"done.\n" );
93 # Inform the user of what we're going to do
94 $count = count( $oldRevs );
95 $this->
output(
"$count old revisions found.\n" );
97 # Delete as appropriate
98 if ( $delete && $count ) {
99 $this->
output(
"Deleting..." );
100 $dbw->newDeleteQueryBuilder()
101 ->deleteFrom(
'revision' )
102 ->where( [
'rev_id' => $oldRevs ] )
103 ->caller( __METHOD__ )->execute();
104 $dbw->newDeleteQueryBuilder()
105 ->deleteFrom(
'ip_changes' )
106 ->where( [
'ipc_rev_id' => $oldRevs ] )
107 ->caller( __METHOD__ )->execute();
108 $this->
output(
"done.\n" );
111 # Purge redundant text records
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.
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.