From 1553664477ce61a220db20e4be7bf220771f45bd Mon Sep 17 00:00:00 2001 From: Sergei Jeihala Date: Sat, 24 Aug 2024 21:45:11 +0300 Subject: [PATCH] Delete object update Updated object deletion procedure to avoid problem when user tries to delete object that is already removed. --- modules/devices/devices.class.php | 2 ++ modules/objects/objects.class.php | 2 ++ 2 files changed, 4 insertions(+) diff --git a/modules/devices/devices.class.php b/modules/devices/devices.class.php index 6c840cefc..6840fdb6b 100644 --- a/modules/devices/devices.class.php +++ b/modules/devices/devices.class.php @@ -1053,6 +1053,8 @@ function delete_devices($id) { $rec = SQLSelectOne("SELECT * FROM devices WHERE ID='$id'"); + if (!isset($rec['ID'])) return false; + $payload = array(); $payload['name'] = $rec['LINKED_OBJECT']; sg('HomeBridge.to_remove', json_encode($payload)); diff --git a/modules/objects/objects.class.php b/modules/objects/objects.class.php index bb21ecefe..16a55f696 100644 --- a/modules/objects/objects.class.php +++ b/modules/objects/objects.class.php @@ -296,6 +296,8 @@ function delete_objects($id) { $rec = SQLSelectOne("SELECT * FROM objects WHERE ID='$id'"); + if (!isset($rec['ID'])) return false; + // DELETE LINKED OBJECT FROM ALL TABLES $tables = SQLSelect("SELECT DISTINCT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME IN ('LINKED_OBJECT') AND TABLE_SCHEMA='" . DB_NAME . "';"); $total = count($tables);