Efficiency for app defaults.

This commit is contained in:
markjcrane 2016-07-01 13:02:31 -06:00
parent 640d463fb7
commit 52c1726fe6
2 changed files with 140 additions and 203 deletions

View File

@ -24,57 +24,8 @@
Mark J Crane <markjcrane@fusionpbx.com>
*/
//if there is more than one domain then set the default context to the domain name
/*
if (count($_SESSION['domains']) > 1) {
$sql = "select * from v_dialplans ";
$sql .= "where dialplan_context = 'default' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
foreach ($result as &$row) {
$domain_uuid = $row["domain_uuid"];
$dialplan_uuid = $row["dialplan_uuid"];
$dialplan_context = $_SESSION['domains'][$domain_uuid]['domain_name'];
$sql = "update v_dialplans set ";
$sql .= "dialplan_context = '$dialplan_context' ";
$sql .= "where domain_uuid = '$domain_uuid' ";
$sql .= "and dialplan_uuid = '$dialplan_uuid' ";
$db->exec(check_sql($sql));
unset($sql);
}
}
*/
//remove the global dialplan that calls app.lua dialplan
if (count($_SESSION['domains']) > 1) {
//get the dialplan data
$sql = "select * from v_dialplans ";
$sql .= "where app_uuid = '34dd307b-fffe-4ead-990c-3d070e288126' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
foreach ($result as &$row) {
$dialplan_uuid = $row["dialplan_uuid"];
}
unset($prep_statement);
//delete child data
if (isset($dialplan_uuid)) {
$sql = "delete from v_dialplan_details ";
$sql .= "where dialplan_uuid = '".$dialplan_uuid."'; ";
$db->query($sql);
unset($sql);
}
//delete parent data
if (isset($dialplan_uuid)) {
$sql = "delete from v_dialplans ";
$sql .= "where dialplan_uuid = '".$dialplan_uuid."'; ";
$db->query($sql);
unset($sql,$dialplan_uuid);
}
}
//only run the following code if the directory exists
/*
if (is_dir($_SESSION['switch']['dialplan']['dir'])) {
//write the dialplan/default.xml if it does not exist
//set the path
@ -102,8 +53,10 @@
fclose($fh);
}
}
*/
//get the $apps array from the installed apps from the core and mod directories
if ($domains_processed == 1) {
$xml_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/resources/switch/conf/dialplan/*.xml");
foreach ($xml_list as &$xml_file) {
//get and parse the xml
@ -118,7 +71,6 @@
}
//dialplan class
$dialplan = new dialplan;
$dialplan->domain_uuid = $domain_uuid;
$dialplan->dialplan_order = $dialplan_order;
$dialplan->default_context = $domain_name;
if ($display_type == "text") {
@ -127,37 +79,7 @@
$dialplan->xml = $xml_string;
$dialplan->import();
}
//add the global dialplan to inbound routes
/*
if ($domains_processed == 1) {
$sql = "select count(*) as num_rows from v_dialplans ";
$sql .= "where dialplan_uuid = 'd4e06654-e394-444a-b3af-4c3d54aebbec' ";
$prep_statement = $db->prepare(check_sql($sql));
if ($prep_statement) {
$prep_statement->execute();
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
if ($row['num_rows'] == 0) {
$sql = "INSERT INTO v_dialplans ";
$sql .= "(dialplan_uuid, app_uuid, dialplan_context, dialplan_name, dialplan_continue, dialplan_order, dialplan_enabled) ";
$sql .= "VALUES ('d4e06654-e394-444a-b3af-4c3d54aebbec', 'c03b422e-13a8-bd1b-e42b-b6b9b4d27ce4', 'public', 'global', 'true', '0', 'false');";
$db->query($sql);
$sql = "INSERT INTO v_dialplan_details ";
$sql .= "(dialplan_uuid, dialplan_detail_uuid, dialplan_detail_tag, dialplan_detail_type, dialplan_detail_data, dialplan_detail_order) ";
$sql .= "VALUES ('d4e06654-e394-444a-b3af-4c3d54aebbec', '5e1062d8-6842-4890-a78a-388e8dd5bbaf', 'condition', 'context', 'public', '10');";
$db->query($sql);
$sql = "INSERT INTO v_dialplan_details ";
$sql .= "(dialplan_uuid, dialplan_detail_uuid, dialplan_detail_tag, dialplan_detail_type, dialplan_detail_data, dialplan_detail_order) ";
$sql .= "VALUES ('d4e06654-e394-444a-b3af-4c3d54aebbec', 'bdafd4aa-6633-48fc-970e-bc2778f3f022', 'action', 'lua', 'app.lua dialplan', '20');";
$db->query($sql);
unset($sql);
}
unset($prep_statement);
}
}
*/
//add not found dialplan to inbound routes
/*

View File

@ -228,39 +228,39 @@ include "root.php";
}
private function app_uuid_exists() {
$sql = "select count(*) as num_rows from v_dialplans ";
$sql = "select domain_uuid from v_dialplans ";
$sql .= "where (domain_uuid = '".$this->domain_uuid."' or domain_uuid is null) ";
$sql .= "and app_uuid = '".$this->app_uuid."' ";
$prep_statement = $this->db->prepare(check_sql($sql));
if ($prep_statement) {
$prep_statement->execute();
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
if ($row['num_rows'] > 0) {
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
if (count($result)) {
return true;
}
else {
return false;
}
}
unset($prep_statement, $result);
unset($sql, $prep_statement, $result);
}
public function dialplan_exists() {
$sql = "select count(*) as num_rows from v_dialplans ";
$sql = "select domain_uuid from v_dialplans ";
$sql .= "where (domain_uuid = '".$this->domain_uuid."' or domain_uuid is null)";
$sql .= "and dialplan_uuid = '".$this->dialplan_uuid."' ";
$prep_statement = $this->db->prepare(check_sql($sql));
if ($prep_statement) {
$prep_statement->execute();
$row = $prep_statement->fetch(PDO::FETCH_ASSOC);
if ($row['num_rows'] > 0) {
$result = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
if (count($result)) {
return true;
}
else {
return false;
}
}
unset($prep_statement, $result);
unset($sql, $prep_statement, $result);
}
public function import() {
@ -289,12 +289,26 @@ include "root.php";
$dialplan['extension']['condition'][0] = $tmp;
}
}
//check if the dialplan app uuid exists
//get the app_uuid
$this->app_uuid = $dialplan['extension']['@attributes']['app_uuid'];
if ($this->app_uuid_exists()) {
//dialplan entry already exists do nothing
//get the list of domains
if (!isset($_SESSION['domains'])) {
$sql = "select * from v_domains; ";
$prep_statement = $this->db->prepare($sql);
$prep_statement->execute();
$_SESSION['domains'] = $prep_statement->fetchAll(PDO::FETCH_ASSOC);
unset($sql, $prep_statement);
}
else {
//check if the dialplan app uuid exists
foreach ($_SESSION['domains'] as $row) {
//get the domain_uuid
$this->domain_uuid $row['domain_uuid'];
//check if the dialplan exists
if (!$this->app_uuid_exists()) {
//start the transaction
$this->db->beginTransaction();
//get the attributes
@ -393,6 +407,7 @@ include "root.php";
$this->db->commit();
}
}
}
public function outbound_routes($destination_number) {