Update provision.php

Simplify the code where device keys can override keys assigned to the device profile keys.
This commit is contained in:
FusionPBX 2016-07-16 03:37:46 -06:00 committed by GitHub
parent 16dd385bf9
commit 8faefced75
1 changed files with 30 additions and 33 deletions

View File

@ -643,6 +643,7 @@ include "root.php";
//get the provisioning information from device keys //get the provisioning information from device keys
if (strlen($device_uuid) > 0) { if (strlen($device_uuid) > 0) {
//get the device keys array //get the device keys array
$sql = "SELECT * FROM v_device_keys "; $sql = "SELECT * FROM v_device_keys ";
$sql .= "WHERE ("; $sql .= "WHERE (";
@ -657,41 +658,37 @@ include "root.php";
else { else {
$sql .= "AND (lower(device_key_vendor) = '".$device_vendor."' or device_key_vendor is null) "; $sql .= "AND (lower(device_key_vendor) = '".$device_vendor."' or device_key_vendor is null) ";
} }
$sql .= "ORDER BY device_key_category asc, device_key_id asc, device_uuid desc"; $sql .= "ORDER BY ";
$prep_statement = $this->db->prepare(check_sql($sql)); $sql .= "device_key_vendor ASC, ";
$prep_statement->execute(); $sql .= "CASE device_key_category ";
$device_keys = $prep_statement->fetchAll(PDO::FETCH_NAMED); $sql .= "WHEN 'line' THEN 1 ";
$sql .= "WHEN 'memory' THEN 2 ";
//rebuild the array to allow profile keys to be overridden by keys assigned to this device $sql .= "WHEN 'programmable' THEN 3 ";
$x = 0; $sql .= "WHEN 'expansion' THEN 4 ";
$previous_category = ''; $sql .= "ELSE 100 END, ";
$previous_id = ''; if ($db_type == "mysql") {
foreach($device_keys as $row) { $sql .= "device_key_id ASC, ";
//set the variables
if ($row['device_key_category'] == $previous_category && $row['device_key_id'] == $previous_id) {
$device_keys[$x]['device_key_override'] = "true";
$device_keys[$x]['device_key_message'] = "value=".$device_keys[$x-1]['device_key_value']."&label=".$device_keys[$x-1]['device_key_label'];
unset($device_keys[$x-1]);
}
$device_keys[$x]['device_key_category'] = $row['device_key_category'];
$device_keys[$x]['device_key_id'] = $row['device_key_id']; //1
$device_keys[$x]['device_key_type'] = $row['device_key_type']; //line, memory, expansion
$device_keys[$x]['device_key_line'] = $row['device_key_line'];
$device_keys[$x]['device_key_value'] = $row['device_key_value']; //1
$device_keys[$x]['device_key_extension'] = $row['device_key_extension'];
$device_keys[$x]['device_key_label'] = $row['device_key_label']; //label
if (is_uuid($row['device_profile_uuid'])) {
$device_keys[$x]['device_key_owner'] = "profile";
} }
else { else {
$device_keys[$x]['device_key_owner'] = "device"; $sql .= "CAST(device_key_id as numeric) ASC, ";
} }
//set previous values $sql .= "CASE WHEN device_uuid IS NULL THEN 0 ELSE 1 END ASC ";
$previous_category = $row['device_key_category']; $prep_statement = $this->db->prepare(check_sql($sql));
$previous_id = $row['device_key_id']; $prep_statement->execute();
//increment the key $keys = $prep_statement->fetchAll(PDO::FETCH_NAMED);
$x++;
//override profile keys with device keys
foreach($keys as $row) {
$id = $row['device_key_id'];
$device_keys[$id] = $row;
if (is_uuid($row['device_profile_uuid'])) {
$device_keys[$id]['device_key_owner'] = "profile";
} }
else {
$device_keys[$id]['device_key_owner'] = "device";
}
}
unset($keys);
} }
//debug information //debug information