| 144 | } |
| 145 | |
| 146 | void HostDbObject::OnConfigUpdateHeavy() |
| 147 | { |
| 148 | Host::Ptr host = static_pointer_cast<Host>(GetObject()); |
| 149 | |
| 150 | /* groups */ |
| 151 | Array::Ptr groups = host->GetGroups(); |
| 152 | |
| 153 | std::vector<DbQuery> queries; |
| 154 | |
| 155 | DbQuery query1; |
| 156 | query1.Table = DbType::GetByName("HostGroup")->GetTable() + "_members"; |
| 157 | query1.Type = DbQueryDelete; |
| 158 | query1.Category = DbCatConfig; |
| 159 | query1.WhereCriteria = new Dictionary(); |
| 160 | query1.WhereCriteria->Set("host_object_id", host); |
| 161 | queries.emplace_back(std::move(query1)); |
| 162 | |
| 163 | if (groups) { |
| 164 | ObjectLock olock(groups); |
| 165 | for (String groupName : groups) { |
| 166 | HostGroup::Ptr group = HostGroup::GetByName(groupName); |
| 167 | |
| 168 | DbQuery query2; |
| 169 | query2.Table = DbType::GetByName("HostGroup")->GetTable() + "_members"; |
| 170 | query2.Type = DbQueryInsert; |
| 171 | query2.Category = DbCatConfig; |
| 172 | query2.Fields = new Dictionary({ |
| 173 | { "instance_id", 0 }, /* DbConnection class fills in real ID */ |
| 174 | { "hostgroup_id", DbValue::FromObjectInsertID(group) }, |
| 175 | { "host_object_id", host } |
| 176 | }); |
| 177 | query2.WhereCriteria = new Dictionary({ |
| 178 | { "instance_id", 0 }, /* DbConnection class fills in real ID */ |
| 179 | { "hostgroup_id", DbValue::FromObjectInsertID(group) }, |
| 180 | { "host_object_id", host } |
| 181 | }); |
| 182 | queries.emplace_back(std::move(query2)); |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | DbObject::OnMultipleQueries(queries); |
| 187 | |
| 188 | queries.clear(); |
| 189 | |
| 190 | DbQuery query2; |
| 191 | query2.Table = GetType()->GetTable() + "_parenthosts"; |
| 192 | query2.Type = DbQueryDelete; |
| 193 | query2.Category = DbCatConfig; |
| 194 | query2.WhereCriteria = new Dictionary({ |
| 195 | { GetType()->GetTable() + "_id", DbValue::FromObjectInsertID(GetObject()) } |
| 196 | }); |
| 197 | queries.emplace_back(std::move(query2)); |
| 198 | |
| 199 | /* parents */ |
| 200 | for (const Checkable::Ptr& checkable : host->GetParents()) { |
| 201 | Host::Ptr parent = dynamic_pointer_cast<Host>(checkable); |
| 202 | |
| 203 | if (!parent) |
nothing calls this directly
no test coverage detected