From 3cdc020354122584961dadf64693f21eff4336fb Mon Sep 17 00:00:00 2001 From: wilpig Date: Tue, 29 Aug 2023 16:01:33 -0500 Subject: [PATCH] Add correction for duplicate key on copy fixes #1433 The create device function adds in the global custom attributes and this portion of the copy function was duplicating any values from the original device but that was causing a duplicate key error for the global custom values that already existed. --- classes/Device.class.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/classes/Device.class.php b/classes/Device.class.php index 7fea0de1b..9fdf03e71 100644 --- a/classes/Device.class.php +++ b/classes/Device.class.php @@ -610,7 +610,9 @@ function CopyDeviceCustomValues($new) { global $dbh; if($this->GetDevice() && $new->GetDevice()) { $sql="INSERT INTO fac_DeviceCustomValue(DeviceID, AttributeID, Value) - SELECT $new->DeviceID, dcv.AttributeID, dcv.Value FROM fac_DeviceCustomValue dcv WHERE dcv.DeviceID=$this->DeviceID;"; + SELECT $new->DeviceID, dcv.AttributeID, dcv.Value + FROM fac_DeviceCustomValue, dcv WHERE dcv.DeviceID=$this->DeviceID + ON DUPLICATE KEY UPDATE Value=dcv.Value;"; if(!$dbh->query($sql)){ $info=$dbh->errorInfo();