MediaWiki  master
updateArticleCount.php
Go to the documentation of this file.
1 <?php
27 
28 require_once __DIR__ . '/Maintenance.php';
29 
37 
38  public function __construct() {
39  parent::__construct();
40  $this->addDescription( 'Count of the number of articles and update the site statistics table' );
41  $this->addOption( 'update', 'Update the site_stats table with the new count' );
42  $this->addOption( 'use-master', 'Count using the primary database' );
43  }
44 
45  public function execute() {
46  $this->output( "Counting articles..." );
47 
48  if ( $this->hasOption( 'use-master' ) ) {
49  $dbr = $this->getDB( DB_PRIMARY );
50  } else {
51  $dbr = $this->getDB( DB_REPLICA, 'vslow' );
52  }
53  $counter = new SiteStatsInit( $dbr );
54  $result = $counter->articles();
55 
56  $this->output( "found {$result}.\n" );
57  if ( $this->hasOption( 'update' ) ) {
58  $this->output( "Updating site statistics table..." );
59  $dbw = $this->getDB( DB_PRIMARY );
60  $dbw->update(
61  'site_stats',
62  [ 'ss_good_articles' => $result ],
63  [ 'ss_row_id' => 1 ],
64  __METHOD__
65  );
66  $this->output( "done.\n" );
67  } else {
68  $this->output( "To update the site statistics table, run the script "
69  . "with the --update option.\n" );
70  }
71  }
72 }
73 
74 $maintClass = UpdateArticleCount::class;
75 require_once RUN_MAINTENANCE_IF_MAIN;
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:66
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option was set.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
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.
const DB_REPLICA
Definition: defines.php:26
const DB_PRIMARY
Definition: defines.php:28