fix: Fixed the org edit API

- it only worked if all fields were set
- switched to a different strategy where any changed field is updated
Iglocska 2017-01-22 17:35:35 +01:00
parent a22abaa106
commit a290e4254d
1 changed files with 11 additions and 0 deletions

View File

@ -135,6 +135,17 @@ class OrganisationsController extends AppController {
if (!isset($this->request->data['Organisation'])) {
$this->request->data['Organisation'] = $this->request->data;
}
$existingOrg = $this->Organisation->find('first', array('conditions' => array('Organisation.id' => $id)));
$changeFields = array('name', 'type', 'nationality', 'sector', 'contacts', 'description', 'local', 'uuid');
$temp = array('Organisation' => array());
foreach ($changeFields as $field) {
if (isset($this->request->data['Organisation'][$field])) {
$temp['Organisation'][$field] = $this->request->data['Organisation'][$field];
} else {
$temp['Organisation'][$field] = $existingOrg['Organisation'][$field];
}
$this->request->data = $temp;
}
}
$this->request->data['Organisation']['id'] = $id;
if ($this->Organisation->save($this->request->data)) {