Skip to content

Commit

Permalink
Fix migration warnings if there aren't extnsions (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stell0 authored Nov 27, 2023
1 parent 1b9ae3f commit a52cefd
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions freepbx/initdb.d/migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')");
Expand Down

0 comments on commit a52cefd

Please sign in to comment.