| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
use MediaWiki\SiteStats\SiteStatsInit; |
| 27 |
|
| 28 |
|
| 29 |
require_once __DIR__ . '/Maintenance.php'; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
class UpdateArticleCount extends Maintenance { |
| 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 |
|
| 77 |
$maintClass = UpdateArticleCount::class; |
| 78 |
require_once RUN_MAINTENANCE_IF_MAIN; |
| 79 |
|