Call Center Queue name change from uuid@domain to extension@domain

This commit is contained in:
markjcrane
2021-04-27 22:42:09 -06:00
parent 356fd56af1
commit a6e59c3522
5 changed files with 139 additions and 39 deletions

View File

@@ -17,7 +17,7 @@
The Initial Developer of the Original Code is
Mark J Crane <markjcrane@fusionpbx.com>
Portions created by the Initial Developer are Copyright (C) 2018
Portions created by the Initial Developer are Copyright (C) 2018 - 2021
the Initial Developer. All Rights Reserved.
Contributor(s):
@@ -64,18 +64,108 @@ if ($domains_processed == 1) {
}
unset($sql);
//update all callcenter dialplans to have the @domain in the queue name
$sql = "UPDATE \n";
$sql .= " v_dialplans d SET dialplan_xml = REPLACE( \n";
$sql .= " dialplan_xml, \n";
$sql .= " (SELECT call_center_queue_uuid::text FROM v_call_center_queues c WHERE c.dialplan_uuid = d.dialplan_uuid ), \n";
$sql .= " (SELECT call_center_queue_uuid::text FROM v_call_center_queues c WHERE c.dialplan_uuid = d.dialplan_uuid ) || '@' || (SELECT domain_name FROM v_domains vd WHERE vd.domain_uuid = d.domain_uuid) \n";
$sql .= " ) \n";
$sql .= "WHERE dialplan_uuid IN (SELECT dialplan_uuid FROM v_call_center_queues) \n";
$sql .= "AND dialplan_xml NOT LIKE '%<action application=\"callcenter\" data=%@%\"/>%' \n";
$database = new database;
$database->execute($sql);
//update all callcenter dialplans to have the @domain in the queue name
$sql = "select q.domain_uuid, d.domain_name, q.call_center_queue_uuid, q.dialplan_uuid, ";
$sql .= "q.queue_name, q.queue_extension, q.queue_timeout_action, q.queue_cid_prefix, q.queue_cc_exit_keys, ";
$sql .= "q.queue_description, q.queue_time_base_score_sec, q.queue_greeting ";
$sql .= "from v_call_center_queues as q, v_domains as d ";
$sql .= "where q.domain_uuid = d.domain_uuid ";
$database = new database;
$call_center_queues = $database->select($sql, null, 'all');
$id = 0;
if (is_array($call_center_queues)) {
foreach ($call_center_queues as $row) {
//get the application and data
$action_array = explode(":",$row['queue_timeout_action']);
$queue_timeout_app = $action_array[0];
unset($action_array[0]);
$queue_timeout_data = implode($action_array);
//add the recording path if needed
if ($row['queue_greeting'] != '') {
if (file_exists($_SESSION['switch']['recordings']['dir'].'/'.$row['domain_name'].'/'.$row['queue_greeting'])) {
$queue_greeting_path = $_SESSION['switch']['recordings']['dir'].'/'.$_SESSION['domain_name'].'/'.$row['queue_greeting'];
}
else {
$queue_greeting_path = trim($row['queue_greeting']);
}
}
//build the xml dialplan
$dialplan_xml = "<extension name=\"".$row["queue_name"]."\" continue=\"\" uuid=\"".$row["dialplan_uuid"]."\">\n";
$dialplan_xml .= " <condition field=\"destination_number\" expression=\"^([^#]+#)(.*)\$\" break=\"never\">\n";
$dialplan_xml .= " <action application=\"set\" data=\"caller_id_name=\$2\"/>\n";
$dialplan_xml .= " </condition>\n";
$dialplan_xml .= " <condition field=\"destination_number\" expression=\"^".$row["queue_extension"]."$\">\n";
$dialplan_xml .= " <action application=\"answer\" data=\"\"/>\n";
$dialplan_xml .= " <action application=\"set\" data=\"hangup_after_bridge=true\"/>\n";
if ($row['queue_time_base_score_sec'] != '') {
$dialplan_xml .= " <action application=\"set\" data=\"cc_base_score=".$row['queue_time_base_score_sec']."\"/>\n";
}
if ($row['queue_greeting_path'] != '') {
$greeting_array = explode(':', $row['queue_greeting_path']);
if (count($greeting_array) == 1) {
$dialplan_xml .= " <action application=\"playback\" data=\"".$row['queue_greeting_path']."\"/>\n";
}
else {
if ($greeting_array[0] == 'say' || $greeting_array[0] == 'tone_stream' || $greeting_array[0] == 'phrase') {
$dialplan_xml .= " <action application=\"".$greeting_array[0]."\" data=\"".$greeting_array[1]."\"/>\n";
}
}
}
if (strlen($row['queue_cid_prefix']) > 0) {
$dialplan_xml .= " <action application=\"set\" data=\"effective_caller_id_name=".$row['queue_cid_prefix']."#\${caller_id_name}\"/>\n";
}
if (strlen($row['queue_cc_exit_keys']) > 0) {
$dialplan_xml .= " <action application=\"set\" data=\"cc_exit_keys=".$row['queue_cc_exit_keys']."\"/>\n";
}
$dialplan_xml .= " <action application=\"callcenter\" data=\"".$row['queue_extension']."@".$row['domain_name']."\"/>\n";
//if ($destination->valid($queue_timeout_app.':'.$queue_timeout_data)) {
$dialplan_xml .= " <action application=\"".$queue_timeout_app."\" data=\"".$queue_timeout_data."\"/>\n";
//}
$dialplan_xml .= " </condition>\n";
$dialplan_xml .= "</extension>\n";
//build the dialplan array
$array['dialplans'][$id]["domain_uuid"] = $row["domain_uuid"];
$array['dialplans'][$id]["dialplan_uuid"] = $row["dialplan_uuid"];
$array['dialplans'][$id]["dialplan_name"] = $row["queue_name"];
$array['dialplans'][$id]["dialplan_number"] = $row["queue_extension"];
$array['dialplans'][$id]["dialplan_context"] = $row['domain_name'];
$array['dialplans'][$id]["dialplan_continue"] = "false";
$array['dialplans'][$id]["dialplan_xml"] = $dialplan_xml;
$array['dialplans'][$id]["dialplan_order"] = "230";
$array['dialplans'][$id]["dialplan_enabled"] = "true";
$array['dialplans'][$id]["dialplan_description"] = $row["queue_description"];
$array['dialplans'][$id]["app_uuid"] = "95788e50-9500-079e-2807-fd530b0ea370";
//increment the array id
$id++;
}
}
unset ($prep_statement);
//save the array to the database
if (is_array($array)) {
//add the dialplan permission
$p = new permissions;
$p->add("dialplan_add", "temp");
$p->add("dialplan_edit", "temp");
//save to the data
$database = new database;
$database->app_name = 'call_centers';
$database->app_uuid = '95788e50-9500-079e-2807-fd530b0ea370';
$database->save($array);
$message = $database->message;
//remove the temporary permission
$p->delete("dialplan_add", "temp");
$p->delete("dialplan_edit", "temp");
}
}
?>
?>