Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
29 / 29 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| InitSiteStats | |
100.00% |
29 / 29 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| execute | |
100.00% |
24 / 24 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Re-initialise or update the site statistics table. |
| 4 | * |
| 5 | * @license GPL-2.0-or-later |
| 6 | * @file |
| 7 | * @ingroup Maintenance |
| 8 | * @author Brooke Vibber |
| 9 | * @author Rob Church <robchur@gmail.com> |
| 10 | */ |
| 11 | |
| 12 | use MediaWiki\Deferred\SiteStatsUpdate; |
| 13 | use MediaWiki\Maintenance\Maintenance; |
| 14 | use MediaWiki\SiteStats\SiteStatsInit; |
| 15 | |
| 16 | // @codeCoverageIgnoreStart |
| 17 | require_once __DIR__ . '/Maintenance.php'; |
| 18 | // @codeCoverageIgnoreEnd |
| 19 | |
| 20 | /** |
| 21 | * Maintenance script to re-initialise or update the site statistics table |
| 22 | * |
| 23 | * @ingroup Maintenance |
| 24 | */ |
| 25 | class InitSiteStats extends Maintenance { |
| 26 | public function __construct() { |
| 27 | parent::__construct(); |
| 28 | $this->addDescription( 'Re-initialise the site statistics tables' ); |
| 29 | $this->addOption( 'update', 'Update the existing statistics' ); |
| 30 | $this->addOption( 'active', 'Also update active users count' ); |
| 31 | $this->addOption( 'use-master', 'Count using the primary database' ); |
| 32 | } |
| 33 | |
| 34 | public function execute() { |
| 35 | $this->output( "Refresh Site Statistics\n\n" ); |
| 36 | $counter = new SiteStatsInit( $this->hasOption( 'use-master' ) ); |
| 37 | |
| 38 | $this->output( "Counting total edits..." ); |
| 39 | $edits = $counter->edits(); |
| 40 | $this->output( "{$edits}\nCounting number of articles..." ); |
| 41 | |
| 42 | $good = $counter->articles(); |
| 43 | $this->output( "{$good}\nCounting total pages..." ); |
| 44 | |
| 45 | $pages = $counter->pages(); |
| 46 | $this->output( "{$pages}\nCounting number of users..." ); |
| 47 | |
| 48 | $users = $counter->users(); |
| 49 | $this->output( "{$users}\nCounting number of images..." ); |
| 50 | |
| 51 | $image = $counter->files(); |
| 52 | $this->output( "{$image}\n" ); |
| 53 | |
| 54 | if ( $this->hasOption( 'update' ) ) { |
| 55 | $this->output( "\nUpdating site statistics..." ); |
| 56 | $counter->refresh(); |
| 57 | $this->output( "done.\n" ); |
| 58 | } else { |
| 59 | $this->output( "\nTo update the site statistics table, run the script " |
| 60 | . "with the --update option.\n" ); |
| 61 | } |
| 62 | |
| 63 | if ( $this->hasOption( 'active' ) ) { |
| 64 | $this->output( "\nCounting and updating active users..." ); |
| 65 | $active = SiteStatsUpdate::cacheUpdate( $this->getPrimaryDB() ); |
| 66 | $this->output( "{$active}\n" ); |
| 67 | } |
| 68 | |
| 69 | $this->output( "\nDone.\n" ); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | // @codeCoverageIgnoreStart |
| 74 | $maintClass = InitSiteStats::class; |
| 75 | require_once RUN_MAINTENANCE_IF_MAIN; |
| 76 | // @codeCoverageIgnoreEnd |