Skip to content

Commit

Permalink
ES: fixed issue with storing empty records
Browse files Browse the repository at this point in the history
  • Loading branch information
cebe committed Jun 4, 2014
1 parent df65a0f commit 59b9065
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
7 changes: 5 additions & 2 deletions extensions/elasticsearch/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.

6 changes: 5 additions & 1 deletion extensions/elasticsearch/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/extensions/elasticsearch/ActiveRecordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 59b9065

Please sign in to comment.