"; } } if (! function_exists("outn")) { function outn($text) { echo $text; } } /* Delete all occurences of the specified trunk from all routes that may use it */ if (!function_exists('core_routing_trunk_del')) { function core_routing_trunk_del($trunknum) { global $db; $sql = "DELETE FROM `extensions` WHERE `application` = 'Macro' AND `context` LIKE 'outrt-%' AND `args` LIKE 'dialout-%,$trunknum,%'"; $result = $db->query($sql); } } /* A long standing bug resulted in routes with trunk nubmers that had been deleted. Because trunk numbers are recyvled (something that 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 not intended. This will find all phantom trunks and remove them from routes. */ /* Get a list of all trunks being used */ outn(_("Checking routes for trunks..")); $sql = "SELECT DISTINCT `args` FROM `extensions` WHERE `context` LIKE 'outrt-%' AND `application` = 'Macro' AND `args` LIKE 'dialout-%'"; $results = $db->getCol($sql); if(DB::IsError($results)) { $results = array(); out(_("an error occured quering the extensions table for routes, skipping check")); } else { $trunks = array(); foreach ($results as $trunk_call) { if (preg_match('/^dialout-(?:trunk|enum|dundi),([\d]+),.*$/',$trunk_call,$match) != 1) { out(_("error detected")); out(sprintf(_("an eroneous entry, %s, was found in extensions table that should not be there"),$trunk_call)); } else { $trunks_hash[$match[1]] = "OUT_".$match[1]; } } $num_trunks = count($trunks_hash); out(sprintf(_("found %s"),$num_trunks)); outn(_("checking for phantoms..")); $trunks = core_trunks_list(true); $bad_trunks = array(); $cnt = 0; foreach ($trunks_hash as $trunknum => $globalvar) { $bad = true; foreach ($trunks as $trunk) { if ($trunk['globalvar'] == $globalvar) { $bad = false; break; } } if ($bad) { $cnt++; outn("$trunknum.."); core_routing_trunk_del($trunknum); } } if ($cnt) { out(sprintf(_("removed %s phantoms"),$cnt)); } else { out(_("none")); } } ?>