26require_once __DIR__ .
'/Maintenance.php';
41 parent::__construct();
42 $this->
addOption(
'list',
'List special page names' );
43 $this->
addOption(
'only',
'Only update "page"; case sensitive, ' .
44 'check correct case by calling this script with --list. ' .
45 'Ex: --only=BrokenRedirects',
false,
true );
46 $this->
addOption(
'override',
'Also update pages that have updates disabled' );
56 $queryCacheLimit = (int)$config->get( MainConfigNames::QueryCacheLimit );
57 $disabledQueryPages = QueryPage::getDisabledQueryPages( $config );
58 foreach ( QueryPage::getPages() as $page ) {
59 [ , $special ] = $page;
60 $limit = $page[2] ?? $queryCacheLimit;
62 # --list : just show the name of pages
64 $this->
output(
"$special [QueryPage]\n" );
69 && isset( $disabledQueryPages[$special] )
71 $this->
output( sprintf(
"%-30s [QueryPage] disabled\n", $special ) );
75 $specialObj = $specialPageFactory->getPage( $special );
77 $this->
output(
"No such special page: $special\n" );
81 $queryPage = $specialObj;
83 $class = get_class( $specialObj );
84 $this->
fatalError(
"$class is not an instance of QueryPage.\n" );
87 if ( !$this->
hasOption(
'only' ) || $this->
getOption(
'only' ) === $queryPage->getName() ) {
88 $this->
output( sprintf(
'%-30s [QueryPage] ', $special ) );
89 if ( $queryPage->isExpensive() ) {
90 $t1 = microtime(
true );
92 $num = $queryPage->recache( $limit );
93 $t2 = microtime(
true );
94 if ( $num ===
false ) {
95 $this->
output(
"FAILED: database error\n" );
97 $this->
output(
"got $num rows in " );
98 $this->outputElapsedTime( $t2 - $t1 );
100 # Reopen any connections that have closed
101 $this->reopenAndWaitForReplicas();
104 $cached = $queryPage->getCachedTimestamp();
106 $queryPage->deleteAllCachedData();
107 $this->reopenAndWaitForReplicas();
108 $this->
output(
"cheap, but deleted cached data\n" );
110 $this->
output(
"cheap, skipped\n" );
126 private function reopenAndWaitForReplicas() {
128 $lb = $lbFactory->getMainLB();
129 if ( !$lb->pingAll() ) {
135 $this->
error(
"Connection failed, reconnecting in 10 seconds..." );
138 }
while ( !$lb->pingAll() );
139 $this->
output(
"Reconnected\n\n" );
146 foreach ( $this->
getConfig()->
get( MainConfigNames::SpecialPageCacheUpdates ) as $special => $call ) {
147 # --list : just show the name of pages
149 $this->
output(
"$special [callback]\n" );
154 $this->
output( sprintf(
'%-30s [callback] ', $special ) );
155 if ( !is_callable( $call ) ) {
156 $this->
error(
"Uncallable function $call!" );
159 $t1 = microtime(
true );
161 $t2 = microtime(
true );
163 $this->
output(
"completed in " );
164 $this->outputElapsedTime( $t2 - $t1 );
166 # Wait for the replica DB to catch up
167 $this->reopenAndWaitForReplicas();
179 private function outputElapsedTime(
float $elapsed ) {
180 $hours = intval( $elapsed / 3600 );
181 $minutes = intval( (
int)$elapsed % 3600 / 60 );
182 $seconds = $elapsed - $hours * 3600 - $minutes * 60;
184 $this->
output( $hours .
'h ' );
187 $this->
output( $minutes .
'm ' );
189 $this->
output( sprintf(
"%.2fs\n", $seconds ) );
195require_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.
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.