AddComment: return Comment::Ptr instead of String containing the name

Mimic 88e5744d54f79ab6a84260bd4a8d2cc0ffd43465 and address nullptr on concurrent
  add-comment / remove-comment actions.
This commit is contained in:
Yannick Martin 2025-06-03 16:33:12 +02:00
parent ab58ff2928
commit e6fc1b91a7
No known key found for this signature in database
GPG Key ID: AABC9B180F109264
3 changed files with 5 additions and 5 deletions

View File

@ -316,11 +316,11 @@ Dictionary::Ptr ApiActions::AddComment(const ConfigObject::Ptr& object,
return ApiActions::CreateResult(503, "Icinga is reloading.");
}
String commentName = Comment::AddComment(checkable, CommentUser,
Comment::Ptr comment = Comment::AddComment(checkable, CommentUser,
HttpUtility::GetLastParameter(params, "author"),
HttpUtility::GetLastParameter(params, "comment"), false, timestamp);
Comment::Ptr comment = Comment::GetByName(commentName);
String commentName = comment->GetName();
Dictionary::Ptr additional = new Dictionary({
{ "name", commentName },

View File

@ -130,7 +130,7 @@ int Comment::GetNextCommentID()
return l_NextCommentID;
}
String Comment::AddComment(const Checkable::Ptr& checkable, CommentType entryType, const String& author,
Comment::Ptr Comment::AddComment(const Checkable::Ptr& checkable, CommentType entryType, const String& author,
const String& text, bool persistent, double expireTime, bool sticky, const String& id, const MessageOrigin::Ptr& origin)
{
String fullName;
@ -184,7 +184,7 @@ String Comment::AddComment(const Checkable::Ptr& checkable, CommentType entryTyp
Log(LogNotice, "Comment")
<< "Added comment '" << comment->GetName() << "'.";
return fullName;
return comment;
}
void Comment::RemoveComment(const String& id, bool removedManually, const String& removedBy,

View File

@ -34,7 +34,7 @@ public:
static int GetNextCommentID();
static String AddComment(const intrusive_ptr<Checkable>& checkable, CommentType entryType,
static Ptr AddComment(const intrusive_ptr<Checkable>& checkable, CommentType entryType,
const String& author, const String& text, bool persistent, double expireTime, bool sticky = false,
const String& id = String(), const MessageOrigin::Ptr& origin = nullptr);