MediaWiki master
updateArticleCount.php
Go to the documentation of this file.
1<?php
28
29// @codeCoverageIgnoreStart
30require_once __DIR__ . '/Maintenance.php';
31// @codeCoverageIgnoreEnd
32
40
41 public function __construct() {
42 parent::__construct();
43 $this->addDescription( 'Count of the number of articles and update the site statistics table' );
44 $this->addOption( 'update', 'Update the site_stats table with the new count' );
45 $this->addOption( 'use-master', 'Count using the primary database' );
46 }
47
48 public function execute() {
49 $this->output( "Counting articles..." );
50
51 if ( $this->hasOption( 'use-master' ) ) {
52 $dbr = $this->getPrimaryDB();
53 } else {
54 $dbr = $this->getDB( DB_REPLICA, 'vslow' );
55 }
56 $counter = new SiteStatsInit( $dbr );
57 $result = $counter->articles();
58
59 $this->output( "found {$result}.\n" );
60 if ( $this->hasOption( 'update' ) ) {
61 $this->output( "Updating site statistics table..." );
62 $dbw = $this->getPrimaryDB();
63 $dbw->newUpdateQueryBuilder()
64 ->update( 'site_stats' )
65 ->set( [ 'ss_good_articles' => $result ] )
66 ->where( [ 'ss_row_id' => 1 ] )
67 ->caller( __METHOD__ )
68 ->execute();
69 $this->output( "done.\n" );
70 } else {
71 $this->output( "To update the site statistics table, run the script "
72 . "with the --update option.\n" );
73 }
74 }
75}
76
77// @codeCoverageIgnoreStart
78$maintClass = UpdateArticleCount::class;
79require_once RUN_MAINTENANCE_IF_MAIN;
80// @codeCoverageIgnoreEnd
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.
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.
const DB_REPLICA
Definition defines.php:26