26require_once __DIR__ .
'/Maintenance.php';
40 parent::__construct();
41 $this->
addOption(
'list',
'List special page names' );
42 $this->
addOption(
'only',
'Only update "page"; case sensitive, ' .
43 'check correct case by calling this script with --list. ' .
44 'Ex: --only=BrokenRedirects',
false,
true );
45 $this->
addOption(
'override',
'Also update pages that have updates disabled' );
55 $queryCacheLimit = (int)$config->get( MainConfigNames::QueryCacheLimit );
56 $disabledQueryPages = QueryPage::getDisabledQueryPages( $config );
57 foreach ( QueryPage::getPages() as $page ) {
58 [ , $special ] = $page;
59 $limit = $page[2] ?? $queryCacheLimit;
61 # --list : just show the name of pages
63 $this->
output(
"$special [QueryPage]\n" );
68 && isset( $disabledQueryPages[$special] )
70 $this->
output( sprintf(
"%-30s [QueryPage] disabled\n", $special ) );
74 $specialObj = $specialPageFactory->getPage( $special );
76 $this->
output(
"No such special page: $special\n" );
80 $queryPage = $specialObj;
82 $class = get_class( $specialObj );
83 $this->
fatalError(
"$class is not an instance of QueryPage.\n" );
86 if ( !$this->
hasOption(
'only' ) || $this->
getOption(
'only' ) === $queryPage->getName() ) {
87 $this->
output( sprintf(
'%-30s [QueryPage] ', $special ) );
88 if ( $queryPage->isExpensive() ) {
89 $t1 = microtime(
true );
91 $num = $queryPage->recache( $limit );
92 $t2 = microtime(
true );
93 if ( $num ===
false ) {
94 $this->
output(
"FAILED: database error\n" );
96 $this->
output(
"got $num rows in " );
99 $hours = intval( $elapsed / 3600 );
100 $minutes = intval( (
int)$elapsed % 3600 / 60 );
101 $seconds = $elapsed - $hours * 3600 - $minutes * 60;
103 $this->
output( $hours .
'h ' );
106 $this->
output( $minutes .
'm ' );
108 $this->
output( sprintf(
"%.2fs\n", $seconds ) );
110 # Reopen any connections that have closed
111 $this->reopenAndWaitForReplicas();
114 $cached = $queryPage->getCachedTimestamp();
116 $queryPage->deleteAllCachedData();
117 $this->reopenAndWaitForReplicas();
118 $this->
output(
"cheap, but deleted cached data\n" );
120 $this->
output(
"cheap, skipped\n" );
136 private function reopenAndWaitForReplicas() {
138 $lb = $lbFactory->getMainLB();
139 if ( !$lb->pingAll() ) {
142 $this->
error(
"Connection failed, reconnecting in 10 seconds..." );
145 }
while ( !$lb->pingAll() );
146 $this->
output(
"Reconnected\n\n" );
152 foreach ( $this->
getConfig()->
get( MainConfigNames::SpecialPageCacheUpdates ) as $special => $call ) {
153 # --list : just show the name of pages
155 $this->
output(
"$special [callback]\n" );
160 if ( !is_callable( $call ) ) {
161 $this->
error(
"Uncallable function $call!" );
164 $this->
output( sprintf(
'%-30s [callback] ', $special ) );
165 $t1 = microtime(
true );
167 $t2 = microtime(
true );
169 $this->
output(
"completed in " );
170 $elapsed = $t2 - $t1;
171 $hours = intval( $elapsed / 3600 );
172 $minutes = intval( (
int)$elapsed % 3600 / 60 );
173 $seconds = $elapsed - $hours * 3600 - $minutes * 60;
175 $this->
output( $hours .
'h ' );
178 $this->
output( $minutes .
'm ' );
180 $this->
output( sprintf(
"%.2fs\n", $seconds ) );
181 # Wait for the replica DB to catch up
182 $this->reopenAndWaitForReplicas();
190require_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.
doSpecialPageCacheUpdates( $dbw)
__construct()
Default constructor.
execute()
Do the actual work.