root/modules/branches/2.10/sipstation/install.php

Revision 11109, 3.0 kB (checked in by p_lindheimer, 2 years ago)

remove functions now always included by utility.functions.php

Line 
1 <?php
2 /* $Id:$ */
3
4 /* Copyright (c) 2009 Bandwidth.com
5    Licensed for use by active FreePBX.com SIP Trunking Customers (SIPSTATION(tm)). Not licensed to be modified or redistributed in any fashion.
6    No guarantees or warranties provided, use at your own risk. See license included with module for more details.
7 */
8
9 global $db;
10 global $amp_conf;
11
12 /* Delete all occurences of the specified trunk from all routes that may use it
13  * this only gets called if the extensions table is still present and this is needed
14  */
15 function __core_routing_trunk_del($trunknum) {
16   global $db;
17
18   $sql = "DELETE FROM `extensions` WHERE `application` = 'Macro' AND `context` LIKE 'outrt-%' AND `args` LIKE 'dialout-%,$trunknum,%'";
19   $result = $db->query($sql);
20 }
21
22 /* A long standing bug resulted in routes with trunk numbers that had been deleted. Because trunk numbers are recycled (something that
23    should be removed in the future), this can result in a new trunk being created and then silently inserted as part of a route that is
24    not intended. This will find all phantom trunks and remove them from routes.
25
26    The following code should no longer be required with the new outbound routes stuff. However, it's remotely possible that this module
27    could get loaded on an upgrade scenario where core hasn't done a migration yet. Setting this module to depend on core makes for a
28    more painful upgrade process so we will simply leave this code in place since it checks for the extensions table and if not found
29    it does nothing. If found, it just manipulates that table which could still help in a subsequent migration to the new outbound routes.
30 */
31
32 /* Get a list of all trunks being used
33  */
34 outn(_("Checking routes for trunks.."));
35 $sql = "SELECT DISTINCT `args` FROM `extensions` WHERE `context` LIKE 'outrt-%' AND `application` = 'Macro' AND `args` LIKE 'dialout-%'";
36 $results = $db->getCol($sql);
37 if(DB::IsError($results)) {
38     $results = array();
39   out(_("ok"));
40 } else {
41   $trunks = array();
42   $trunks_hash = array();
43   foreach ($results as $trunk_call) {
44     if (preg_match('/^dialout-(?:trunk|enum|dundi),([\d]+),.*$/',$trunk_call,$match) != 1) {
45       out(_("error detected"));
46       out(sprintf(_("an erroneous entry, %s,  was found in extensions table that should not be there"),$trunk_call));
47     } else {
48       $trunks_hash[$match[1]] = "OUT_".$match[1];
49     }
50   }
51   $num_trunks = count($trunks_hash);
52   out(sprintf(_("found %s"),$num_trunks));
53
54   outn(_("checking for phantoms.."));
55
56   require_once($amp_conf['AMPWEBROOT'].'/admin/modules/core/functions.inc.php');
57   $trunks = core_trunks_list(true);
58  
59   $bad_trunks = array();
60   $cnt = 0;
61   foreach ($trunks_hash as $trunknum => $globalvar) {
62     $bad = true;
63     foreach ($trunks as $trunk) {
64       if ($trunk['globalvar'] == $globalvar) {
65         $bad = false;
66         break;
67       }
68     }
69     if ($bad) {
70       $cnt++;
71       outn("$trunknum..");
72       __core_routing_trunk_del($trunknum);
73     }
74   }
75   if ($cnt) {
76     out(sprintf(_("removed %s phantoms"),$cnt));
77   } else {
78     out(_("none"));
79   }
80 }
81 ?>
82
Note: See TracBrowser for help on using the browser.