Handle columns in the table that may not exist
The old v_device_keys column device_profile_uuid is deprecated. It will exist on systems that were upgraded from an older version before the change was made. The app default code here moves data from the old format to the newer one. This is useful for upgrades. Newer installs will not have this deprecated field in the device_keys and device_settings table.
This commit is contained in:
parent
42a1625daa
commit
fe0680f9b1
|
|
@ -77,86 +77,90 @@ if ($domains_processed == 1) {
|
||||||
unset($sql, $device_keys);
|
unset($sql, $device_keys);
|
||||||
|
|
||||||
//set the device profile keys
|
//set the device profile keys
|
||||||
$sql = "select count(*) from v_device_profile_keys ";
|
if ($database->column_exists('v_device_keys', 'device_profile_uuid')) {
|
||||||
$num_rows = $database->select($sql, null, 'column');
|
$sql = "select count(*) from v_device_profile_keys ";
|
||||||
if ($num_rows == 0) {
|
$num_rows = $database->select($sql, null, 'column');
|
||||||
//get the device profile keys from device_keys table
|
if ($num_rows == 0) {
|
||||||
$sql = "select * from v_device_keys ";
|
//get the device profile keys from device_keys table
|
||||||
$sql .= "where device_profile_uuid is not null ";
|
$sql = "select * from v_device_keys ";
|
||||||
$device_profile_keys = $database->select($sql, null, 'all');
|
$sql .= "where device_profile_uuid is not null ";
|
||||||
|
$device_profile_keys = $database->select($sql, null, 'all');
|
||||||
|
|
||||||
//loop through the device_keys to build the data array
|
//loop through the device_keys to build the data array
|
||||||
if (!empty($device_profile_keys)) {
|
if (!empty($device_profile_keys)) {
|
||||||
foreach ($device_profile_keys as $index => $row) {
|
foreach ($device_profile_keys as $index => $row) {
|
||||||
$array['device_profile_keys'][$index]['device_profile_key_uuid'] = $row["device_key_uuid"];
|
$array['device_profile_keys'][$index]['device_profile_key_uuid'] = $row["device_key_uuid"];
|
||||||
$array['device_profile_keys'][$index]['domain_uuid'] = $row["domain_uuid"];
|
$array['device_profile_keys'][$index]['domain_uuid'] = $row["domain_uuid"];
|
||||||
$array['device_profile_keys'][$index]['device_profile_uuid'] = $row["device_profile_uuid"];
|
$array['device_profile_keys'][$index]['device_profile_uuid'] = $row["device_profile_uuid"];
|
||||||
$array['device_profile_keys'][$index]['profile_key_id'] = $row["device_key_id"];
|
$array['device_profile_keys'][$index]['profile_key_id'] = $row["device_key_id"];
|
||||||
$array['device_profile_keys'][$index]['profile_key_category'] = $row["device_key_category"];
|
$array['device_profile_keys'][$index]['profile_key_category'] = $row["device_key_category"];
|
||||||
$array['device_profile_keys'][$index]['profile_key_vendor'] = $row["device_key_vendor"];
|
$array['device_profile_keys'][$index]['profile_key_vendor'] = $row["device_key_vendor"];
|
||||||
$array['device_profile_keys'][$index]['profile_key_type'] = $row["device_key_type"];
|
$array['device_profile_keys'][$index]['profile_key_type'] = $row["device_key_type"];
|
||||||
$array['device_profile_keys'][$index]['profile_key_line'] = $row["device_key_line"];
|
$array['device_profile_keys'][$index]['profile_key_line'] = $row["device_key_line"];
|
||||||
$array['device_profile_keys'][$index]['profile_key_value'] = $row["device_key_value"];
|
$array['device_profile_keys'][$index]['profile_key_value'] = $row["device_key_value"];
|
||||||
$array['device_profile_keys'][$index]['profile_key_extension'] = $row["device_key_extension"];
|
$array['device_profile_keys'][$index]['profile_key_extension'] = $row["device_key_extension"];
|
||||||
$array['device_profile_keys'][$index]['profile_key_protected'] = $row["device_key_protected"];
|
$array['device_profile_keys'][$index]['profile_key_protected'] = $row["device_key_protected"];
|
||||||
$array['device_profile_keys'][$index]['profile_key_label'] = $row["device_key_label"];
|
$array['device_profile_keys'][$index]['profile_key_label'] = $row["device_key_label"];
|
||||||
$array['device_profile_keys'][$index]['profile_key_icon'] = $row["device_key_icon"];
|
$array['device_profile_keys'][$index]['profile_key_icon'] = $row["device_key_icon"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//save the array
|
||||||
|
if (!empty($array)) {
|
||||||
|
$p = permissions::new();
|
||||||
|
$p->add('device_profile_key_add', 'temp');
|
||||||
|
|
||||||
|
$database->app_name = 'devices';
|
||||||
|
$database->app_uuid = '4efa1a1a-32e7-bf83-534b-6c8299958a8e';
|
||||||
|
$database->save($array);
|
||||||
|
$response = $database->message;
|
||||||
|
unset($array);
|
||||||
|
|
||||||
|
$p->delete('device_profile_key_add', 'temp');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
unset($sql, $device_profile_keys);
|
||||||
//save the array
|
|
||||||
if (!empty($array)) {
|
|
||||||
$p = permissions::new();
|
|
||||||
$p->add('device_profile_key_add', 'temp');
|
|
||||||
|
|
||||||
$database->app_name = 'devices';
|
|
||||||
$database->app_uuid = '4efa1a1a-32e7-bf83-534b-6c8299958a8e';
|
|
||||||
$database->save($array);
|
|
||||||
$response = $database->message;
|
|
||||||
unset($array);
|
|
||||||
|
|
||||||
$p->delete('device_profile_key_add', 'temp');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
unset($sql, $device_profile_keys);
|
|
||||||
|
|
||||||
//set the device profile settings
|
//set the device profile settings
|
||||||
$sql = "select count(*) from v_device_profile_settings ";
|
if ($database->column_exists('v_device_settings', 'device_profile_uuid')) {
|
||||||
$num_rows = $database->select($sql, null, 'column');
|
$sql = "select count(*) from v_device_profile_settings ";
|
||||||
if ($num_rows == 0) {
|
$num_rows = $database->select($sql, null, 'column');
|
||||||
//get the device profile keys from device_keys table
|
if ($num_rows == 0) {
|
||||||
$sql = "select * from v_device_settings ";
|
//get the device profile keys from device_keys table
|
||||||
$sql .= "where device_profile_uuid is not null ";
|
$sql = "select * from v_device_settings ";
|
||||||
$device_profile_keys = $database->select($sql, null, 'all');
|
$sql .= "where device_profile_uuid is not null ";
|
||||||
|
$device_profile_keys = $database->select($sql, null, 'all');
|
||||||
|
|
||||||
//loop through the device_keys to build the data array
|
//loop through the device_keys to build the data array
|
||||||
if (!empty($device_profile_keys)) {
|
if (!empty($device_profile_keys)) {
|
||||||
foreach ($device_profile_keys as $index => $row) {
|
foreach ($device_profile_keys as $index => $row) {
|
||||||
$array['device_profile_settings'][$index]['device_profile_setting_uuid'] = $row["device_setting_uuid"];
|
$array['device_profile_settings'][$index]['device_profile_setting_uuid'] = $row["device_setting_uuid"];
|
||||||
$array['device_profile_settings'][$index]['domain_uuid'] = $row["domain_uuid"];
|
$array['device_profile_settings'][$index]['domain_uuid'] = $row["domain_uuid"];
|
||||||
$array['device_profile_settings'][$index]['device_profile_uuid'] = $row["device_profile_uuid"];
|
$array['device_profile_settings'][$index]['device_profile_uuid'] = $row["device_profile_uuid"];
|
||||||
$array['device_profile_settings'][$index]['profile_setting_name'] = $row["device_setting_subcategory"];
|
$array['device_profile_settings'][$index]['profile_setting_name'] = $row["device_setting_subcategory"];
|
||||||
$array['device_profile_settings'][$index]['profile_setting_value'] = $row["device_setting_value"];
|
$array['device_profile_settings'][$index]['profile_setting_value'] = $row["device_setting_value"];
|
||||||
$array['device_profile_settings'][$index]['profile_setting_enabled'] = $row["device_setting_enabled"];
|
$array['device_profile_settings'][$index]['profile_setting_enabled'] = $row["device_setting_enabled"];
|
||||||
$array['device_profile_settings'][$index]['profile_setting_description'] = $row["device_setting_description"];
|
$array['device_profile_settings'][$index]['profile_setting_description'] = $row["device_setting_description"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//save the array
|
||||||
|
if (!empty($array)) {
|
||||||
|
$p = permissions::new();
|
||||||
|
$p->add('device_profile_setting_add', 'temp');
|
||||||
|
|
||||||
|
$database->app_name = 'devices';
|
||||||
|
$database->app_uuid = '4efa1a1a-32e7-bf83-534b-6c8299958a8e';
|
||||||
|
$database->save($array);
|
||||||
|
$response = $database->message;
|
||||||
|
unset($array);
|
||||||
|
|
||||||
|
$p->delete('device_profile_setting_add', 'temp');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
unset($sql, $device_profile_keys);
|
||||||
//save the array
|
|
||||||
if (!empty($array)) {
|
|
||||||
$p = permissions::new();
|
|
||||||
$p->add('device_profile_setting_add', 'temp');
|
|
||||||
|
|
||||||
$database->app_name = 'devices';
|
|
||||||
$database->app_uuid = '4efa1a1a-32e7-bf83-534b-6c8299958a8e';
|
|
||||||
$database->save($array);
|
|
||||||
$response = $database->message;
|
|
||||||
unset($array);
|
|
||||||
|
|
||||||
$p->delete('device_profile_setting_add', 'temp');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
unset($sql, $device_profile_keys);
|
|
||||||
|
|
||||||
//add device vendor functions to the database
|
//add device vendor functions to the database
|
||||||
$sql = "select count(*) from v_device_vendors; ";
|
$sql = "select count(*) from v_device_vendors; ";
|
||||||
|
|
@ -247,6 +251,7 @@ if ($domains_processed == 1) {
|
||||||
$sql = "update v_device_lines set label = display_name where label is null;\n";
|
$sql = "update v_device_lines set label = display_name where label is null;\n";
|
||||||
$database->execute($sql);
|
$database->execute($sql);
|
||||||
unset($sql);
|
unset($sql);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue