From: Aaron Schulz Date: Wed, 7 Sep 2016 16:18:37 +0000 (-0700) Subject: Make adaptiveTTL() less strict about $mtime type X-Git-Tag: 1.31.0-rc.0~5730 X-Git-Url: http://git.cyclocoop.org//%27http:/jquery.khurshid.com/ifixpng.php/%27?a=commitdiff_plain;h=334820047390abb72b3c6b97f2acf285a732479c;p=lhc%2Fweb%2Fwiklou.git Make adaptiveTTL() less strict about $mtime type Callers using wfTimestamp( TS_UNIX, ... ) where getting $minTTL due to the output being a string number. Change-Id: I6b67a941940f40ef9a543f11d0dbccacafaaa53b --- diff --git a/includes/libs/objectcache/WANObjectCache.php b/includes/libs/objectcache/WANObjectCache.php index 8de68ded96..06b87e0483 100644 --- a/includes/libs/objectcache/WANObjectCache.php +++ b/includes/libs/objectcache/WANObjectCache.php @@ -1086,8 +1086,8 @@ class WANObjectCache implements IExpiringStore, LoggerAwareInterface { * @since 1.28 */ public function adaptiveTTL( $mtime, $maxTTL, $minTTL = 30, $factor = .2 ) { - if ( is_float( $mtime ) ) { - $mtime = (int)$mtime; // ignore fractional seconds + if ( is_float( $mtime ) || ctype_digit( $mtime ) ) { + $mtime = (int)$mtime; // handle fractional seconds and string integers } if ( !is_int( $mtime ) || $mtime <= 0 ) { diff --git a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php index aeb466629d..abef758a42 100644 --- a/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php +++ b/tests/phpunit/includes/libs/objectcache/WANObjectCacheTest.php @@ -734,6 +734,11 @@ class WANObjectCacheTest extends MediaWikiTestCase { $this->assertGreaterThanOrEqual( $adaptiveTTL - $margin, $ttl ); $this->assertLessThanOrEqual( $adaptiveTTL + $margin, $ttl ); + + $ttl = $this->cache->adaptiveTTL( (string)$mtime, $maxTTL, $minTTL, $factor ); + + $this->assertGreaterThanOrEqual( $adaptiveTTL - $margin, $ttl ); + $this->assertLessThanOrEqual( $adaptiveTTL + $margin, $ttl ); } public static function provideAdaptiveTTL() {