From 89256112174bd32ef0964b4cf7db26e4a75fa088 Mon Sep 17 00:00:00 2001 From: asus Date: Mon, 8 Apr 2024 22:30:56 +0200 Subject: [PATCH] smal fixe in history presentation --- plugins/cipf_plugin/php/_utils_acf_fields.php | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/plugins/cipf_plugin/php/_utils_acf_fields.php b/plugins/cipf_plugin/php/_utils_acf_fields.php index 9577b43..21cd52c 100644 --- a/plugins/cipf_plugin/php/_utils_acf_fields.php +++ b/plugins/cipf_plugin/php/_utils_acf_fields.php @@ -130,6 +130,7 @@ function set_acf_field_CIPF($acf_field, $acf_value, $acf_id) { Plgntls::debug_infos(); $acf_history = Cipf::ACF_HISTORY; + $old_value = get_acf_field_CIPF($acf_field, $acf_id); /* * if acf_value is the name of a key in const acf_field, * then we want to get its value from there, @@ -146,16 +147,22 @@ function set_acf_field_CIPF($acf_field, $acf_value, $acf_id) { /* * create history + * only if value has changed. Or not ? + * why using new_value and not $value ? -> because acf can format fields * */ - $old_history = get_acf_field_CIPF($acf_history, $acf_id); - $france_timezone = new DateTimeZone("Europe/Paris"); - $date_now = date_create('now', $france_timezone)->format('d/m/Y H:i:s'); - $acf_field_name = $acf_field['_name']; - $history = "- [$date_now] '$acf_field_name' : '$value' + $new_value = get_acf_field_CIPF($acf_field, $acf_id); + if ($new_value !== $old_value) { + $old_history = get_acf_field_CIPF($acf_history, $acf_id); + $france_timezone = new DateTimeZone("Europe/Paris"); + $date_now = date_create('now', $france_timezone)->format('d/m/Y H:i:s'); + $acf_field_name = $acf_field['_name']; + // we use the real newline, so must not tabulate + $history = "- [$date_now] '$acf_field_name' : '$old_value' -> '$new_value' "; - $history .= $old_history; - update_field($acf_history['_name'], $history, $acf_id); + $history .= $old_history; + update_field($acf_history['_name'], $history, $acf_id); + } } function get_acf_field_CIPF($acf_field, $acf_id) { Plgntls::debug_infos();