Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 26
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
UpdateArticleCount
0.00% covered (danger)
0.00%
0 / 23
0.00% covered (danger)
0.00%
0 / 2
20
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2/**
3 * Provide a better count of the number of articles
4 * and update the site statistics table, if desired.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
20 *
21 * @file
22 * @ingroup Maintenance
23 * @author Rob Church <robchur@gmail.com>
24 */
25
26use MediaWiki\SiteStats\SiteStatsInit;
27
28require_once __DIR__ . '/Maintenance.php';
29
30/**
31 * Maintenance script to provide a better count of the number of articles
32 * and update the site statistics table, if desired.
33 *
34 * @ingroup Maintenance
35 */
36class UpdateArticleCount extends Maintenance {
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->getPrimaryDB();
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->getPrimaryDB();
60            $dbw->newUpdateQueryBuilder()
61                ->update( 'site_stats' )
62                ->set( [ 'ss_good_articles' => $result ] )
63                ->where( [ 'ss_row_id' => 1 ] )
64                ->caller( __METHOD__ )
65                ->execute();
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;
75require_once RUN_MAINTENANCE_IF_MAIN;