Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions lib/MongoQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;

}
}