diff --git a/extensions/elasticsearch/CHANGELOG.md b/extensions/elasticsearch/CHANGELOG.md index ceaa33fa341..60ab3fe7853 100644 --- a/extensions/elasticsearch/CHANGELOG.md +++ b/extensions/elasticsearch/CHANGELOG.md @@ -4,11 +4,12 @@ Yii Framework 2 elasticsearch extension Change Log 2.0.0-rc under development -------------------------- +- Bug #3587: Fixed an issue with storing empty records (cebe) +- Enh #3520: Added `unlinkAll()`-method to active record to remove all records of a model relation (NmDimas, samdark, cebe) +- Enh #3527: Added `highlight` property to Query and ActiveRecord. (Borales) - Chg: asArray in ActiveQuery is now equal to using the normal Query. This means, that the output structure has changed and `with` is supported anymore. (cebe) - Chg: Deletion of a record is now also considered successful if the record did not exist. (cebe) - Chg: Requirement changes: Yii now requires elasticsearch version 1.0 or higher (cebe) -- Enh #3520: Added `unlinkAll()`-method to active record to remove all records of a model relation (NmDimas, samdark, cebe) -- Enh #3527: Added `highlight` property to Query and ActiveRecord. (Borales) 2.0.0-beta April 13, 2014 @@ -27,7 +28,9 @@ Yii Framework 2 elasticsearch extension Change Log All relational queries are now directly served by `ActiveQuery` allowing to use custom scopes in relations (cebe) + 2.0.0-alpha, December 1, 2013 ----------------------------- - Initial release. + diff --git a/extensions/elasticsearch/Command.php b/extensions/elasticsearch/Command.php index 7528f0f7af4..6654efd1593 100644 --- a/extensions/elasticsearch/Command.php +++ b/extensions/elasticsearch/Command.php @@ -80,7 +80,11 @@ public function search($options = []) */ public function insert($index, $type, $data, $id = null, $options = []) { - $body = is_array($data) ? Json::encode($data) : $data; + if (empty($data)) { + $body = '{}'; + } else { + $body = is_array($data) ? Json::encode($data) : $data; + } if ($id !== null) { return $this->db->put([$index, $type, $id], $options, $body); diff --git a/tests/unit/extensions/elasticsearch/ActiveRecordTest.php b/tests/unit/extensions/elasticsearch/ActiveRecordTest.php index 045f112cb21..4b05aa205b8 100644 --- a/tests/unit/extensions/elasticsearch/ActiveRecordTest.php +++ b/tests/unit/extensions/elasticsearch/ActiveRecordTest.php @@ -186,6 +186,16 @@ public function setUp() $db->createCommand()->flushIndex('yiitest'); } + public function testSaveNoChanges() + { + // this should not fail with exception + $customer = new Customer(); + // insert + $customer->save(false); + // update + $customer->save(false); + } + public function testFindAsArray() { // asArray