From e2a0725ff5aca6dbab56be53ef543a00c75e9f4c Mon Sep 17 00:00:00 2001 From: Madushan Gamage Date: Wed, 25 Feb 2015 16:00:39 +0800 Subject: [PATCH] fixed deprecations(connected property on MongoClient) in MongoQueue --- lib/MongoQueue.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/MongoQueue.php b/lib/MongoQueue.php index 85e0a00..bdcaad7 100644 --- a/lib/MongoQueue.php +++ b/lib/MongoQueue.php @@ -178,7 +178,7 @@ protected static function getDatabase($hint = null) if ($connection == null) throw new Exception("BaseMongoRecord::connection must be initialized to a valid Mongo object"); - if (!$connection->connected) + if (!self::isConnected()) $connection->connect(); return $connection->selectDB(self::$database); @@ -196,7 +196,7 @@ protected static function getCollection($hint = null) throw new Exception("BaseMongoRecord::connection must be initialized to a valid Mongo object"); - if (!$connection->connected) + if (!$connection->is) $connection->connect(); return $connection->selectCollection(self::$database, $collection_name); @@ -218,4 +218,17 @@ function ($className) use ($environment) self::$environmentLoaded = true; } } + + private static function isConnected(){ + + if (!(self::$connection instanceof \MongoClient || self::$connection instanceof \Mongo)) { + return false; + } + /* MongoClient::$connected is deprecated in 1.5.0+ + */ + return version_compare(phpversion('mongo'), '1.5.0', '<') + ? self::$connection + : count(self::$connection->getHosts()) > 0; + + } }