From 9485938d3220564650d0520e219a5872ec2d60e1 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Thu, 29 Oct 2015 16:12:53 +0100 Subject: [PATCH] Fix: Unique constraint violation with multiple comment inserts in DB IDO fixes #10491 --- lib/db_ido/dbevents.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/db_ido/dbevents.cpp b/lib/db_ido/dbevents.cpp index a0c5d5812..0da037c77 100644 --- a/lib/db_ido/dbevents.cpp +++ b/lib/db_ido/dbevents.cpp @@ -303,7 +303,12 @@ void DbEvents::EnableChangedHandlerInternal(const Checkable::Ptr& checkable, con /* comments */ void DbEvents::AddComments(const Checkable::Ptr& checkable) { - BOOST_FOREACH(const Comment::Ptr& comment, checkable->GetComments()) { + std::set comments = checkable->GetComments(); + + if (!comments.empty()) + RemoveComments(checkable); + + BOOST_FOREACH(const Comment::Ptr& comment, comments) { AddComment(comment); } } @@ -430,9 +435,12 @@ void DbEvents::RemoveComment(const Comment::Ptr& comment) /* downtimes */ void DbEvents::AddDowntimes(const Checkable::Ptr& checkable) { - RemoveDowntimes(checkable); + std::set downtimes = checkable->GetDowntimes(); - BOOST_FOREACH(const Downtime::Ptr& downtime, checkable->GetDowntimes()) { + if (!downtimes.empty()) + RemoveDowntimes(checkable); + + BOOST_FOREACH(const Downtime::Ptr& downtime, downtimes) { AddDowntime(downtime, false); } }