Skip to content

Commit

Permalink
Add correction for duplicate key on copy fixes #1433
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wilpig committed Aug 29, 2023
1 parent 5a783a2 commit 3cdc020
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion classes/Device.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

1 comment on commit 3cdc020

@Cotximahou
Copy link

@Cotximahou Cotximahou commented on 3cdc020 Sep 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, after I applied this fix my instance is still giving us the same 500 error. Thanks.

Edit: found this error in www-error.log
image

Please sign in to comment.