https://www.mediawiki.org/wiki/Special:Code/MediaWiki/114344

Revision: 114344
Author:   demon
Date:     2012-03-21 03:36:52 +0000 (Wed, 21 Mar 2012)
Log Message:
-----------
Resolve issues with r109666: mixing getters and setters in the same function is 
confusing, so split it in 2. Also removes isset() to check for null

Modified Paths:
--------------
    trunk/extensions/InterfaceConcurrency/ApiConcurrency.php
    trunk/extensions/InterfaceConcurrency/includes/ConcurrencyCheck.php
    trunk/extensions/InterfaceConcurrency/tests/phpunit/ConcurrencyCheckTest.php

Modified: trunk/extensions/InterfaceConcurrency/ApiConcurrency.php
===================================================================
--- trunk/extensions/InterfaceConcurrency/ApiConcurrency.php    2012-03-21 
03:24:38 UTC (rev 114343)
+++ trunk/extensions/InterfaceConcurrency/ApiConcurrency.php    2012-03-21 
03:36:52 UTC (rev 114344)
@@ -30,7 +30,7 @@
 
                                // data to be utilized by the caller for 
checkout
                                if ( $params['ccaction'] === 'checkout' ) {
-                                       $lastCheckout = 
$concurrencyCheck->checkoutResult();
+                                       $lastCheckout = 
$concurrencyCheck->getCheckoutResult();
 
                                        if ( $res['result'] === 'success' ) {
                                                $user = $wgUser;

Modified: trunk/extensions/InterfaceConcurrency/includes/ConcurrencyCheck.php
===================================================================
--- trunk/extensions/InterfaceConcurrency/includes/ConcurrencyCheck.php 
2012-03-21 03:24:38 UTC (rev 114343)
+++ trunk/extensions/InterfaceConcurrency/includes/ConcurrencyCheck.php 
2012-03-21 03:36:52 UTC (rev 114344)
@@ -72,7 +72,7 @@
                                $cached['expiration'] > time()
                        ) {
                                // this is already checked out.
-                               $this->checkoutResult( $cached );
+                               $this->setCheckoutResult( $cached );
                                return false;
                        }
                }
@@ -105,7 +105,7 @@
                        $wgMemc->set( $cacheKey, $toCache, 
$this->expirationTime );
                        
                        $dbw->commit( __METHOD__ );
-                       $this->checkoutResult( $toCache );
+                       $this->setCheckoutResult( $toCache );
                        return true;
                }
 
@@ -145,7 +145,7 @@
                        );
                        
                        $dbw->rollback( __METHOD__ );
-                       $this->checkoutResult( $toCache );
+                       $this->setCheckoutResult( $toCache );
                        return false;
                }
 
@@ -172,7 +172,7 @@
                );
 
                $dbw->commit( __METHOD__ );
-               $this->checkoutResult( $toCache );
+               $this->setCheckoutResult( $toCache );
                return true;
        }
 
@@ -401,15 +401,22 @@
        /**
         * Return information about the owner of the record on which a checkout 
was last
         * attempted.
+        *
+        * @return array
+        */
+       public function getCheckoutResult() {
+               return $this->lastCheckout;
+       }
+
+       /**
+        * Set information about the owner of the record on which a checkout 
was last
+        * attempted.
         * 
         * @param $checkoutInfo array (optional) of checkout information to 
store
         * @return array
         */
-       public function checkoutResult( $checkoutInfo = null ) {
-               if( isset( $checkoutInfo ) ) { // true on empty array
-                       $this->lastCheckout = $checkoutInfo;
-               }
-               return $this->lastCheckout;
+       protected function setCheckoutResult( $checkoutInfo = array() ) {
+               $this->lastCheckout = $checkoutInfo;
        }
 
        /**

Modified: 
trunk/extensions/InterfaceConcurrency/tests/phpunit/ConcurrencyCheckTest.php
===================================================================
--- 
trunk/extensions/InterfaceConcurrency/tests/phpunit/ConcurrencyCheckTest.php    
    2012-03-21 03:24:38 UTC (rev 114343)
+++ 
trunk/extensions/InterfaceConcurrency/tests/phpunit/ConcurrencyCheckTest.php    
    2012-03-21 03:36:52 UTC (rev 114344)
@@ -59,7 +59,7 @@
 
                // tests
                $this->assertTrue( $first->checkout( $testKey ), "Initial 
checkout" );
-               $res = $first->checkoutResult();
+               $res = $first->getCheckoutResult();
                $this->assertEquals( $firstId, $res['userId'], "User matches on 
success");
                $this->assertTrue( array_key_exists( 'expiration', $res ), 
"Expiration is present");
                $this->assertTrue( $res['expiration'] > 0, "Expiration is a 
positive integer");
@@ -71,7 +71,7 @@
                $wgMemc->delete($cacheKey);
                $first->lastCheckout = array();
                $this->assertTrue( $first->checkout( $testKey ), "Cache miss" );
-               $res = $first->checkoutResult();
+               $res = $first->getCheckoutResult();
                $this->assertEquals( $firstId, $res['userId'], "User matches on 
success (nocache)");
                $this->assertTrue( array_key_exists( 'expiration', $res ), 
"Expiration is present (nocache)");
                $this->assertTrue( $res['expiration'] > 0, "Expiration is a 
positive integer (nocache)");
@@ -80,7 +80,7 @@
                        $second->checkout( $testKey ),
                        "Checkout of locked resource fails as different user"
                );
-               $res = $second->checkoutResult();
+               $res = $second->getCheckoutResult();
                $this->assertEquals( $firstId, $res['userId'], "Actual owner 
matches on failure");
                $this->assertTrue( $res['expiration'] > 0, "Expiration is a 
positive integer");
                


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to