diff --git a/htdocs/recruitment/class/api_recruitments.class.php b/htdocs/recruitment/class/api_recruitments.class.php index 1acf80676d7..0b32a2fdfed 100644 --- a/htdocs/recruitment/class/api_recruitments.class.php +++ b/htdocs/recruitment/class/api_recruitments.class.php @@ -375,7 +375,7 @@ class Recruitments extends DolibarrApi } // Check mandatory fields - $result = $this->_validate($request_data); + $result = $this->_validate($request_data, $this->jobposition); foreach ($request_data as $field => $value) { if ($field === 'caller') { @@ -415,16 +415,16 @@ class Recruitments extends DolibarrApi } // Check mandatory fields - $result = $this->_validate($request_data); + $result = $this->_validate($request_data, $this->candidature); foreach ($request_data as $field => $value) { if ($field === 'caller') { // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again with the caller - $this->jobposition->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09'); + $this->candidature->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09'); continue; } - $this->jobposition->$field = $this->_checkValForAPI($field, $value, $this->jobposition); + $this->candidature->$field = $this->_checkValForAPI($field, $value, $this->candidature); } // Clean data @@ -686,25 +686,26 @@ class Recruitments extends DolibarrApi * Validate fields before create or update object * * @param ?array $data Array of data to validate + * @param CommonObject $object Object to validate against * @return array * * @throws RestException */ - private function _validate($data) + private function _validate($data, $object) { if ($data === null) { $data = array(); } - $jobposition = array(); - foreach ($this->jobposition->fields as $field => $propfield) { - if (in_array($field, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat')) || empty($propfield['notnull']) || $propfield['notnull'] != 1) { - continue; // Not a mandatory field + $result = array(); + foreach ($object->fields as $field => $propfield) { + if (in_array($field, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat', 'ref')) || empty($propfield['notnull']) || $propfield['notnull'] != 1 || !empty($propfield['noteditable']) || isset($propfield['default'])) { + continue; // Not a mandatory field or auto-generated field or has default value } if (!isset($data[$field])) { throw new RestException(400, "$field field missing"); } - $jobposition[$field] = $data[$field]; + $result[$field] = $data[$field]; } - return $jobposition; + return $result; } }