gateway_uuid.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. /*
  3. FusionPBX
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FusionPBX
  14. The Initial Developer of the Original Code is
  15. Mark J Crane <[email protected]>
  16. Portions created by the Initial Developer are Copyright (C) 2008-2012
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. include "root.php";
  22. require "resources/require.php";
  23. require_once "resources/check_auth.php";
  24. if (permission_exists('dialplan_edit')) {
  25. //access granted
  26. }
  27. else {
  28. echo "access denied";
  29. exit;
  30. }
  31. //get the includes
  32. require_once "resources/header.php";
  33. echo "<pre>\n";
  34. //get the domain, and gateway information
  35. $sql = "SELECT d.domain_uuid, d.domain_name, g.gateway_uuid, g.gateway FROM v_domains as d, v_gateways as g ";
  36. $sql .= "WHERE d.domain_uuid = g.domain_uuid \n";
  37. //echo $sql."<br />\n";
  38. $prep_statement = $db->prepare(check_sql($sql));
  39. $prep_statement->execute();
  40. $gateways = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  41. //print_r($gateways);
  42. unset($prep_statement);
  43. //start the atomic transaction
  44. $db->exec("BEGIN;");
  45. //migrate from gateway names to gateway uuids
  46. echo "<pre>\n";
  47. $sql = "SELECT dialplan_detail_uuid, dialplan_detail_data FROM v_dialplan_details ";
  48. $sql .= "WHERE dialplan_detail_data LIKE 'sofia/gateway/%' \n";
  49. //echo $sql."<br />\n";
  50. $prep_statement2 = $db->prepare(check_sql($sql));
  51. $prep_statement2->execute();
  52. $result = $prep_statement2->fetchAll(PDO::FETCH_NAMED);
  53. //unset($prep_statement2);
  54. //print_r($result);
  55. foreach($result as $field) {
  56. //set the variables
  57. $dialplan_detail_uuid = $field['dialplan_detail_uuid'];
  58. $dialplan_detail_data = $field['dialplan_detail_data'];
  59. //echo "dialplan_detail_data29: ".$dialplan_detail_data."<br />\n";
  60. //parse the data
  61. //sofia/gateway/domain_name-gateway_name/1208$1
  62. $data = substr($dialplan_detail_data, 14); //domain_name-gateway_name/1208$1
  63. $data = explode("/", $data);
  64. $deprecated = $data[0]; //domain_name-gateway_name
  65. //print_r($gateways);
  66. //gateways
  67. foreach ($gateways as $row) {
  68. //set the variables
  69. $domain_uuid = $row["domain_uuid"];
  70. $domain_name = $row["domain_name"];
  71. $gateway = $row["gateway"];
  72. //multi-tenant gateway name
  73. if (count($_SESSION['domains']) > 1) {
  74. $original_gateway_name = $domain_name."-".$gateway;
  75. }
  76. //single tenant gateway name
  77. if (count($_SESSION['domains']) == 1) {
  78. $original_gateway_name = $gateway;
  79. }
  80. //find a match
  81. if ($deprecated == $original_gateway_name) {
  82. //get the variables
  83. $domain_uuid = $row["domain_uuid"];
  84. $gateway_uuid = $row["gateway_uuid"];
  85. $postfix = substr($dialplan_detail_data, (strlen($deprecated) + 14));
  86. //update the data
  87. $bridge = "sofia/gateway/".$gateway_uuid.$postfix;
  88. $sql = "update v_dialplan_details set ";
  89. $sql .= "dialplan_detail_data = '".$bridge."' ";
  90. $sql .= "where dialplan_detail_uuid = '$dialplan_detail_uuid'; ";
  91. $db->exec(check_sql($sql));
  92. echo $sql."<br />\n";
  93. unset($sql);
  94. //exit the loop
  95. break;
  96. }
  97. }
  98. }
  99. echo "completed";
  100. echo "<pre>\n";
  101. //commit the atomic transaction
  102. $count = $db->exec("COMMIT;");
  103. //show the footer
  104. echo "</pre>\n";
  105. require_once "resources/footer.php";
  106. ?>