40 parent::__construct();
42 'Maintenance script to delete revisions which refer to a nonexisting page' );
43 $this->
addOption(
'report',
'Prints out a count of affected revisions but doesn\'t delete them' );
47 $this->
output(
"Delete Orphaned Revisions\n" );
54 # Find all the orphaned revisions
55 $this->
output(
"Checking for orphaned revisions..." );
56 $res = $dbw->newSelectQueryBuilder()
59 ->leftJoin(
'page',
null,
'rev_page = page_id' )
60 ->where( [
'page_namespace' =>
null ] )
61 ->caller(
'deleteOrphanedRevisions' )
64 # Stash 'em all up for deletion (if needed)
66 foreach ( $res as $row ) {
67 $revisions[] = $row->rev_id;
69 $count = count( $revisions );
70 $this->
output(
"found {$count}.\n" );
73 if ( $report || $count == 0 ) {
78 # Delete each revision
79 $this->
output(
"Deleting..." );
80 $this->deleteRevs( $revisions, $dbw );
81 $this->
output(
"done.\n" );
83 # Close the transaction and call the script to purge unused text records
95 private function deleteRevs( array $id, $dbw ) {
96 $dbw->newDeleteQueryBuilder()
97 ->deleteFrom(
'revision' )
98 ->where( [
'rev_id' => $id ] )
99 ->caller( __METHOD__ )->execute();
102 $dbw->newDeleteQueryBuilder()
103 ->deleteFrom(
'ip_changes' )
104 ->where( [
'ipc_rev_id' => $id ] )
105 ->caller( __METHOD__ )->execute();
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.