http://www.mediawiki.org/wiki/Special:Code/MediaWiki/97270

Revision: 97270
Author:   nikerabbit
Date:     2011-09-16 14:11:41 +0000 (Fri, 16 Sep 2011)
Log Message:
-----------
Fixed two bugs in Stats code:
* Stats for subgroups of aggregate groups were not loaded -> those would be 
calculated again and inserted into database, which would fail with duplicate key
* Calculated stats was assigned into wrong place, which lead to duplicate 
calculation of stats for same group, again failing with db error

Modified Paths:
--------------
    trunk/extensions/Translate/utils/MessageGroupStats.php

Modified: trunk/extensions/Translate/utils/MessageGroupStats.php
===================================================================
--- trunk/extensions/Translate/utils/MessageGroupStats.php      2011-09-16 
14:04:18 UTC (rev 97269)
+++ trunk/extensions/Translate/utils/MessageGroupStats.php      2011-09-16 
14:11:41 UTC (rev 97270)
@@ -176,13 +176,26 @@
                return $stats;
        }
 
+       protected static function expandAggregates( MessageGroup $group ) {
+               $flattened = array( $group->getId() );
+               if ( $group instanceof AggregateMessageGroup ) {
+                       foreach ( $group->getGroups() as $subgroup ) {
+                               $flattened = array_merge( $flattened, 
self::expandAggregates( $subgroup ) );
+                       }
+               }
+               return $flattened;
+       }
+
+       
+
        protected static function forGroupInternal( $group, $stats = array() ) {
-               $id = $group->getId();
-               $res = self::selectRowsIdLang( $id, null );
+               $ids = array_unique( self::expandAggregates( $group ) );
+               $res = self::selectRowsIdLang( $ids, null );
                $stats = self::extractResults( $res, $stats );
 
                # Go over each language filling missing entries
-               $languages = array_keys( Language::getLanguageNames() );
+               $id = $group->getId();
+               $languages = array_keys( Language::getLanguageNames( false ) );
                foreach ( $languages as $code ) {
                        if ( isset( $stats[$id][$code] ) ) continue;
                        $stats[$id][$code] = self::forItemInternal( $stats, 
$group, $code );
@@ -210,14 +223,9 @@
                $id = $group->getId();
 
                if ( self::$timeStart !== null && ( microtime( true ) - 
self::$timeStart ) > self::$limit ) {
-                       return array( null, null, null );
+                       return $stats[$id][$code] = array( null, null, null );
                }
 
-               // Might happen when called recursively
-               if ( isset( $stats[$id][$code] ) ) {
-                       return $stats[$id][$code];
-               }
-
                if ( $group instanceof AggregateMessageGroup ) {
                        $aggregates = array( 0, 0, 0 );
                        foreach ( $group->getGroups() as $sid => $sgroup ) {
@@ -226,7 +234,7 @@
                                }
                                $aggregates = self::multiAdd( $aggregates, 
$stats[$sid][$code] );
                        }
-                       $stats[$id] = $aggregates;
+                       $stats[$id][$code] = $aggregates;
                } else {
                        $aggregates = self::calculateGroup( $group, $code );
                }


_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to