File tree 2 files changed +23
-7
lines changed
classes/Ushahidi/Repository
2 files changed +23
-7
lines changed Original file line number Diff line number Diff line change @@ -68,30 +68,42 @@ protected function selectQuery(Array $where = [])
68
68
69
69
// CreateRepository
70
70
public function create (Entity $ entity ) {
71
+ // Get record as an array
72
+ $ record = $ entity ->asArray ();
73
+ // .. then filter empty values and JSON encode properties
71
74
$ record = array_filter ($ this ->json_transcoder ->encode (
72
- $ entity -> asArray () ,
75
+ $ record ,
73
76
$ this ->json_properties
74
77
));
78
+ // Set the created time
75
79
$ record ['created ' ] = time ();
80
+ // And save if this is a saved search or collection
76
81
$ record ['search ' ] = (int )$ this ->savedSearch ;
82
+ // Finally, save the record to the DB
77
83
return $ this ->executeInsert ($ this ->removeNullValues ($ record ));
78
84
79
85
}
80
86
81
87
// UpdateRepository
82
88
public function update (Entity $ entity )
83
89
{
84
- $ record = array_filter ($ this ->json_transcoder ->encode (
85
- $ entity ->asArray (),
86
- $ this ->json_properties
87
- ));
90
+ // Get changed values
88
91
$ 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
89
100
$ record ['updated ' ] = time ();
90
101
102
+ // Finally, update the record in the DB
91
103
return $ this ->executeUpdate ([
92
104
'id ' => $ entity ->id ,
93
105
'search ' => (int )$ this ->savedSearch
94
- ], $ entity -> getChanged () );
106
+ ], $ record );
95
107
}
96
108
97
109
// DeleteRepository
Original file line number Diff line number Diff line change @@ -56,7 +56,10 @@ Feature: Testing the Sets API
56
56
And that the request "data" is:
57
57
"""
58
58
{
59
- "name":"Updated Search One"
59
+ "name":"Updated Search One",
60
+ "filter":{
61
+ "q":"updated"
62
+ }
60
63
}
61
64
"""
62
65
And that its "id" is "4"
@@ -65,6 +68,7 @@ Feature: Testing the Sets API
65
68
And the "id" property equals "4"
66
69
And the response has a "name" property
67
70
And the "name" property equals "Updated Search One"
71
+ And the "filter.q" property equals "updated"
68
72
Then the guzzle status code should be 200
69
73
70
74
Scenario : Updating a non-existent SavedSearch
You can’t perform that action at this time.
0 commit comments