30 require_once __DIR__ .
'/Maintenance.php';
40 parent::__construct();
41 $this->
addOption(
"fix",
"Actually fix the entries, will dry run otherwise" );
43 "Regenerate the page_latest field for all records in table page" );
44 $this->
addDescription(
'Fix page_latest entries in the page table' );
48 $this->
output(
"Looking for pages with page_latest set to 0...\n" );
50 $conds = [
'page_latest' => 0 ];
51 if ( $this->
hasOption(
'regenerate-all' ) ) {
54 $result = $dbw->newSelectQueryBuilder()
55 ->select( [
'page_id',
'page_namespace',
'page_title' ] )
58 ->caller( __METHOD__ )
62 $dbDomain = $services->getDBLoadBalancerFactory()->getLocalDomainID();
63 $wikiPageFactory = $services->getWikiPageFactory();
64 $revisionLookup = $services->getRevisionLookup();
67 foreach ( $result as $row ) {
68 $pageId = intval( $row->page_id );
69 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
70 $name = $title->getPrefixedText();
71 $latestTime = $dbw->newSelectQueryBuilder()
72 ->select(
'MAX(rev_timestamp' )
74 ->where( [
'rev_page' => $pageId ] )
75 ->caller( __METHOD__ )
78 $this->
output(
"$dbDomain $pageId [[$name]] can't find latest rev time?!\n" );
82 $revRecord = $revisionLookup->getRevisionByTimestamp( $title, $latestTime, RevisionLookup::READ_LATEST );
83 if ( $revRecord ===
null ) {
85 "$dbDomain $pageId [[$name]] latest time $latestTime, can't find revision id\n"
90 $id = $revRecord->getId();
91 $this->
output(
"$dbDomain $pageId [[$name]] latest time $latestTime, rev id $id\n" );
93 $page = $wikiPageFactory->newFromTitle( $title );
94 $page->updateRevisionOn( $dbw, $revRecord );
99 $this->
output(
"Done! Processed $n pages.\n" );
101 $this->
output(
"This was a dry run; rerun with --fix to update page_latest.\n" );
107 require_once RUN_MAINTENANCE_IF_MAIN;
Maintenance script to correct wrong values in the page_latest field in the database.
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.
output( $out, $channel=null)
Throw some output to the user.
waitForReplication()
Wait for replica DBs to catch up.
hasOption( $name)
Checks to see if a particular option was set.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.