From 031a818c778487f2eb60c274721e43cf51ef896d Mon Sep 17 00:00:00 2001 From: laf Date: Mon, 20 Jul 2015 16:52:33 +0100 Subject: [PATCH] Removed references to location override --- html/includes/functions.inc.php | 14 +------------- html/includes/hostbox-public.inc.php | 4 ---- html/includes/object-cache.inc.php | 5 ----- html/includes/table/devices.inc.php | 6 +----- html/pages/device/edit/device.inc.php | 26 ++++++++++++++------------ html/pages/devices.inc.php | 3 +-- html/pages/front/globe.php | 2 +- includes/common.php | 4 ---- scripts/console-ui.php | 4 ---- 9 files changed, 18 insertions(+), 50 deletions(-) diff --git a/html/includes/functions.inc.php b/html/includes/functions.inc.php index aa83aca1f..9ee224ab3 100644 --- a/html/includes/functions.inc.php +++ b/html/includes/functions.inc.php @@ -738,18 +738,6 @@ function devclass($device) { function getlocations() { $ignore_dev_location = array(); $locations = array(); - // Fetch override locations, not through get_dev_attrib, this would be a huge number of queries - $rows = dbFetchRows("SELECT attrib_type,attrib_value,device_id FROM devices_attribs WHERE attrib_type LIKE 'override_sysLocation%' ORDER BY attrib_type"); - foreach ($rows as $row) { - if ($row['attrib_type'] == 'override_sysLocation_bool' && $row['attrib_value'] == 1) { - $ignore_dev_location[$row['device_id']] = 1; - } //end if - else if ($row['attrib_type'] == 'override_sysLocation_string' && (isset($ignore_dev_location[$row['device_id']]) && $ignore_dev_location[$row['device_id']] == 1)) { - if (!in_array($row['attrib_value'], $locations)) { - $locations[] = $row['attrib_value']; - } - } - } // Fetch regular locations if ($_SESSION['userlevel'] >= '5') { @@ -761,7 +749,7 @@ function getlocations() { foreach ($rows as $row) { // Only add it as a location if it wasn't overridden (and not already there) - if ($row['location'] != '' && !isset($ignore_dev_location[$row['device_id']])) { + if ($row['location'] != '') { if (!in_array($row['location'], $locations)) { $locations[] = $row['location']; } diff --git a/html/includes/hostbox-public.inc.php b/html/includes/hostbox-public.inc.php index 161ad34f1..437344529 100644 --- a/html/includes/hostbox-public.inc.php +++ b/html/includes/hostbox-public.inc.php @@ -64,10 +64,6 @@ echo ''; echo ' '.$device['hardware'].' '.$device['features'].''; echo ' '.formatUptime($device['uptime'], 'short').'
'; -if (get_dev_attrib($device, 'override_sysLocation_bool')) { - $device['location'] = get_dev_attrib($device, 'override_sysLocation_string'); -} - echo ' '.truncate($device['location'], 32, '').''; echo ' '; diff --git a/html/includes/object-cache.inc.php b/html/includes/object-cache.inc.php index 023730758..fd7a9977d 100644 --- a/html/includes/object-cache.inc.php +++ b/html/includes/object-cache.inc.php @@ -6,11 +6,6 @@ require_once $config['install_dir'].'/includes/object-cache.inc.php'; // FIXME: This appears to keep a complete cache of device details in memory for every page load. // It would be interesting to know where this is used. It probably should have its own API. foreach (dbFetchRows('SELECT * FROM `devices` ORDER BY `hostname`') as $device) { - if (get_dev_attrib($device, 'override_sysLocation_bool')) { - $device['real_location'] = $device['location']; - $device['location'] = get_dev_attrib($device, 'override_sysLocation_string'); - } - $cache['devices']['hostname'][$device['hostname']] = $device['device_id']; $cache['devices']['id'][$device['device_id']] = $device; diff --git a/html/includes/table/devices.inc.php b/html/includes/table/devices.inc.php index 129e198f2..55f09d9f5 100644 --- a/html/includes/table/devices.inc.php +++ b/html/includes/table/devices.inc.php @@ -78,7 +78,7 @@ if (!empty($_POST['location']) && $_POST['location'] == 'Unset') { } if (!empty($_POST['location'])) { - $sql .= " AND (((`DB`.`attrib_value`='1' AND `DA`.`attrib_type`='override_sysLocation_string' AND `DA`.`attrib_value` = ?)) OR `location` = ?)"; + $sql .= " AND `location` = ?"; $param[] = mres($_POST['location']); $param[] = mres($_POST['location']); } @@ -167,10 +167,6 @@ foreach (dbFetchRows($sql, $param) as $device) { $port_count = dbFetchCell('SELECT COUNT(*) FROM `ports` WHERE `device_id` = ?', array($device['device_id'])); $sensor_count = dbFetchCell('SELECT COUNT(*) FROM `sensors` WHERE `device_id` = ?', array($device['device_id'])); - if (get_dev_attrib($device, 'override_sysLocation_bool')) { - $device['location'] = get_dev_attrib($device, 'override_sysLocation_string'); - } - $actions = ('
'); $actions .= ' View device '; diff --git a/html/pages/device/edit/device.inc.php b/html/pages/device/edit/device.inc.php index 17af0cbaf..b1705eab1 100644 --- a/html/pages/device/edit/device.inc.php +++ b/html/pages/device/edit/device.inc.php @@ -9,20 +9,22 @@ if ($_POST['editing']) { $override_sysLocation_string = mres($_POST['sysLocation']); } - if (get_dev_attrib($device,'override_sysLocation_bool') != $override_sysLocation_bool - || get_dev_attrib($device,'override_sysLocation_string') != $override_sysLocation_string) { - $updated = 1; - } + if ($device['override_sysLocation'] != $override_sysLocation_bool || $device['location'] != $override_sysLocation_string) { + $updated = 1; + } if ($override_sysLocation_bool) { - set_dev_attrib($device, 'override_sysLocation_bool', '1'); + $override_sysLocation = 1; } else { - del_dev_attrib($device, 'override_sysLocation_bool'); + $override_sysLocation = 0; } + + dbUpdate(array('override_sysLocation'=>$override_sysLocation), 'devices', '`device_id`=?' ,array($device['device_id'])); + if (isset($override_sysLocation_string)) { - set_dev_attrib($device, 'override_sysLocation_string', $override_sysLocation_string); - }; + dbUpdate(array('location'=>$override_sysLocation_string), 'devices', '`device_id`=?' ,array($device['device_id'])); + } #FIXME needs more sanity checking! and better feedback @@ -50,8 +52,8 @@ if ($_POST['editing']) { $descr = $device['purpose']; -$override_sysLocation_bool = get_dev_attrib($device,'override_sysLocation_bool'); -$override_sysLocation_string = get_dev_attrib($device,'override_sysLocation_string'); +$override_sysLocation = $device['override_sysLocation']; +$override_sysLocation_string = $device['location']; if ($updated && $update_message) { print_message($update_message); @@ -116,7 +118,7 @@ if ($unknown) {
- /> + />
@@ -124,7 +126,7 @@ if ($unknown) {
- value="" /> + value="" />
diff --git a/html/pages/devices.inc.php b/html/pages/devices.inc.php index a51358762..aaac360e3 100644 --- a/html/pages/devices.inc.php +++ b/html/pages/devices.inc.php @@ -181,8 +181,7 @@ if($format == "graph") { } if (device_permitted($device['device_id'])) { - if (!$location_filter || ((get_dev_attrib($device,'override_sysLocation_bool') && get_dev_attrib($device,'override_sysLocation_string') == $location_filter) - || $device['location'] == $location_filter)) { + if (!$location_filter || $device['location'] == $location_filter) { $graph_type = "device_".$subformat; if ($_SESSION['widescreen']) { diff --git a/html/pages/front/globe.php b/html/pages/front/globe.php index 9884b402f..95172f9ed 100644 --- a/html/pages/front/globe.php +++ b/html/pages/front/globe.php @@ -43,7 +43,7 @@ foreach (getlocations() as $location) { $devices_up = array(); $count = 0; $down = 0; - foreach (dbFetchRows("SELECT devices.device_id,devices.hostname,devices.status FROM devices LEFT JOIN devices_attribs ON devices.device_id = devices_attribs.device_id WHERE ( devices.location = ? || ( devices_attribs.attrib_type = 'override_sysLocation_string' && devices_attribs.attrib_value = ? ) ) && devices.disabled = 0 && devices.ignore = 0 GROUP BY devices.hostname", array($location,$location)) as $device) { + foreach (dbFetchRows("SELECT devices.device_id,devices.hostname,devices.status FROM devices LEFT JOIN devices_attribs ON devices.device_id = devices_attribs.device_id WHERE devices.location = ? && devices.disabled = 0 && devices.ignore = 0 GROUP BY devices.hostname", array($location)) as $device) { if( $config['frontpage_globe']['markers'] == 'devices' || empty($config['frontpage_globe']['markers']) ) { $devices[] = $device['hostname']; $count++; diff --git a/includes/common.php b/includes/common.php index b0cd6c7af..e63c240a2 100644 --- a/includes/common.php +++ b/includes/common.php @@ -296,10 +296,6 @@ function device_by_id_cache($device_id, $refresh = '0') { } else { $device = dbFetchRow("SELECT * FROM `devices` WHERE `device_id` = ?", array($device_id)); - if (get_dev_attrib($device,'override_sysLocation_bool')) { - $device['real_location'] = $device['location']; - $device['location'] = get_dev_attrib($device,'override_sysLocation_string'); - } $cache['devices']['id'][$device_id] = $device; } return $device; diff --git a/scripts/console-ui.php b/scripts/console-ui.php index 30556a95f..7e39cf319 100755 --- a/scripts/console-ui.php +++ b/scripts/console-ui.php @@ -22,10 +22,6 @@ while ($end == 0) { passthru('clear'); $tbl = new Console_Table(CONSOLE_TABLE_ALIGN_RIGHT); foreach (dbFetchRows('SELECT * FROM `devices` ORDER BY `hostname`') as $device) { - if (get_dev_attrib($device, 'override_sysLocation_bool')) { - $device['real_location'] = $device['location']; - $device['location'] = get_dev_attrib($device, 'override_sysLocation_string'); - } $devices['count']++;