25 require_once __DIR__ .
'/Maintenance.php';
37 parent::__construct();
38 $this->
addOption(
'list',
'List special page names' );
39 $this->
addOption(
'only',
'Only update "page"; case sensitive, ' .
40 'check correct case by calling this script with --list. ' .
41 'Ex: --only=BrokenRedirects',
false,
true );
42 $this->
addOption(
'override',
'Also update pages that have updates disabled' );
52 $queryCacheLimit = (int)$config->get( MainConfigNames::QueryCacheLimit );
53 $disabledQueryPages = QueryPage::getDisabledQueryPages( $config );
54 foreach ( QueryPage::getPages() as $page ) {
55 [ , $special ] = $page;
56 $limit = $page[2] ?? $queryCacheLimit;
58 # --list : just show the name of pages
60 $this->
output(
"$special [QueryPage]\n" );
65 && isset( $disabledQueryPages[$special] )
67 $this->
output( sprintf(
"%-30s [QueryPage] disabled\n", $special ) );
71 $specialObj = $specialPageFactory->getPage( $special );
73 $this->
output(
"No such special page: $special\n" );
77 $queryPage = $specialObj;
79 $class = get_class( $specialObj );
80 $this->
fatalError(
"$class is not an instance of QueryPage.\n" );
83 if ( !$this->
hasOption(
'only' ) || $this->
getOption(
'only' ) === $queryPage->getName() ) {
84 $this->
output( sprintf(
'%-30s [QueryPage] ', $special ) );
85 if ( $queryPage->isExpensive() ) {
86 $t1 = microtime(
true );
88 $num = $queryPage->recache( $limit );
89 $t2 = microtime(
true );
90 if ( $num ===
false ) {
91 $this->
output(
"FAILED: database error\n" );
93 $this->
output(
"got $num rows in " );
96 $hours = intval( $elapsed / 3600 );
97 $minutes = intval( (
int)$elapsed % 3600 / 60 );
98 $seconds = $elapsed - $hours * 3600 - $minutes * 60;
100 $this->
output( $hours .
'h ' );
103 $this->
output( $minutes .
'm ' );
105 $this->
output( sprintf(
"%.2fs\n", $seconds ) );
107 # Reopen any connections that have closed
108 $this->reopenAndWaitForReplicas();
111 $cached = $queryPage->getCachedTimestamp();
113 $queryPage->deleteAllCachedData();
114 $this->reopenAndWaitForReplicas();
115 $this->
output(
"cheap, but deleted cached data\n" );
117 $this->
output(
"cheap, skipped\n" );
133 private function reopenAndWaitForReplicas() {
135 $lb = $lbFactory->getMainLB();
136 if ( !$lb->pingAll() ) {
139 $this->
error(
"Connection failed, reconnecting in 10 seconds..." );
141 }
while ( !$lb->pingAll() );
142 $this->
output(
"Reconnected\n\n" );
149 foreach ( $this->
getConfig()->
get( MainConfigNames::SpecialPageCacheUpdates ) as $special => $call ) {
150 # --list : just show the name of pages
152 $this->
output(
"$special [callback]\n" );
157 if ( !is_callable( $call ) ) {
158 $this->
error(
"Uncallable function $call!" );
161 $this->
output( sprintf(
'%-30s [callback] ', $special ) );
162 $t1 = microtime(
true );
164 $t2 = microtime(
true );
166 $this->
output(
"completed in " );
167 $elapsed = $t2 - $t1;
168 $hours = intval( $elapsed / 3600 );
169 $minutes = intval( (
int)$elapsed % 3600 / 60 );
170 $seconds = $elapsed - $hours * 3600 - $minutes * 60;
172 $this->
output( $hours .
'h ' );
175 $this->
output( $minutes .
'm ' );
177 $this->
output( sprintf(
"%.2fs\n", $seconds ) );
178 # Wait for the replica DB to catch up
179 $this->reopenAndWaitForReplicas();
186 require_once RUN_MAINTENANCE_IF_MAIN;
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.
error( $err, $die=0)
Throw an error to the user.
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.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
A class containing constants representing the names of configuration variables.
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.