12require_once __DIR__ .
'/Maintenance.php';
27 parent::__construct();
28 $this->
addOption(
'list',
'List special page names' );
29 $this->
addOption(
'only',
'Only update "page"; case sensitive, ' .
30 'check correct case by calling this script with --list. ' .
31 'Ex: --only=BrokenRedirects',
false,
true );
32 $this->
addOption(
'override',
'Also update pages that have updates disabled' );
42 $queryCacheLimit = (int)$config->get( MainConfigNames::QueryCacheLimit );
43 $disabledQueryPages = QueryPage::getDisabledQueryPages( $config );
44 foreach ( QueryPage::getPages() as $page ) {
45 [ , $special ] = $page;
46 $limit = $page[2] ?? $queryCacheLimit;
48 # --list : just show the name of pages
50 $this->
output(
"$special [QueryPage]\n" );
55 && isset( $disabledQueryPages[$special] )
57 $this->
output( sprintf(
"%-30s [QueryPage] disabled\n", $special ) );
61 $specialObj = $specialPageFactory->getPage( $special );
63 $this->
output(
"No such special page: $special\n" );
67 $queryPage = $specialObj;
69 $class = get_class( $specialObj );
70 $this->
fatalError(
"$class is not an instance of QueryPage.\n" );
73 if ( !$this->
hasOption(
'only' ) || $this->
getOption(
'only' ) === $queryPage->getName() ) {
74 $this->
output( sprintf(
'%-30s [QueryPage] ', $special ) );
75 if ( $queryPage->isExpensive() ) {
76 $t1 = microtime(
true );
78 $num = $queryPage->recache( $limit );
79 $t2 = microtime(
true );
80 if ( $num ===
false ) {
81 $this->
output(
"FAILED: database error\n" );
83 $this->
output(
"got $num rows in " );
84 $this->outputElapsedTime( $t2 - $t1 );
86 # Reopen any connections that have closed
87 $this->reopenAndWaitForReplicas();
90 $cached = $queryPage->getCachedTimestamp();
92 $queryPage->deleteAllCachedData();
93 $this->reopenAndWaitForReplicas();
94 $this->
output(
"cheap, but deleted cached data\n" );
96 $this->
output(
"cheap, skipped\n" );
112 private function reopenAndWaitForReplicas() {
114 $lb = $lbFactory->getMainLB();
115 if ( !$lb->pingAll() ) {
121 $this->
error(
"Connection failed, reconnecting in 10 seconds..." );
124 }
while ( !$lb->pingAll() );
125 $this->
output(
"Reconnected\n\n" );
132 foreach ( $this->
getConfig()->
get( MainConfigNames::SpecialPageCacheUpdates ) as $special => $call ) {
133 # --list : just show the name of pages
135 $this->
output(
"$special [callback]\n" );
140 $this->
output( sprintf(
'%-30s [callback] ', $special ) );
141 if ( !is_callable( $call ) ) {
142 $this->
error(
"Uncallable function $call!" );
145 $t1 = microtime(
true );
147 $t2 = microtime(
true );
149 $this->
output(
"completed in " );
150 $this->outputElapsedTime( $t2 - $t1 );
152 # Wait for the replica DB to catch up
153 $this->reopenAndWaitForReplicas();
165 private function outputElapsedTime(
float $elapsed ) {
166 $hours = intval( $elapsed / 3600 );
167 $minutes = intval( (
int)$elapsed % 3600 / 60 );
168 $seconds = $elapsed - $hours * 3600 - $minutes * 60;
170 $this->
output( $hours .
'h ' );
173 $this->
output( $minutes .
'm ' );
175 $this->
output( sprintf(
"%.2fs\n", $seconds ) );
181require_once RUN_MAINTENANCE_IF_MAIN;
A class containing constants representing the names of configuration variables.
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.
waitForReplication()
Wait for replica DB servers to catch up.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
error( $err, $die=0)
Throw an error to the user.
getServiceContainer()
Returns the main service container.
getPrimaryDB(string|false $virtualDomain=false)
This is a class for doing query pages; since they're almost all the same, we factor out some of the f...
Maintenance script to update cached special pages.
__construct()
Default constructor.
doSpecialPageCacheUpdates(IDatabase $dbw)
execute()
Do the actual work.