Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
23 / 23 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
UpdateArticleCount | |
100.00% |
23 / 23 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
execute | |
100.00% |
19 / 19 |
|
100.00% |
1 / 1 |
3 |
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 | |
26 | use MediaWiki\Maintenance\Maintenance; |
27 | use MediaWiki\SiteStats\SiteStatsInit; |
28 | |
29 | // @codeCoverageIgnoreStart |
30 | require_once __DIR__ . '/Maintenance.php'; |
31 | // @codeCoverageIgnoreEnd |
32 | |
33 | /** |
34 | * Maintenance script to provide a better count of the number of articles |
35 | * and update the site statistics table, if desired. |
36 | * |
37 | * @ingroup Maintenance |
38 | */ |
39 | class UpdateArticleCount extends Maintenance { |
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; |
79 | require_once RUN_MAINTENANCE_IF_MAIN; |
80 | // @codeCoverageIgnoreEnd |