From a52cefd5351494b5ba9cf3516b61a302f7b0031b Mon Sep 17 00:00:00 2001 From: Stefano Date: Mon, 27 Nov 2023 09:45:41 +0100 Subject: [PATCH] Fix migration warnings if there aren't extnsions (#89) --- freepbx/initdb.d/migration.php | 50 ++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/freepbx/initdb.d/migration.php b/freepbx/initdb.d/migration.php index 7923a66bf..f8be47569 100644 --- a/freepbx/initdb.d/migration.php +++ b/freepbx/initdb.d/migration.php @@ -30,34 +30,38 @@ $res = $stmt->fetchAll(\PDO::FETCH_ASSOC); $extensions = array_column($res, 'extension'); -# set media_encryption to no in freepbx sip table -$sql = "UPDATE `asterisk`.`sip` SET `data` = 'no' WHERE `keyword` = 'media_encryption' AND `id` IN (".str_repeat('?, ', count($extensions) - 1) . '?'.")"; -$stmt = $db->prepare($sql); -$stmt->execute($extensions); +if (count($extensions) > 0) { + $qm_string = str_repeat('?, ', count($extensions) - 1) . '?'; -# set srtp to true in rest_devices_phones table -$sql = "UPDATE `asterisk`.`rest_devices_phones` SET `srtp` = 1 WHERE `extension` IN (".str_repeat('?, ', count($extensions) - 1) . '?'.")"; -$stmt = $db->prepare($sql); -$stmt->execute($extensions); + # set media_encryption to no in freepbx sip table + $sql = "UPDATE `asterisk`.`sip` SET `data` = 'no' WHERE `keyword` = 'media_encryption' AND `id` IN ($qm_string)"; + $stmt = $db->prepare($sql); + $stmt->execute($extensions); -# configure proxy on all FreePBX extensions -$proxy_host = $_ENV['PUBLIC_IP']; -$proxy_port = 5060; + # set srtp to true in rest_devices_phones table + $sql = "UPDATE `asterisk`.`rest_devices_phones` SET `srtp` = 1 WHERE `extension` IN ($qm_string)"; + $stmt = $db->prepare($sql); + $stmt->execute($extensions); -$sql = "UPDATE `asterisk`.`sip` SET `data` = ? WHERE `keyword` = 'outbound_proxy' AND `id` IN (".str_repeat('?, ', count($extensions) - 1) . '?'.")"; -$stmt = $db->prepare($sql); -$stmt->execute(array_merge(['sip:'.$proxy_host.':'.$proxy_port], $extensions)); + # configure proxy on all FreePBX extensions + $proxy_host = $_ENV['PUBLIC_IP']; + $proxy_port = 5060; -# set rtp_symmetric to no in freepbx sip table -$sql = "UPDATE `asterisk`.`sip` SET `data` = 'no' WHERE `keyword` = 'rtp_symmetric' WHERE `id` IN (".str_repeat('?, ', count($extensions) - 1) . '?'.")"; -$stmt = $db->prepare($sql); -$stmt->execute($extensions); + $sql = "UPDATE `asterisk`.`sip` SET `data` = ? WHERE `keyword` = 'outbound_proxy' AND `id` IN ($qm_string)"; + $stmt = $db->prepare($sql); + $stmt->execute(array_merge(['sip:'.$proxy_host.':'.$proxy_port], $extensions)); -# set rewrite_contact to no in freepbx sip table -$sql = "UPDATE `asterisk`.`sip` SET `data` = 'no' WHERE `keyword` = 'rewrite_contact' WHERE `id` IN (".str_repeat('?, ', count($extensions) - 1) . '?'.")"; -$db->query($sql); -$stmt = $db->prepare($sql); -$stmt->execute($extensions); + # set rtp_symmetric to no in freepbx sip table + $sql = "UPDATE `asterisk`.`sip` SET `data` = 'no' WHERE `keyword` = 'rtp_symmetric' WHERE `id` IN ($qm_string)"; + $stmt = $db->prepare($sql); + $stmt->execute($extensions); + + # set rewrite_contact to no in freepbx sip table + $sql = "UPDATE `asterisk`.`sip` SET `data` = 'no' WHERE `keyword` = 'rewrite_contact' WHERE `id` IN ($qm_string)"; + $db->query($sql); + $stmt = $db->prepare($sql); + $stmt->execute($extensions); +} # migrate profiles, macro_permissions and permissions scheme to new format $db->query("INSERT INTO `rest_cti_macro_permissions` VALUES (12,'nethvoice_cti','NethVoice CTI','Enables access to NethVoice CTI application')");