From dec9456bc00c7ac5fbf9e70ececf3c20bac4dafa Mon Sep 17 00:00:00 2001 From: Dmitry Danilson Date: Tue, 24 Mar 2015 12:37:43 +0500 Subject: [PATCH] Fix findOne: it missed $record in case of no cache This commit deals with such notice, which appears each time we have no cache for record: "Notice: Undefined variable: record in /vendor/sammaye/mongoyii/EMongoDocument.php on line 843" --- EMongoDocument.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/EMongoDocument.php b/EMongoDocument.php index 3d6722d..3f3bf52 100755 --- a/EMongoDocument.php +++ b/EMongoDocument.php @@ -804,20 +804,18 @@ public function findOne($criteria = array(), $fields = array()) 'Executing findOne: '.'{$query:' . json_encode($query) . ',$project:' . json_encode($project) . '}', 'extensions.MongoYii.EMongoDocument' ); - + if( - $this->getDbConnection()->queryCachingCount > 0 + $this->getDbConnection()->queryCachingCount > 0 && $this->getDbConnection()->queryCachingDuration > 0 && $this->getDbConnection()->queryCacheID !== false - && ($cache = Yii::app()->getComponent($this->getDbConnection()->queryCacheID)) !== null + && ($cache = Yii::app()->getComponent($this->getDbConnection()->queryCacheID)) + && ($cacheKey = 'yii:dbquery'.$this->getDbConnection()->server.':'.$this->getDbConnection()->db .':'.$this->getDbConnection()->getSerialisedQuery($query, $project).':'.$this->getCollection()) + && ($result = $cache->get($cacheKey)) !== false ){ $this->getDbConnection()->queryCachingCount--; - $cacheKey = 'yii:dbquery' . $this->getDbConnection()->server . ':' . $this->getDbConnection()->db; - $cacheKey .= ':' . $this->getDbConnection()->getSerialisedQuery($query, $project) . ':' . $this->getCollection(); - if(($result = $cache->get($cacheKey)) !== false){ - Yii::trace('Query result found in cache', 'extensions.MongoYii.EMongoDocument'); - $record = $result[0]; - } + Yii::trace('Query result found in cache', 'extensions.MongoYii.EMongoDocument'); + $record = $result[0]; }else{ if($this->getDbConnection()->enableProfiling){ Yii::beginProfile( @@ -1458,4 +1456,4 @@ public function trace($func) { Yii::trace(get_class($this) . '.' . $func . '()', 'extensions.MongoYii.EMongoDocument'); } -} \ No newline at end of file +}