From 80cffb0a7ab5d756f61af1ddd854c048f66e1a5c Mon Sep 17 00:00:00 2001 From: Esteban Zeller Date: Tue, 24 Feb 2015 19:09:08 -0300 Subject: [PATCH 1/2] Changed update all function Changed the updateAll function to use: - Multi insted of multiple ( for mongodb 2.4.9 ) - Convert conditions when using "_id" as primary key to the correspondent value. --- Model/Datasource/MongodbSource.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Model/Datasource/MongodbSource.php b/Model/Datasource/MongodbSource.php index 3ce32e1..789e3ce 100755 --- a/Model/Datasource/MongodbSource.php +++ b/Model/Datasource/MongodbSource.php @@ -890,19 +890,33 @@ public function updateAll(&$Model, $fields = null, $conditions = null) { $this->_prepareLogQuery($Model); // just sets a timer $table = $this->fullTableName($Model); + if (!is_null($conditions)) { + foreach ($conditions as $key => &$condition) { + if ($key == $Model->primaryKey) { + if (is_array($condition)) { + foreach($condition as &$c) { + $c = "ObjectId(".$c.")"; + } + $condition = array( '$in' => $condition ); + } else { + $condition = "ObjectId(".$condition.")"; + } + } + } + } try{ if ($this->_driverVersion >= '1.3.0') { // not use 'upsert' $return = $this->_db ->selectCollection($table) - ->update($conditions, $fields, array("multiple" => true, 'safe' => true)); + ->update($conditions, $fields, array("multi" => true, 'safe' => true)); if (isset($return['updatedExisting'])) { $return = $return['updatedExisting']; } } else { $return = $this->_db ->selectCollection($table) - ->update($conditions, $fields, array("multiple" => true)); + ->update($conditions, $fields, array("multi" => true)); } } catch (MongoException $e) { $this->error = $e->getMessage(); @@ -911,7 +925,7 @@ public function updateAll(&$Model, $fields = null, $conditions = null) { if ($this->fullDebug) { $this->logQuery("db.{$table}.update( :conditions, :fields, :params )", - array('conditions' => $conditions, 'fields' => $fields, 'params' => array("multiple" => true)) + array('conditions' => $conditions, 'fields' => $fields, 'params' => array("multi" => true)) ); } return $return; From 8e60ffecee89e3618a62b5e260cb769cdb09e53e Mon Sep 17 00:00:00 2001 From: Esteban Zeller Date: Tue, 24 Feb 2015 19:48:28 -0300 Subject: [PATCH 2/2] Update MongodbSource.php Small change to use already implemented function for converting primary key to mongodb elements --- Model/Datasource/MongodbSource.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/Model/Datasource/MongodbSource.php b/Model/Datasource/MongodbSource.php index 789e3ce..c880fb3 100755 --- a/Model/Datasource/MongodbSource.php +++ b/Model/Datasource/MongodbSource.php @@ -889,18 +889,11 @@ public function updateAll(&$Model, $fields = null, $conditions = null) { $fields = $this->setMongoUpdateOperator($Model, $fields); $this->_prepareLogQuery($Model); // just sets a timer - $table = $this->fullTableName($Model); + $table = $this->fullTableName($Model); if (!is_null($conditions)) { - foreach ($conditions as $key => &$condition) { - if ($key == $Model->primaryKey) { - if (is_array($condition)) { - foreach($condition as &$c) { - $c = "ObjectId(".$c.")"; - } - $condition = array( '$in' => $condition ); - } else { - $condition = "ObjectId(".$condition.")"; - } + foreach ($conditions as $key => &$cond ) { + if ($key === $Model->primaryKey) { + $this->_convertId($cond, true); } } }