r91076 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91075‎ | r91076 | r91077 >
Date:15:39, 29 June 2011
Author:ialex
Status:resolved (Comments)
Tags:
Comment:
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.
Modified paths:
  • /trunk/phase3/includes/SiteStats.php (modified) (history)
  • /trunk/phase3/includes/installer/DatabaseUpdater.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SiteStats.php
@@ -55,7 +55,7 @@
5656 // clean schema with mwdumper.
5757 wfDebug( __METHOD__ . ": initializing damaged or missing site_stats\n" );
5858
59 - SiteStatsInit::doAllAndCommit( false );
 59+ SiteStatsInit::doAllAndCommit( wfGetDB( DB_SLAVE ) );
6060
6161 $row = self::doLoad( wfGetDB( DB_MASTER ) );
6262 }
@@ -317,10 +317,16 @@
318318
319319 /**
320320 * 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
322324 */
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+ }
325331 }
326332
327333 /**
@@ -402,13 +408,21 @@
403409 /**
404410 * Do all updates and commit them. More or less a replacement
405411 * 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)
409420 */
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+
411424 // Grab the object and count everything
412 - $counter = new SiteStatsInit( false );
 425+ $counter = new SiteStatsInit( $database );
 426+
413427 $counter->edits();
414428 $counter->articles();
415429 $counter->pages();
@@ -416,19 +430,19 @@
417431 $counter->files();
418432
419433 // Only do views if we don't want to not count them
420 - if( !$noViews ) {
 434+ if( $options['views'] ) {
421435 $counter->views();
422436 }
423437
424438 // Update/refresh
425 - if( $update ) {
 439+ if( $options['update'] ) {
426440 $counter->update();
427441 } else {
428442 $counter->refresh();
429443 }
430444
431445 // Count active users if need be
432 - if( $activeUsers ) {
 446+ if( $options['activeUsers'] ) {
433447 SiteStatsUpdate::cacheUpdate( wfGetDB( DB_MASTER ) );
434448 }
435449 }
Index: trunk/phase3/includes/installer/DatabaseUpdater.php
@@ -497,7 +497,7 @@
498498 $this->output( "done.\n" );
499499 return;
500500 }
501 - SiteStatsInit::doAllAndCommit( false );
 501+ SiteStatsInit::doAllAndCommit( $this->db );
502502 }
503503
504504 # Common updater functions

Follow-up revisions

RevisionCommit summaryAuthorDate
r91080Fix for r91076: forgot to change one instance of $useMaster to $databaseialex17:18, 29 June 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r72842* Use Maintenance::runChild() to get the child script instance...ialex09:07, 12 September 2010

Comments

#Comment by 😂 (talk | contribs)   16:49, 29 June 2011

Missed one instance of the $useMaster rename in the constructor.

#Comment by IAlex (talk | contribs)   17:18, 29 June 2011

Fixed in r91080.

Status & tagging log