diff --git a/libraries/src/MVC/Controller/ApiController.php b/libraries/src/MVC/Controller/ApiController.php index e1c138d1c246c..251968fcd6ced 100644 --- a/libraries/src/MVC/Controller/ApiController.php +++ b/libraries/src/MVC/Controller/ApiController.php @@ -423,6 +423,9 @@ protected function save($recordKey = null) $checkin = property_exists($table, $table->getColumnAlias('checked_out')); $data[$key] = $recordKey; + // Stored values of the fields which are not in the PATCH request + $storedValues = []; + if ($this->input->getMethod() === 'PATCH') { if ($recordKey && $table->load($recordKey)) { $fields = $table->getFields(); @@ -432,7 +435,8 @@ protected function save($recordKey = null) continue; } - $data[$field->Field] = $table->{$field->Field}; + $data[$field->Field] = $table->{$field->Field}; + $storedValues[$field->Field] = $table->{$field->Field}; } } } @@ -472,6 +476,17 @@ protected function save($recordKey = null) throw new InvalidParameterException(implode("\n", $messages)); } + // Stored values are already in UTC, so don't let the SERVER_UTC / USER_UTC form filter convert them a second time + foreach ($storedValues as $field => $value) { + if (!\array_key_exists($field, $validData)) { + continue; + } + + if (\in_array(strtoupper($form->getFieldAttribute($field, 'filter', '')), ['SERVER_UTC', 'USER_UTC'], true)) { + $validData[$field] = $value; + } + } + if (!isset($validData['tags'])) { $validData['tags'] = []; }