9require_once __DIR__ .
'/Maintenance.php';
33 parent::__construct();
35 $this->
addOption(
'ns',
'Namespace to restrict the query',
false,
true );
36 $this->
addOption(
'dry-run',
'Run in dry-mode' );
37 $this->
addOption(
'delete',
'Actually delete the found rows' );
46 $this->
fatalError(
'Cannot do both --dry-run and --delete.' );
47 } elseif ( $this->
hasOption(
'delete' ) ) {
49 } elseif ( !$this->
hasOption(
'dry-run' ) ) {
50 $this->
fatalError(
'Either --dry-run or --delete must be specified.' );
53 $conds = [
'page_id<>rev_page' ];
55 $conds[
'page_namespace'] = (int)$this->
getOption(
'ns' );
58 $res = $dbr->newSelectQueryBuilder()
60 ->join(
'revision',
null,
'page_latest=rev_id' )
61 ->fields( [
'page_namespace',
'page_title',
'page_id' ] )
63 ->caller( __METHOD__ )
66 $count = $res->numRows();
69 $this->
output(
"Nothing was found, no page matches the criteria.\n" );
76 foreach ( $res as $row ) {
77 $title = Title::makeTitleSafe( $row->page_namespace, $row->page_title );
79 $this->
output(
"Skipping invalid title with page_id: $row->page_id\n" );
82 $titleText = $title->getPrefixedDBkey();
86 $revId = $dbr->newSelectQueryBuilder()
87 ->select(
'MAX(rev_id)' )
89 ->where( [
'rev_page' => $row->page_id ] )
90 ->caller( __METHOD__ )->fetchField();
94 $this->
output(
"Would delete $titleText with page_id: $row->page_id\n" );
96 $this->
output(
"Deleting $titleText with page_id: $row->page_id\n" );
97 $dbw->newDeleteQueryBuilder()
98 ->deleteFrom(
'page' )
99 ->where( [
'page_id' => $row->page_id ] )
100 ->caller( __METHOD__ )->execute();
105 $this->
output(
"Would update page_id $row->page_id to page_latest $revId\n" );
107 $this->
output(
"Updating page_id $row->page_id to page_latest $revId\n" );
108 $dbw->newUpdateQueryBuilder()
110 ->set( [
'page_latest' => $revId ] )
111 ->where( [
'page_id' => $row->page_id ] )
112 ->caller( __METHOD__ )->execute();
119 $this->
output(
"Updated $numUpdated row(s), deleted $numDeleted row(s)\n" );
126require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance script that clears rows of pages corrupted by MergeHistory, those pages 'exist' but have ...
__construct()
Default constructor.
execute()
Do the actual work.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
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.
getOption( $name, $default=null)
Get an option, or return the default.
getReplicaDB(string|false $virtualDomain=false)
getPrimaryDB(string|false $virtualDomain=false)
addDescription( $text)
Set the description text.