Index: trunk/phase3/includes/SiteStats.php |
— | — | @@ -55,7 +55,7 @@ |
56 | 56 | // clean schema with mwdumper. |
57 | 57 | wfDebug( __METHOD__ . ": initializing damaged or missing site_stats\n" ); |
58 | 58 | |
59 | | - SiteStatsInit::doAllAndCommit( false ); |
| 59 | + SiteStatsInit::doAllAndCommit( wfGetDB( DB_SLAVE ) ); |
60 | 60 | |
61 | 61 | $row = self::doLoad( wfGetDB( DB_MASTER ) ); |
62 | 62 | } |
— | — | @@ -317,10 +317,16 @@ |
318 | 318 | |
319 | 319 | /** |
320 | 320 | * Constructor |
321 | | - * @param $useMaster Boolean: whether to use the master DB |
| 321 | + * @param $database Boolean or DatabaseBase: |
| 322 | + * - Boolean: whether to use the master DB |
| 323 | + * - DatabaseBase: database connection to use |
322 | 324 | */ |
323 | | - public function __construct( $useMaster = false ) { |
324 | | - $this->db = wfGetDB( $useMaster ? DB_MASTER : DB_SLAVE ); |
| 325 | + public function __construct( $database = false ) { |
| 326 | + if ( $database instanceof DatabaseBase ) { |
| 327 | + $this->db = $database; |
| 328 | + } else { |
| 329 | + $this->db = wfGetDB( $useMaster ? DB_MASTER : DB_SLAVE ); |
| 330 | + } |
325 | 331 | } |
326 | 332 | |
327 | 333 | /** |
— | — | @@ -402,13 +408,21 @@ |
403 | 409 | /** |
404 | 410 | * Do all updates and commit them. More or less a replacement |
405 | 411 | * for the original initStats, but without the calls to wfOut() |
406 | | - * @param $update Boolean: whether to update the current stats or write fresh |
407 | | - * @param $noViews Boolean: when true, do not update the number of page views |
408 | | - * @param $activeUsers Boolean: whether to update the number of active users |
| 412 | + * |
| 413 | + * @param $database Boolean or DatabaseBase: |
| 414 | + * - Boolean: whether to use the master DB |
| 415 | + * - DatabaseBase: database connection to use |
| 416 | + * @param $options Array of options, may contain the following values |
| 417 | + * - update Boolean: whether to update the current stats (true) or write fresh (false) (default: false) |
| 418 | + * - views Boolean: when true, do not update the number of page views (default: true) |
| 419 | + * - activeUsers Boolean: whether to update the number of active users (default: false) |
409 | 420 | */ |
410 | | - public static function doAllAndCommit( $update, $noViews = false, $activeUsers = false ) { |
| 421 | + public static function doAllAndCommit( $database, array $options = array() ) { |
| 422 | + $options += array( 'update' => false, 'views' => true, 'activeUsers' => false ); |
| 423 | + |
411 | 424 | // Grab the object and count everything |
412 | | - $counter = new SiteStatsInit( false ); |
| 425 | + $counter = new SiteStatsInit( $database ); |
| 426 | + |
413 | 427 | $counter->edits(); |
414 | 428 | $counter->articles(); |
415 | 429 | $counter->pages(); |
— | — | @@ -416,19 +430,19 @@ |
417 | 431 | $counter->files(); |
418 | 432 | |
419 | 433 | // Only do views if we don't want to not count them |
420 | | - if( !$noViews ) { |
| 434 | + if( $options['views'] ) { |
421 | 435 | $counter->views(); |
422 | 436 | } |
423 | 437 | |
424 | 438 | // Update/refresh |
425 | | - if( $update ) { |
| 439 | + if( $options['update'] ) { |
426 | 440 | $counter->update(); |
427 | 441 | } else { |
428 | 442 | $counter->refresh(); |
429 | 443 | } |
430 | 444 | |
431 | 445 | // Count active users if need be |
432 | | - if( $activeUsers ) { |
| 446 | + if( $options['activeUsers'] ) { |
433 | 447 | SiteStatsUpdate::cacheUpdate( wfGetDB( DB_MASTER ) ); |
434 | 448 | } |
435 | 449 | } |
Index: trunk/phase3/includes/installer/DatabaseUpdater.php |
— | — | @@ -497,7 +497,7 @@ |
498 | 498 | $this->output( "done.\n" ); |
499 | 499 | return; |
500 | 500 | } |
501 | | - SiteStatsInit::doAllAndCommit( false ); |
| 501 | + SiteStatsInit::doAllAndCommit( $this->db ); |
502 | 502 | } |
503 | 503 | |
504 | 504 | # Common updater functions |