27 require_once __DIR__ .
'/Maintenance.php';
38 parent::__construct();
40 'Maintenance script to delete revisions which refer to a nonexisting page' );
41 $this->
addOption(
'report',
'Prints out a count of affected revisions but doesn\'t delete them' );
45 $this->
output(
"Delete Orphaned Revisions\n" );
52 # Find all the orphaned revisions
53 $this->
output(
"Checking for orphaned revisions..." );
54 $res = $dbw->newSelectQueryBuilder()
57 ->leftJoin(
'page',
null,
'rev_page = page_id' )
58 ->where( [
'page_namespace' =>
null ] )
59 ->caller(
'deleteOrphanedRevisions' )
62 # Stash 'em all up for deletion (if needed)
64 foreach ( $res as $row ) {
65 $revisions[] = $row->rev_id;
67 $count = count( $revisions );
68 $this->
output(
"found {$count}.\n" );
71 if ( $report || $count == 0 ) {
76 # Delete each revision
77 $this->
output(
"Deleting..." );
78 $this->deleteRevs( $revisions, $dbw );
79 $this->
output(
"done.\n" );
81 # Close the transaction and call the script to purge unused text records
93 private function deleteRevs( array $id, $dbw ) {
94 $dbw->delete(
'revision', [
'rev_id' => $id ], __METHOD__ );
97 $dbw->delete(
'ip_changes', [
'ipc_rev_id' => $id ], __METHOD__ );
102 require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance script that deletes revisions which refer to a nonexisting page.
execute()
Do the actual work.
__construct()
Default constructor.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
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.