From 334820047390abb72b3c6b97f2acf285a732479c Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 7 Sep 2016 09:18:37 -0700 Subject: [PATCH] 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 --- includes/libs/objectcache/WANObjectCache.php | 4 ++-- .../phpunit/includes/libs/objectcache/WANObjectCacheTest.php | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) 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() { -- 2.20.1