Skip to content

Commit 8118d88

Browse files
committed
JSON encode saved search filters when updating (not just creating)
Refs T1678 Conflicts: application/classes/Ushahidi/Repository/Set.php
1 parent 4e2e2e1 commit 8118d88

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

application/classes/Ushahidi/Repository/Set.php

+18-6
Original file line numberDiff line numberDiff line change
@@ -68,30 +68,42 @@ protected function selectQuery(Array $where = [])
6868

6969
// CreateRepository
7070
public function create(Entity $entity) {
71+
// Get record as an array
72+
$record = $entity->asArray();
73+
// .. then filter empty values and JSON encode properties
7174
$record = array_filter($this->json_transcoder->encode(
72-
$entity->asArray(),
75+
$record,
7376
$this->json_properties
7477
));
78+
// Set the created time
7579
$record['created'] = time();
80+
// And save if this is a saved search or collection
7681
$record['search'] = (int)$this->savedSearch;
82+
// Finally, save the record to the DB
7783
return $this->executeInsert($this->removeNullValues($record));
7884

7985
}
8086

8187
// UpdateRepository
8288
public function update(Entity $entity)
8389
{
84-
$record = array_filter($this->json_transcoder->encode(
85-
$entity->asArray(),
86-
$this->json_properties
87-
));
90+
// Get changed values
8891
$record = $entity->getChanged();
92+
93+
// .. then JSON encode json properties
94+
$record = $this->json_transcoder->encode(
95+
$record,
96+
$this->json_properties
97+
);
98+
99+
// Set the updated time
89100
$record['updated'] = time();
90101

102+
// Finally, update the record in the DB
91103
return $this->executeUpdate([
92104
'id' => $entity->id,
93105
'search' => (int)$this->savedSearch
94-
], $entity->getChanged());
106+
], $record);
95107
}
96108

97109
// DeleteRepository

application/tests/features/api.savedsearch.feature

+5-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ Feature: Testing the Sets API
5656
And that the request "data" is:
5757
"""
5858
{
59-
"name":"Updated Search One"
59+
"name":"Updated Search One",
60+
"filter":{
61+
"q":"updated"
62+
}
6063
}
6164
"""
6265
And that its "id" is "4"
@@ -65,6 +68,7 @@ Feature: Testing the Sets API
6568
And the "id" property equals "4"
6669
And the response has a "name" property
6770
And the "name" property equals "Updated Search One"
71+
And the "filter.q" property equals "updated"
6872
Then the guzzle status code should be 200
6973

7074
Scenario: Updating a non-existent SavedSearch

0 commit comments

Comments
 (0)