From f7e23476ba6c991d73c2861fc8db2fc5d15c5a6b Mon Sep 17 00:00:00 2001 From: FusionPBX Date: Fri, 3 Oct 2025 11:59:46 -0600 Subject: [PATCH] Normalize the user data to match the database - Used to check if the data has changed - Only update modified data - Added the following - normalize null - normalize numeric - normalize string - normalize boolean (updated) --- resources/classes/database.php | 38 ++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/resources/classes/database.php b/resources/classes/database.php index 256f15f4d6..fb7aaffdfa 100644 --- a/resources/classes/database.php +++ b/resources/classes/database.php @@ -2514,22 +2514,43 @@ class database { $i = 0; foreach ($parent_field_array as $array_key => $array_value) { //skip child array - if (is_array($array_value)) { continue; } + if (is_array($array_value)) { continue; } - //normalize the boolean data - if ($array_value === 'true' || $array_value === 'false') { - if ($parent_results[$i][$array_key] === 0) { - $parent_results[$i][$array_key] = 'false'; + //get the variable type of the value + $database_field_type = gettype($parent_results[$i][$array_key]); + $user_field_type = gettype($array_value); + + //normalize the data to match the database + if ($database_field_type !== $user_field_type) { + //normalize null + if ($array_value === '') { + $array_value = null; } - if ($parent_results[$i][$array_key] === 1) { - $parent_results[$i][$array_key] = 'true'; + + //normalize string + if ($database_field_type === 'string') { + $array_value = (string)$array_value; + } + + //normalize numeric + if ($database_field_type === 'numeric') { + $array_value = intval($array_value); + } + + //normalize boolean + if ($database_field_type === 'boolean') { + if ($array_value === 'true') { + $array_value = true; + } else { + $array_value = false; + } } } //verify if the data in the database has been modified if ($parent_results[$i][$array_key] !== $array_value) { //echo "no match\n"; - //echo "$parent_name.$array_key ".($parent_results[0][$array_key])." != ".$array_value."\n\n"; + //echo "$parent_name.$array_key ".($parent_results[$i][$array_key])." != ".$array_value."\n\n"; $data_modified = true; break; } @@ -2541,7 +2562,6 @@ class database { //parent data - process the modified data if ($data_modified) { - //remove the child array and update the special values if (is_array($parent_field_array)) { foreach ($parent_field_array as $array_key => $array_value) {