28require_once __DIR__ .
'/Maintenance.php';
41 parent::__construct();
43 'Maintenance script to delete revisions which refer to a nonexisting page' );
44 $this->
addOption(
'report',
'Prints out a count of affected revisions but doesn\'t delete them' );
48 $this->
output(
"Delete Orphaned Revisions\n" );
55 # Find all the orphaned revisions
56 $this->
output(
"Checking for orphaned revisions..." );
57 $res = $dbw->newSelectQueryBuilder()
60 ->leftJoin(
'page',
null,
'rev_page = page_id' )
61 ->where( [
'page_namespace' =>
null ] )
62 ->caller(
'deleteOrphanedRevisions' )
65 # Stash 'em all up for deletion (if needed)
67 foreach ( $res as $row ) {
68 $revisions[] = $row->rev_id;
70 $count = count( $revisions );
71 $this->
output(
"found {$count}.\n" );
74 if ( $report || $count == 0 ) {
79 # Delete each revision
80 $this->
output(
"Deleting..." );
81 $this->deleteRevs( $revisions, $dbw );
82 $this->
output(
"done.\n" );
84 # Close the transaction and call the script to purge unused text records
96 private function deleteRevs( array $id, $dbw ) {
97 $dbw->newDeleteQueryBuilder()
98 ->deleteFrom(
'revision' )
99 ->where( [
'rev_id' => $id ] )
100 ->caller( __METHOD__ )->execute();
103 $dbw->newDeleteQueryBuilder()
104 ->deleteFrom(
'ip_changes' )
105 ->where( [
'ipc_rev_id' => $id ] )
106 ->caller( __METHOD__ )->execute();
112require_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...
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.
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.