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