MediaWiki master
updateArticleCount.php
Go to the documentation of this file.
1<?php
14
15// @codeCoverageIgnoreStart
16require_once __DIR__ . '/Maintenance.php';
17// @codeCoverageIgnoreEnd
18
26
27 public function __construct() {
28 parent::__construct();
29 $this->addDescription( 'Count of the number of articles and update the site statistics table' );
30 $this->addOption( 'update', 'Update the site_stats table with the new count' );
31 $this->addOption( 'use-master', 'Count using the primary database' );
32 }
33
34 public function execute() {
35 $this->output( "Counting articles..." );
36
37 if ( $this->hasOption( 'use-master' ) ) {
38 $dbr = $this->getPrimaryDB();
39 } else {
40 $dbr = $this->getDB( DB_REPLICA, 'vslow' );
41 }
42 $counter = new SiteStatsInit( $dbr );
43 $result = $counter->articles();
44
45 $this->output( "found {$result}.\n" );
46 if ( $this->hasOption( 'update' ) ) {
47 $this->output( "Updating site statistics table..." );
48 $dbw = $this->getPrimaryDB();
49 $dbw->newUpdateQueryBuilder()
50 ->update( 'site_stats' )
51 ->set( [ 'ss_good_articles' => $result ] )
52 ->where( [ 'ss_row_id' => 1 ] )
53 ->caller( __METHOD__ )
54 ->execute();
55 $this->output( "done.\n" );
56 } else {
57 $this->output( "To update the site statistics table, run the script "
58 . "with the --update option.\n" );
59 }
60 }
61}
62
63// @codeCoverageIgnoreStart
64$maintClass = UpdateArticleCount::class;
65require_once RUN_MAINTENANCE_IF_MAIN;
66// @codeCoverageIgnoreEnd
const DB_REPLICA
Definition defines.php:26
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
hasOption( $name)
Checks to see if a particular option was set.
getPrimaryDB(string|false $virtualDomain=false)
addDescription( $text)
Set the description text.
Class designed for counting of stats.
Maintenance script to provide a better count of the number of articles and update the site statistics...
__construct()
Default constructor.
execute()
Do the actual work.