Fix initSiteStats.php maintenance script
authorThis, that and the other <at.light@live.com.au>
Tue, 27 May 2014 08:09:24 +0000 (18:09 +1000)
committerLegoktm <legoktm.wikipedia@gmail.com>
Sun, 29 Jun 2014 00:12:16 +0000 (00:12 +0000)
It appears not to have worked for some time, as it either calls a protected
function ($counter->refresh()) or an undefined function
($counter->update()) depending on the parameters specified.

Bug: 65214
Change-Id: Ia7d867792b84c98714ec6dbbfef09745e875c8bc

includes/SiteStats.php
maintenance/initSiteStats.php

index 4e737d1..e5c1e17 100644 (file)
@@ -273,7 +273,8 @@ class SiteStatsInit {
        private $db;
 
        // Various stats
-       private $mEdits, $mArticles, $mPages, $mUsers, $mViews, $mFiles = 0;
+       private $mEdits = null, $mArticles = null, $mPages = null;
+       private $mUsers = null, $mViews = null, $mFiles = null;
 
        /**
         * Constructor
@@ -402,16 +403,17 @@ class SiteStatsInit {
        }
 
        /**
-        * Refresh site_stats.
+        * Refresh site_stats. If you want ss_total_views to be updated, be sure to
+        * call views() first.
         */
-       protected function refresh() {
+       public function refresh() {
                $values = array(
                        'ss_row_id' => 1,
-                       'ss_total_edits' => $this->mEdits,
-                       'ss_good_articles' => $this->mArticles,
-                       'ss_total_pages' => $this->mPages,
-                       'ss_users' => $this->mUsers,
-                       'ss_images' => $this->mFiles,
+                       'ss_total_edits' => ( $this->mEdits === null ? $this->edits() : $this->mEdits ),
+                       'ss_good_articles' => ( $this->mArticles === null ? $this->articles() : $this->mArticles ),
+                       'ss_total_pages' => ( $this->mPages === null ? $this->pages() : $this->mPages ),
+                       'ss_users' => ( $this->mUsers === null ? $this->users() : $this->mUsers ),
+                       'ss_images' => ( $this->mFiles === null ? $this->files() : $this->mFiles ),
                ) + (
                        $this->mViews ? array( 'ss_total_views' => $this->mViews ) : array()
                );
index c368c3f..49e0e9d 100644 (file)
@@ -69,21 +69,19 @@ class InitSiteStats extends Maintenance {
                        $this->output( "{$views}\n" );
                }
 
+               if ( $this->hasOption( 'update' ) ) {
+                       $this->output( "\nUpdating site statistics..." );
+                       $counter->refresh();
+                       $this->output( "done.\n" );
+               }
+
                if ( $this->hasOption( 'active' ) ) {
-                       $this->output( "Counting active users..." );
+                       $this->output( "\nCounting and updating active users..." );
                        $active = SiteStatsUpdate::cacheUpdate( wfGetDB( DB_MASTER ) );
                        $this->output( "{$active}\n" );
                }
 
-               $this->output( "\nUpdating site statistics..." );
-
-               if ( $this->hasOption( 'update' ) ) {
-                       $counter->update();
-               } else {
-                       $counter->refresh();
-               }
-
-               $this->output( "done.\n" );
+               $this->output( "\nDone.\n" );
        }
 }