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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 153 additions and 94 deletions

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";
$database->execute($sql);
unset($sql);
}
//remove origination_callee_id_name from domain-variables dialplan

View File

@ -275,16 +275,26 @@ 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
$database = new database;
$database->app_name = 'dialplans';
$database->app_uuid = $app_uuid ?? null;
if ( strlen($dialplan_uuid)>0 )
$database->uuid($dialplan_uuid);
$database->save($array);
unset($array);
//remove checked dialplan details
//remove checked dialplan details
if (
$action == 'update'
&& permission_exists('dialplan_detail_delete')
@ -297,13 +307,6 @@ javascript:void(0);
$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
$cache = new cache;
if ($dialplan_context == "\${domain_name}" or $dialplan_context == "global") {
@ -1064,3 +1067,4 @@ javascript:void(0);
require_once "resources/footer.php";
?>

View File

@ -29,7 +29,6 @@
class dialplan {
//variables
public $result;
public $domain_uuid;
public $dialplan_uuid;
public $dialplan_detail_uuid;
@ -41,6 +40,7 @@
public $variables;
//dialplans
public $dialplan_details;
public $dialplan_name;
public $dialplan_number;
public $dialplan_destination;
@ -594,6 +594,39 @@
} //if
} //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
public function xml() {
@ -611,6 +644,7 @@
//get the dialplans from the dialplan_xml field in the dialplans table
if ($this->source == "dialplans") {
//get the data using a join between the dialplans and dialplan details tables
$sql = "select dialplan_uuid, dialplan_xml ";
$sql .= "from v_dialplans ";
@ -644,6 +678,7 @@
}
}
unset($sql, $parameters, $results, $row);
}
//get the dialplans from the dialplan details
@ -663,6 +698,7 @@
}
//get the data using a join between the dialplans and dialplan details tables
if (empty($this->dialplan_details)) {
$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.dialplan_continue, p.dialplan_order, p.dialplan_enabled, p.dialplan_description, \n";
@ -680,7 +716,6 @@
else {
$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;
}
if (is_uuid($this->uuid)) {
@ -701,17 +736,25 @@
$sql .= "else 100 end, \n";
$sql .= "s.dialplan_detail_order asc \n";
$database = new database;
$results = $database->select($sql, $parameters ?? null, 'all');
$this->dialplan_details = $database->select($sql, $parameters ?? null, 'all');
unset($sql, $parameters);
//return if no records were found to update
if (empty($this->dialplan_details)) {
return;
}
}
//define the values before they are used
$previous_dialplan_uuid = 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
$x = 0;
if (!empty($results)) {
foreach ($results as $row) {
if (!empty($this->dialplan_details)) {
foreach ($this->dialplan_details as $row) {
//clear flag pass
$pass = false;
@ -751,7 +794,9 @@
//close the tags
if ($dialplan_tag_status != "closed") {
if (($previous_dialplan_uuid != $dialplan_uuid) || ($previous_dialplan_detail_group != $dialplan_detail_group)) {
if ($condition_tag_status != "closed") {
if ($condition_attribute && (!empty($condition_attribute))) {
$xml .= " <condition " . $condition_attribute . $condition_break . "/>\n";
$condition_attribute = "";
@ -775,7 +820,10 @@
}
}
if ($previous_dialplan_uuid != $dialplan_uuid) {
//close the extension tag
if (!empty($previous_dialplan_uuid)) {
$xml .= "</extension>\n";
}
//add to the dialplanss
$dialplans[$previous_dialplan_uuid] = $xml;
@ -787,8 +835,10 @@
//open the tags
if ($dialplan_tag_status == "closed") {
$xml = '';
$xml .= "<extension name=\"" . $dialplan_name . "\" continue=\"" . $dialplan_continue . "\" uuid=\"" . $dialplan_uuid . "\">\n";
$dialplan_tag_status = "open";
$first_action = true;
$condition = "";
@ -959,7 +1009,7 @@
//prevent partial dialplan (pass=nil may be error in sql or empty resultset)
if (isset($pass) && $pass == false) {
if (!empty($results)) {
if (!empty($this->details)) {
echo 'error while build context: ' . $this->context;
}
}
@ -1003,23 +1053,28 @@
if (!empty($dialplans)) {
$x = 0;
foreach ($dialplans as $key => $value) {
if (is_uuid($key) && !empty($value)) {
//build update array
$array['dialplans'][$x]['dialplan_uuid'] = $key;
$array['dialplans'][$x]['dialplan_xml'] = $value;
//grant temporary permissions
$p = new permissions;
$p->add('dialplan_edit', 'temp');
//execute update
$database = new database;
$database->app_name = 'dialplans';
$database->app_uuid = '742714e5-8cdf-32fd-462c-cbe7e3d655db';
$database->save($array);
unset($array);
//revoke temporary permissions
$p->delete('dialplan_edit', 'temp');
}
}
}
}
}

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
$default_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_defaults.php");
foreach ($default_list as &$default_path) {
//echo $default_path."<br />\n";
include($default_path);
}