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