ido: Clear config tables on startup

fixes #4502
This commit is contained in:
Michael Friedrich 2013-08-02 17:11:14 +02:00
parent 0af6393033
commit 2b0fd9e34b
2 changed files with 38 additions and 1 deletions

View File

@ -135,6 +135,8 @@ void MysqlDbConnection::ReconnectTimerHandler(void)
msgbuf << "MySQL IDO instance id: " << static_cast<long>(m_InstanceID);
Log(LogInformation, "ido_mysql", msgbuf.str());
ClearConfigTables();
Query("UPDATE " + GetTablePrefix() + "objects SET is_active = 0");
std::ostringstream q1buf;
@ -158,6 +160,38 @@ void MysqlDbConnection::ReconnectTimerHandler(void)
UpdateAllObjects();
}
void MysqlDbConnection::ClearConfigTables(void)
{
/* TODO make hardcoded table names modular */
ClearConfigTable("commands");
ClearConfigTable("contact_addresses");
ClearConfigTable("contact_notificationcommands");
ClearConfigTable("contactgroup_members");
ClearConfigTable("contactgroups");
ClearConfigTable("contacts");
ClearConfigTable("customvariables");
ClearConfigTable("host_contactgroups");
ClearConfigTable("host_contacts");
ClearConfigTable("host_parenthosts");
ClearConfigTable("hostdependencies");
ClearConfigTable("hostgroup_members");
ClearConfigTable("hostgroups");
ClearConfigTable("hosts");
ClearConfigTable("service_contactgroups");
ClearConfigTable("service_contacts");
ClearConfigTable("servicedependencies");
ClearConfigTable("servicegroup_members");
ClearConfigTable("servicegroups");
ClearConfigTable("services");
ClearConfigTable("timeperiod_timeranges");
ClearConfigTable("timeperiods");
}
void MysqlDbConnection::ClearConfigTable(const String& table)
{
Query("DELETE FROM " + GetTablePrefix() + table + " WHERE instance_id = " + Convert::ToString(static_cast<long>(m_InstanceID)));
}
Array::Ptr MysqlDbConnection::Query(const String& query)
{
Log(LogDebug, "ido_mysql", "Query: " + query);
@ -325,7 +359,7 @@ bool MysqlDbConnection::FieldToEscapedString(const String& key, const Value& val
*result = static_cast<long>(dbrefcol);
} else if (DbValue::IsTimestamp(value)) {
long ts = rawvalue;
long ts = rawvalue;
std::ostringstream msgbuf;
msgbuf << "FROM_UNIXTIME(" << ts << ")";
*result = Value(msgbuf.str());

View File

@ -78,6 +78,9 @@ private:
void TxTimerHandler(void);
void ReconnectTimerHandler(void);
void ClearConfigTables(void);
void ClearConfigTable(const String& table);
};
}