Build dialplan xml from the array. More efficient to save data and xml in one step.

This commit is contained in:
FusionPBX
2023-11-03 02:18:57 -06:00
committed by GitHub
parent 9da5a10a77
commit fa123ff069
4 changed files with 153 additions and 94 deletions
-1
View File
@@ -121,7 +121,6 @@
$sql = "update v_dialplan_details set dialplan_detail_data = 'recording_id=' where dialplan_detail_data = 'recording_id=true'\n"; $sql = "update v_dialplan_details set dialplan_detail_data = 'recording_id=' where dialplan_detail_data = 'recording_id=true'\n";
$database->execute($sql); $database->execute($sql);
unset($sql); unset($sql);
} }
//remove origination_callee_id_name from domain-variables dialplan //remove origination_callee_id_name from domain-variables dialplan
+12 -8
View File
@@ -275,11 +275,21 @@ javascript:void(0);
} }
} }
//update the dialplan xml by using the array
$dialplans = new dialplan;
$dialplans->source = "details";
$dialplans->destination = "array";
$dialplans->uuid = $dialplan_uuid;
$dialplans->prepare_details($array);
$dialplan_array = $dialplans->xml();
//add the dialplan xml to the array
$array['dialplans'][$x]['dialplan_xml'] = $dialplan_array[$dialplan_uuid];
//add or update the database //add or update the database
$database = new database; $database = new database;
$database->app_name = 'dialplans'; $database->app_name = 'dialplans';
$database->app_uuid = $app_uuid ?? null; $database->app_uuid = $app_uuid ?? null;
if ( strlen($dialplan_uuid)>0 )
$database->uuid($dialplan_uuid); $database->uuid($dialplan_uuid);
$database->save($array); $database->save($array);
unset($array); unset($array);
@@ -297,13 +307,6 @@ javascript:void(0);
$obj->delete_details($dialplan_details_delete); $obj->delete_details($dialplan_details_delete);
} }
//update the dialplan xml
$dialplans = new dialplan;
$dialplans->source = "details";
$dialplans->destination = "database";
$dialplans->uuid = $dialplan_uuid;
$dialplans->xml();
//clear the cache //clear the cache
$cache = new cache; $cache = new cache;
if ($dialplan_context == "\${domain_name}" or $dialplan_context == "global") { if ($dialplan_context == "\${domain_name}" or $dialplan_context == "global") {
@@ -1064,3 +1067,4 @@ javascript:void(0);
require_once "resources/footer.php"; require_once "resources/footer.php";
?> ?>
+61 -6
View File
@@ -29,7 +29,6 @@
class dialplan { class dialplan {
//variables //variables
public $result;
public $domain_uuid; public $domain_uuid;
public $dialplan_uuid; public $dialplan_uuid;
public $dialplan_detail_uuid; public $dialplan_detail_uuid;
@@ -41,6 +40,7 @@
public $variables; public $variables;
//dialplans //dialplans
public $dialplan_details;
public $dialplan_name; public $dialplan_name;
public $dialplan_number; public $dialplan_number;
public $dialplan_destination; public $dialplan_destination;
@@ -594,6 +594,39 @@
} //if } //if
} //function } //function
//combines array dialplans and dialplan details arrays to match results from the database
public function prepare_details($database_array) {
$id = 0;
foreach($database_array['dialplans'] as $row) {
if (!empty($row['dialplan_details'])) {
foreach($row['dialplan_details'] as $detail) {
$array[$id]['domain_uuid'] = $row['domain_uuid'];
$array[$id]['dialplan_uuid'] = $row['dialplan_uuid'];
$array[$id]['app_uuid'] = $row['app_uuid'];
$array[$id]['dialplan_context'] = $row['dialplan_context'];
$array[$id]['dialplan_name'] = $row['dialplan_name'];
$array[$id]['dialplan_number'] = $row['dialplan_number'];
$array[$id]['dialplan_continue'] = $row['dialplan_continue'];
$array[$id]['dialplan_order'] = $row['dialplan_order'];
$array[$id]['dialplan_enabled'] = $row['dialplan_enabled'];
$array[$id]['dialplan_description'] = $row['dialplan_description'];
$array[$id]['dialplan_detail_uuid'] = $detail['dialplan_detail_uuid'];
$array[$id]['dialplan_detail_tag'] = $detail['dialplan_detail_tag'];
$array[$id]['dialplan_detail_type'] = $detail['dialplan_detail_type'];
$array[$id]['dialplan_detail_data'] = $detail['dialplan_detail_data'];
$array[$id]['dialplan_detail_break'] = $detail['dialplan_detail_break'];
$array[$id]['dialplan_detail_inline'] = $detail['dialplan_detail_inline'];
$array[$id]['dialplan_detail_group'] = $detail['dialplan_detail_group'];
$array[$id]['dialplan_detail_order'] = $detail['dialplan_detail_order'];
$array[$id]['dialplan_detail_enabled'] = $detail['dialplan_detail_enabled'];
$id++;
}
}
}
$this->dialplan_details = $array;
}
//reads dialplan details from the database to build the xml //reads dialplan details from the database to build the xml
public function xml() { public function xml() {
@@ -611,6 +644,7 @@
//get the dialplans from the dialplan_xml field in the dialplans table //get the dialplans from the dialplan_xml field in the dialplans table
if ($this->source == "dialplans") { if ($this->source == "dialplans") {
//get the data using a join between the dialplans and dialplan details tables //get the data using a join between the dialplans and dialplan details tables
$sql = "select dialplan_uuid, dialplan_xml "; $sql = "select dialplan_uuid, dialplan_xml ";
$sql .= "from v_dialplans "; $sql .= "from v_dialplans ";
@@ -644,6 +678,7 @@
} }
} }
unset($sql, $parameters, $results, $row); unset($sql, $parameters, $results, $row);
} }
//get the dialplans from the dialplan details //get the dialplans from the dialplan details
@@ -663,6 +698,7 @@
} }
//get the data using a join between the dialplans and dialplan details tables //get the data using a join between the dialplans and dialplan details tables
if (empty($this->dialplan_details)) {
$sql = "select \n"; $sql = "select \n";
$sql .= "p.domain_uuid, p.dialplan_uuid, p.app_uuid, p.dialplan_context, p.dialplan_name, p.dialplan_number, \n"; $sql .= "p.domain_uuid, p.dialplan_uuid, p.app_uuid, p.dialplan_context, p.dialplan_name, p.dialplan_number, \n";
$sql .= "p.dialplan_continue, p.dialplan_order, p.dialplan_enabled, p.dialplan_description, \n"; $sql .= "p.dialplan_continue, p.dialplan_order, p.dialplan_enabled, p.dialplan_description, \n";
@@ -680,7 +716,6 @@
else { else {
$sql .= "and (p.dialplan_context = :dialplan_context or p.dialplan_context = '\${domain_name}' or dialplan_context = 'global') \n"; $sql .= "and (p.dialplan_context = :dialplan_context or p.dialplan_context = '\${domain_name}' or dialplan_context = 'global') \n";
} }
$sql .= "and p.dialplan_enabled = 'true' \n";
$parameters['dialplan_context'] = $this->context; $parameters['dialplan_context'] = $this->context;
} }
if (is_uuid($this->uuid)) { if (is_uuid($this->uuid)) {
@@ -701,17 +736,25 @@
$sql .= "else 100 end, \n"; $sql .= "else 100 end, \n";
$sql .= "s.dialplan_detail_order asc \n"; $sql .= "s.dialplan_detail_order asc \n";
$database = new database; $database = new database;
$results = $database->select($sql, $parameters ?? null, 'all'); $this->dialplan_details = $database->select($sql, $parameters ?? null, 'all');
unset($sql, $parameters); unset($sql, $parameters);
//return if no records were found to update
if (empty($this->dialplan_details)) {
return;
}
}
//define the values before they are used //define the values before they are used
$previous_dialplan_uuid = null; $previous_dialplan_uuid = null;
$previous_dialplan_detail_group = null; $previous_dialplan_detail_group = null;
$dialplan_tag_status = null;
//loop through the results to get the xml from the dialplan_xml field or from dialplan details table //loop through the results to get the xml from the dialplan_xml field or from dialplan details table
$x = 0; $x = 0;
if (!empty($results)) { if (!empty($this->dialplan_details)) {
foreach ($results as $row) { foreach ($this->dialplan_details as $row) {
//clear flag pass //clear flag pass
$pass = false; $pass = false;
@@ -751,7 +794,9 @@
//close the tags //close the tags
if ($dialplan_tag_status != "closed") { if ($dialplan_tag_status != "closed") {
if (($previous_dialplan_uuid != $dialplan_uuid) || ($previous_dialplan_detail_group != $dialplan_detail_group)) { if (($previous_dialplan_uuid != $dialplan_uuid) || ($previous_dialplan_detail_group != $dialplan_detail_group)) {
if ($condition_tag_status != "closed") { if ($condition_tag_status != "closed") {
if ($condition_attribute && (!empty($condition_attribute))) { if ($condition_attribute && (!empty($condition_attribute))) {
$xml .= " <condition " . $condition_attribute . $condition_break . "/>\n"; $xml .= " <condition " . $condition_attribute . $condition_break . "/>\n";
$condition_attribute = ""; $condition_attribute = "";
@@ -775,7 +820,10 @@
} }
} }
if ($previous_dialplan_uuid != $dialplan_uuid) { if ($previous_dialplan_uuid != $dialplan_uuid) {
//close the extension tag
if (!empty($previous_dialplan_uuid)) {
$xml .= "</extension>\n"; $xml .= "</extension>\n";
}
//add to the dialplanss //add to the dialplanss
$dialplans[$previous_dialplan_uuid] = $xml; $dialplans[$previous_dialplan_uuid] = $xml;
@@ -787,8 +835,10 @@
//open the tags //open the tags
if ($dialplan_tag_status == "closed") { if ($dialplan_tag_status == "closed") {
$xml = ''; $xml = '';
$xml .= "<extension name=\"" . $dialplan_name . "\" continue=\"" . $dialplan_continue . "\" uuid=\"" . $dialplan_uuid . "\">\n"; $xml .= "<extension name=\"" . $dialplan_name . "\" continue=\"" . $dialplan_continue . "\" uuid=\"" . $dialplan_uuid . "\">\n";
$dialplan_tag_status = "open"; $dialplan_tag_status = "open";
$first_action = true; $first_action = true;
$condition = ""; $condition = "";
@@ -959,7 +1009,7 @@
//prevent partial dialplan (pass=nil may be error in sql or empty resultset) //prevent partial dialplan (pass=nil may be error in sql or empty resultset)
if (isset($pass) && $pass == false) { if (isset($pass) && $pass == false) {
if (!empty($results)) { if (!empty($this->details)) {
echo 'error while build context: ' . $this->context; echo 'error while build context: ' . $this->context;
} }
} }
@@ -1003,23 +1053,28 @@
if (!empty($dialplans)) { if (!empty($dialplans)) {
$x = 0; $x = 0;
foreach ($dialplans as $key => $value) { foreach ($dialplans as $key => $value) {
if (is_uuid($key) && !empty($value)) {
//build update array //build update array
$array['dialplans'][$x]['dialplan_uuid'] = $key; $array['dialplans'][$x]['dialplan_uuid'] = $key;
$array['dialplans'][$x]['dialplan_xml'] = $value; $array['dialplans'][$x]['dialplan_xml'] = $value;
//grant temporary permissions //grant temporary permissions
$p = new permissions; $p = new permissions;
$p->add('dialplan_edit', 'temp'); $p->add('dialplan_edit', 'temp');
//execute update //execute update
$database = new database; $database = new database;
$database->app_name = 'dialplans'; $database->app_name = 'dialplans';
$database->app_uuid = '742714e5-8cdf-32fd-462c-cbe7e3d655db'; $database->app_uuid = '742714e5-8cdf-32fd-462c-cbe7e3d655db';
$database->save($array); $database->save($array);
unset($array); unset($array);
//revoke temporary permissions //revoke temporary permissions
$p->delete('dialplan_edit', 'temp'); $p->delete('dialplan_edit', 'temp');
} }
} }
} }
}
} }
+1
View File
@@ -649,6 +649,7 @@ if (!class_exists('domains')) {
//get the list of installed apps from the core and mod directories and execute the php code in app_defaults.php //get the list of installed apps from the core and mod directories and execute the php code in app_defaults.php
$default_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_defaults.php"); $default_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_defaults.php");
foreach ($default_list as &$default_path) { foreach ($default_list as &$default_path) {
//echo $default_path."<br />\n";
include($default_path); include($default_path);
} }