From fbfc3b7099ceb59eb1e5fad30fc3c5714db99a3e Mon Sep 17 00:00:00 2001 From: frytimo Date: Tue, 26 May 2026 14:31:39 +0000 Subject: [PATCH] Fix cache contact id not cleared if speed dial field is empty (#7991) --- core/contacts/contact_edit.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/core/contacts/contact_edit.php b/core/contacts/contact_edit.php index c6018069e..4b62fcad0 100644 --- a/core/contacts/contact_edit.php +++ b/core/contacts/contact_edit.php @@ -428,10 +428,33 @@ $array['contacts'][0]['contact_phones'][$y]['phone_primary'] = $row["phone_primary"]; $array['contacts'][0]['contact_phones'][$y]['phone_description'] = $row["phone_description"]; - //clear the cache + // clear the speed dial cache only if speed dial is set if (!empty($row["phone_speed_dial"])) { $cache = new cache; + + // clear the cache for the submitted speed dial number $cache->delete("app.dialplan.speed_dial.".$row["phone_speed_dial"]."@".$_SESSION['domain_name']); + + // clear the cache for the old speed dial number if it exists and is different from the submitted speed dial number + if ($action == "update" && is_uuid($row["contact_phone_uuid"])) { + // original speed dial number is not available so we have to get it from the database + $sql = "select phone_speed_dial from v_contact_phones "; + $sql .= "where contact_phone_uuid = :contact_phone_uuid "; + $parameters['contact_phone_uuid'] = $row["contact_phone_uuid"]; + $old_phone_speed_dial = $database->execute($sql, $parameters, 'column'); + unset($sql, $parameters); + + // compare the original speed dial number to the newly submitted one + if (!empty($old_phone_speed_dial) && $old_phone_speed_dial != $row["phone_speed_dial"]) { + // they are different so we clear the old stale value from the cache + $cache->delete("app.dialplan.speed_dial.".$old_phone_speed_dial."@".$_SESSION['domain_name']); + } + } + } + + // always clear caller ID lookup cache when a phone number is saved + if (!empty($row["phone_number"])) { + $cache = $cache ?? new cache; $cache->delete("app:caller_id:lookup:domain_name:" . $_SESSION['domain_name'] . ":" . $row["phone_number"]); if (!empty($row["phone_country_code"])) { $cache->delete("app:caller_id:lookup:domain_name:" . $_SESSION['domain_name'] . ":" . $row["phone_country_code"] . $row["phone_number"]);