From 2b0fd9e34b6ac68edec38d265b26e6af57e66ac1 Mon Sep 17 00:00:00 2001 From: Michael Friedrich Date: Fri, 2 Aug 2013 17:11:14 +0200 Subject: [PATCH] ido: Clear config tables on startup fixes #4502 --- components/ido_mysql/mysqldbconnection.cpp | 36 +++++++++++++++++++++- components/ido_mysql/mysqldbconnection.h | 3 ++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/components/ido_mysql/mysqldbconnection.cpp b/components/ido_mysql/mysqldbconnection.cpp index 333c079c4..36a97dbf8 100644 --- a/components/ido_mysql/mysqldbconnection.cpp +++ b/components/ido_mysql/mysqldbconnection.cpp @@ -135,6 +135,8 @@ void MysqlDbConnection::ReconnectTimerHandler(void) msgbuf << "MySQL IDO instance id: " << static_cast(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(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(dbrefcol); } else if (DbValue::IsTimestamp(value)) { - long ts = rawvalue; + long ts = rawvalue; std::ostringstream msgbuf; msgbuf << "FROM_UNIXTIME(" << ts << ")"; *result = Value(msgbuf.str()); diff --git a/components/ido_mysql/mysqldbconnection.h b/components/ido_mysql/mysqldbconnection.h index 5d71dc2e4..196dce320 100644 --- a/components/ido_mysql/mysqldbconnection.h +++ b/components/ido_mysql/mysqldbconnection.h @@ -78,6 +78,9 @@ private: void TxTimerHandler(void); void ReconnectTimerHandler(void); + + void ClearConfigTables(void); + void ClearConfigTable(const String& table); }; } -- 2.40.0