From 8d9a4d23d185d12ca5d52684885745dafbe15006 Mon Sep 17 00:00:00 2001 From: jokob-sk Date: Sun, 23 Mar 2025 13:23:39 +1100 Subject: [PATCH] stop devParentMAC overwrite if specified #1021 --- server/scan/device_handling.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/server/scan/device_handling.py b/server/scan/device_handling.py index 1550480c..69b075a2 100755 --- a/server/scan/device_handling.py +++ b/server/scan/device_handling.py @@ -316,14 +316,16 @@ def update_devices_data_from_scan (db): FROM CurrentScan WHERE Devices.devMac = CurrentScan.cur_MAC ) - WHERE EXISTS ( + WHERE + (devParentPort IS NULL OR devParentPort = "" OR devParentPort = "null") + AND + EXISTS ( SELECT 1 FROM CurrentScan WHERE Devices.devMac = CurrentScan.cur_MAC AND CurrentScan.cur_Port IS NOT NULL AND CurrentScan.cur_Port NOT IN ("", "null") ) - AND (devParentPort IS NULL OR devParentPort = "" OR devParentPort = "null") """) # Update only devices with empty or NULL devParentMAC @@ -334,13 +336,15 @@ def update_devices_data_from_scan (db): FROM CurrentScan WHERE Devices.devMac = CurrentScan.cur_MAC ) - WHERE EXISTS ( - SELECT 1 - FROM CurrentScan - WHERE Devices.devMac = CurrentScan.cur_MAC - AND CurrentScan.cur_NetworkNodeMAC IS NOT NULL AND CurrentScan.cur_NetworkNodeMAC NOT IN ("", "null") - ) - AND (devParentMAC IS NULL OR devParentMAC = "" OR devParentMAC = "null") + WHERE + (devParentMAC IS NULL OR devParentMAC IN ("", "null", "(unknown)", "(Unknown)")) + AND + EXISTS ( + SELECT 1 + FROM CurrentScan + WHERE Devices.devMac = CurrentScan.cur_MAC + AND CurrentScan.cur_NetworkNodeMAC IS NOT NULL AND CurrentScan.cur_NetworkNodeMAC NOT IN ("", "null") + ) """) # Update only devices with empty or NULL devSite