Retry getting CatChange RC from master
authoraddshore <addshorewiki@gmail.com>
Mon, 28 Sep 2015 18:34:05 +0000 (19:34 +0100)
committeraddshore <addshorewiki@gmail.com>
Wed, 30 Sep 2015 22:09:12 +0000 (23:09 +0100)
This adds optional flags to Revision::getRecentChange
And uses them in CategoryMembershipChange

Bug: T109700
Change-Id: I197ebccf1f62cdcb03ce4daa2527b973e495236c

includes/Revision.php
includes/changes/CategoryMembershipChange.php
includes/changes/RecentChange.php

index 6584207..90d6265 100644 (file)
@@ -948,18 +948,25 @@ class Revision implements IDBAccessObject {
        /**
         * Get the RC object belonging to the current revision, if there's one
         *
+        * @param int $flags (optional) $flags include:
+        *      Revision::READ_LATEST  : Select the data from the master
+        *
         * @since 1.22
         * @return RecentChange|null
         */
-       public function getRecentChange() {
+       public function getRecentChange( $flags = 0 ) {
                $dbr = wfGetDB( DB_SLAVE );
+
+               list( $dbType, ) = DBAccessObjectUtils::getDBOptions( $flags );
+
                return RecentChange::newFromConds(
                        array(
                                'rc_user_text' => $this->getUserText( Revision::RAW ),
                                'rc_timestamp' => $dbr->timestamp( $this->getTimestamp() ),
                                'rc_this_oldid' => $this->getId()
                        ),
-                       __METHOD__
+                       __METHOD__,
+                       $dbType
                );
        }
 
index 2533a5b..a12a1d8 100644 (file)
@@ -166,8 +166,10 @@ class CategoryMembershipChange {
 
                # If no revision is given, the change was probably triggered by parser functions
                if ( $revision !== null ) {
-                       // TODO if no RC try again from the master DB?
                        $correspondingRc = $this->revision->getRecentChange();
+                       if ( $correspondingRc === null ) {
+                               $correspondingRc = $this->revision->getRecentChange( Revision::READ_LATEST );
+                       }
                        if ( $correspondingRc !== null ) {
                                $bot = $correspondingRc->getAttribute( 'rc_bot' ) ?: 0;
                                $ip = $correspondingRc->getAttribute( 'rc_ip' ) ?: '';
index b681f7f..2ccc24b 100644 (file)
@@ -173,11 +173,17 @@ class RecentChange {
         *
         * @param array $conds Array of conditions
         * @param mixed $fname Override the method name in profiling/logs
+        * @param int $dbType DB_* constant
+        *
         * @return RecentChange|null
         */
-       public static function newFromConds( $conds, $fname = __METHOD__ ) {
-               $dbr = wfGetDB( DB_SLAVE );
-               $row = $dbr->selectRow( 'recentchanges', self::selectFields(), $conds, $fname );
+       public static function newFromConds(
+               $conds,
+               $fname = __METHOD__,
+               $dbType = DB_SLAVE
+       ) {
+               $db = wfGetDB( $dbType );
+               $row = $db->selectRow( 'recentchanges', self::selectFields(), $conds, $fname );
                if ( $row !== false ) {
                        return self::newFromRow( $row );
                } else {