From 60eca97237da62964224569d9b1b8cff71451a1e Mon Sep 17 00:00:00 2001 From: Alexandre Emsenhuber Date: Wed, 29 Jun 2011 15:39:40 +0000 Subject: [PATCH] Per Platonides, follow-up r72842: pass the db connection to SiteStatsInit::doAllAndCommit(). Changed parameters to that functions to give as first parameter a db connection and merged existing ones in the second parameter which is now an array of options (and is also much, much easier to read that those boolean parameters). No other calls in core or extensions. --- includes/SiteStats.php | 38 ++++++++++++++++++-------- includes/installer/DatabaseUpdater.php | 2 +- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/includes/SiteStats.php b/includes/SiteStats.php index f0abd829ea..09b0fd06f6 100644 --- a/includes/SiteStats.php +++ b/includes/SiteStats.php @@ -55,7 +55,7 @@ class SiteStats { // clean schema with mwdumper. wfDebug( __METHOD__ . ": initializing damaged or missing site_stats\n" ); - SiteStatsInit::doAllAndCommit( false ); + SiteStatsInit::doAllAndCommit( wfGetDB( DB_SLAVE ) ); $row = self::doLoad( wfGetDB( DB_MASTER ) ); } @@ -317,10 +317,16 @@ class SiteStatsInit { /** * Constructor - * @param $useMaster Boolean: whether to use the master DB + * @param $database Boolean or DatabaseBase: + * - Boolean: whether to use the master DB + * - DatabaseBase: database connection to use */ - public function __construct( $useMaster = false ) { - $this->db = wfGetDB( $useMaster ? DB_MASTER : DB_SLAVE ); + public function __construct( $database = false ) { + if ( $database instanceof DatabaseBase ) { + $this->db = $database; + } else { + $this->db = wfGetDB( $useMaster ? DB_MASTER : DB_SLAVE ); + } } /** @@ -402,13 +408,21 @@ class SiteStatsInit { /** * Do all updates and commit them. More or less a replacement * for the original initStats, but without the calls to wfOut() - * @param $update Boolean: whether to update the current stats or write fresh - * @param $noViews Boolean: when true, do not update the number of page views - * @param $activeUsers Boolean: whether to update the number of active users + * + * @param $database Boolean or DatabaseBase: + * - Boolean: whether to use the master DB + * - DatabaseBase: database connection to use + * @param $options Array of options, may contain the following values + * - update Boolean: whether to update the current stats (true) or write fresh (false) (default: false) + * - views Boolean: when true, do not update the number of page views (default: true) + * - activeUsers Boolean: whether to update the number of active users (default: false) */ - public static function doAllAndCommit( $update, $noViews = false, $activeUsers = false ) { + public static function doAllAndCommit( $database, array $options = array() ) { + $options += array( 'update' => false, 'views' => true, 'activeUsers' => false ); + // Grab the object and count everything - $counter = new SiteStatsInit( false ); + $counter = new SiteStatsInit( $database ); + $counter->edits(); $counter->articles(); $counter->pages(); @@ -416,19 +430,19 @@ class SiteStatsInit { $counter->files(); // Only do views if we don't want to not count them - if( !$noViews ) { + if( $options['views'] ) { $counter->views(); } // Update/refresh - if( $update ) { + if( $options['update'] ) { $counter->update(); } else { $counter->refresh(); } // Count active users if need be - if( $activeUsers ) { + if( $options['activeUsers'] ) { SiteStatsUpdate::cacheUpdate( wfGetDB( DB_MASTER ) ); } } diff --git a/includes/installer/DatabaseUpdater.php b/includes/installer/DatabaseUpdater.php index c5190879bc..e4108fa68e 100644 --- a/includes/installer/DatabaseUpdater.php +++ b/includes/installer/DatabaseUpdater.php @@ -497,7 +497,7 @@ abstract class DatabaseUpdater { $this->output( "done.\n" ); return; } - SiteStatsInit::doAllAndCommit( false ); + SiteStatsInit::doAllAndCommit( $this->db ); } # Common updater functions -- 2.20.1