From ba0dc99a1b72e0dc84790913febf67e1c8da97b0 Mon Sep 17 00:00:00 2001 From: Aeto-J <109135726+Aeto-J@users.noreply.github.com> Date: Mon, 31 Jul 2023 17:11:35 +0200 Subject: [PATCH] Simplified constructHistory function in PluginFieldsContainer class --- inc/container.class.php | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/inc/container.class.php b/inc/container.class.php index 0a18ea30..ae976236 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -1171,7 +1171,8 @@ public function updateFieldsValues($data, $itemtype, $massiveaction = false) $data['plugin_fields_containers_id'], $items_id, $itemtype, - $data + $data, + $obj ); } else { $first_found = array_pop($found); @@ -1184,7 +1185,7 @@ public function updateFieldsValues($data, $itemtype, $massiveaction = false) $items_id, $itemtype, $data, - $first_found + $obj ); } @@ -1205,7 +1206,7 @@ public static function constructHistory( $items_id, $itemtype, $data, - $old_values = [] + $field_obj ) { // Don't log few itemtypes $obj = new $itemtype(); @@ -1229,7 +1230,7 @@ public static function constructHistory( $data = array_diff_key($data, $blacklist_k); //add/update values condition - if (empty($old_values)) { + if (!isset($data['id'])) { // -- add new item -- foreach ($data as $key => $value) { @@ -1241,7 +1242,7 @@ public static function constructHistory( //find searchoption foreach ($searchoptions as $id_search_option => $searchoption) { if ($searchoption['linkfield'] == $key) { - $changes[0] = $id_search_option; + $changes[0] = $id_search_option; if ($searchoption['datatype'] === 'dropdown') { //manage dropdown values @@ -1277,19 +1278,10 @@ public static function constructHistory( } else { // -- update existing item -- - //find changes - $updates = []; - foreach ($old_values as $key => $old_value) { - if ( - !isset($data[$key]) - || empty($old_value) && empty($data[$key]) - || $old_value !== '' && $data[$key] == 'NULL' - ) { - continue; - } - - if ($data[$key] !== $old_value) { - $updates[$key] = [0, $old_value ?? '', $data[$key]]; + // construct $updates + if ($field_obj->updates) { + foreach ($field_obj->updates as $key) { + $updates[$key] = [0, $field_obj->oldvalues[$key], $field_obj->input[$key]]; } }