Bugfix: some legacy_id changes didn't cause the cache to get updated.

This commit is contained in:
Gunnar Beutner 2013-01-30 15:10:51 +01:00
parent 49cc9f5898
commit 7b03c77b66
3 changed files with 8 additions and 32 deletions

View File

@ -184,11 +184,6 @@ void CompatComponent::DumpComments(ofstream& fp, const DynamicObject::Ptr& owner
if (CommentProcessor::IsCommentExpired(comment))
continue;
/* There's no way for us to dump comments that haven't been
* assigned a legacy ID yet. */
if (!comment->Contains("legacy_id"))
continue;
if (!service)
fp << "hostcomment {" << "\n";
else
@ -234,11 +229,6 @@ void CompatComponent::DumpDowntimes(ofstream& fp, const DynamicObject::Ptr& owne
if (DowntimeProcessor::IsDowntimeExpired(downtime))
continue;
/* There's no way for us to dump downtimes that haven't been
* assigned a legacy ID yet. */
if (!downtime->Contains("legacy_id"))
continue;
if (!service)
fp << "hostdowntime {" << "\n";
else

View File

@ -42,6 +42,7 @@ String CommentProcessor::AddComment(const DynamicObject::Ptr& owner,
comment->Set("author", author);
comment->Set("text", text);
comment->Set("expire_time", expireTime);
comment->Set("legacy_id", m_NextCommentID++);
Dictionary::Ptr comments = owner->Get("comments");
@ -133,15 +134,7 @@ void CommentProcessor::AddCommentsToCache(const DynamicObject::Ptr& owner)
String id;
Dictionary::Ptr comment;
BOOST_FOREACH(tie(id, comment), comments) {
int legacy_id;
if (!comment->Contains("legacy_id")) {
legacy_id = m_NextCommentID;
m_NextCommentID++;
comment->Set("legacy_id", legacy_id);
} else {
legacy_id = comment->Get("legacy_id");
}
int legacy_id = comment->Get("legacy_id");
if (legacy_id >= m_NextCommentID)
m_NextCommentID = legacy_id + 1;
@ -150,9 +143,9 @@ void CommentProcessor::AddCommentsToCache(const DynamicObject::Ptr& owner)
/* The legacy_id is already in use by another comment;
* this shouldn't usually happen - assign it a new ID */
legacy_id = m_NextCommentID;
m_NextCommentID++;
legacy_id = m_NextCommentID++;
comment->Set("legacy_id", legacy_id);
owner->Touch("comments");
}
m_LegacyCommentCache[legacy_id] = id;

View File

@ -47,6 +47,7 @@ String DowntimeProcessor::AddDowntime(const DynamicObject::Ptr& owner,
downtime->Set("duration", duration);
downtime->Set("triggered_by", triggeredBy);
downtime->Set("trigger_time", 0);
downtime->Set("legacy_id", m_NextDowntimeID++);
Dictionary::Ptr downtimes = owner->Get("downtimes");
@ -149,15 +150,7 @@ void DowntimeProcessor::AddDowntimesToCache(const DynamicObject::Ptr& owner)
BOOST_FOREACH(tie(id, downtime), downtimes) {
double end_time = downtime->Get("end_time");
int legacy_id;
if (!downtime->Contains("legacy_id")) {
legacy_id = m_NextDowntimeID;
m_NextDowntimeID++;
downtime->Set("legacy_id", legacy_id);
} else {
legacy_id = downtime->Get("legacy_id");
}
int legacy_id = downtime->Get("legacy_id");
if (legacy_id >= m_NextDowntimeID)
m_NextDowntimeID = legacy_id + 1;
@ -165,9 +158,9 @@ void DowntimeProcessor::AddDowntimesToCache(const DynamicObject::Ptr& owner)
if (m_LegacyDowntimeCache.find(legacy_id) != m_LegacyDowntimeCache.end()) {
/* The legacy_id is already in use by another downtime;
* this shouldn't usually happen - assign it a new ID. */
legacy_id = m_NextDowntimeID;
m_NextDowntimeID++;
legacy_id = m_NextDowntimeID++;
downtime->Set("legacy_id", legacy_id);
owner->Touch("downtimes");
}
m_LegacyDowntimeCache[legacy_id] = id;