Merge "Follow-up I0b781c11 (2a55449): use User::getAutomaticGroups()."
[lhc/web/wiklou.git] / includes / SiteStats.php
index 2a1f25d..1c2c454 100644 (file)
@@ -1,4 +1,24 @@
 <?php
+/**
+ * Accessors and mutators for the site-wide statistics.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ */
 
 /**
  * Static accessor class for site_stats and related things
@@ -266,14 +286,13 @@ class SiteStatsUpdate implements DeferrableUpdate {
                        $this->doUpdatePendingDeltas();
                } else {
                        $dbw = wfGetDB( DB_MASTER );
-                       // Need a separate transaction because this a global lock
-                       $dbw->begin( __METHOD__ );
 
                        $lockKey = wfMemcKey( 'site_stats' ); // prepend wiki ID
                        if ( $rate ) {
                                // Lock the table so we don't have double DB/memcached updates
-                               if ( !$dbw->lock( $lockKey, __METHOD__, 1 ) ) {
-                                       $dbw->commit( __METHOD__ );
+                               if ( !$dbw->lockIsFree( $lockKey, __METHOD__ )
+                                       || !$dbw->lock( $lockKey, __METHOD__, 1 ) // 1 sec timeout
+                               ) {
                                        $this->doUpdatePendingDeltas();
                                        return;
                                }
@@ -287,6 +306,9 @@ class SiteStatsUpdate implements DeferrableUpdate {
                                $this->images   += ( $pd['ss_images']['+'] - $pd['ss_images']['-'] );
                        }
 
+                       // Need a separate transaction because this a global lock
+                       $dbw->begin( __METHOD__ );
+
                        // Build up an SQL query of deltas and apply them...
                        $updates = '';
                        $this->appendUpdate( $updates, 'ss_total_views', $this->views );
@@ -325,8 +347,8 @@ class SiteStatsUpdate implements DeferrableUpdate {
                        array(
                                'rc_user != 0',
                                'rc_bot' => 0,
-                               "rc_log_type != 'newusers' OR rc_log_type IS NULL",
-                               "rc_timestamp >= '{$dbw->timestamp( wfTimestamp( TS_UNIX ) - $wgActiveUserDays*24*3600 )}'",
+                               'rc_log_type != ' . $dbr->addQuotes( 'newusers' ) . ' OR rc_log_type IS NULL',
+                               'rc_timestamp >= ' . $dbr->addQuotes( $dbr->timestamp( wfTimestamp( TS_UNIX ) - $wgActiveUserDays*24*3600 ) ),
                        ),
                        __METHOD__
                );
@@ -369,7 +391,7 @@ class SiteStatsUpdate implements DeferrableUpdate {
        /**
         * @param $type string
         * @param $sign string ('+' or '-')
-        * @return void
+        * @return string
         */
        private function getTypeCacheKey( $type, $sign ) {
                return wfMemcKey( 'sitestatsupdate', 'pendingdelta', $type, $sign );
@@ -421,7 +443,7 @@ class SiteStatsUpdate implements DeferrableUpdate {
 
        /**
         * Reduce pending delta counters after updates have been applied
-        * @param Array Result of getPendingDeltas(), used for DB update
+        * @param Array $pd Result of getPendingDeltas(), used for DB update
         * @return void
         */
        protected function removePendingDeltas( array $pd ) {