Commit 423331da by bergquist

alerting: delete alerts when parent folder is deleted

closes #13322
parent 0df14f3f
...@@ -327,20 +327,34 @@ func DeleteDashboard(cmd *m.DeleteDashboardCommand) error { ...@@ -327,20 +327,34 @@ func DeleteDashboard(cmd *m.DeleteDashboardCommand) error {
if dashboard.IsFolder { if dashboard.IsFolder {
deletes = append(deletes, "DELETE FROM dashboard_provisioning WHERE dashboard_id in (select id from dashboard where folder_id = ?)") deletes = append(deletes, "DELETE FROM dashboard_provisioning WHERE dashboard_id in (select id from dashboard where folder_id = ?)")
deletes = append(deletes, "DELETE FROM dashboard WHERE folder_id = ?") deletes = append(deletes, "DELETE FROM dashboard WHERE folder_id = ?")
}
for _, sql := range deletes {
_, err := sess.Exec(sql, dashboard.Id)
dashIds := []struct {
Id int64
}{}
err := sess.SQL("select id from dashboard where folder_id = ?", dashboard.Id).Find(&dashIds)
if err != nil { if err != nil {
return err return err
} }
for _, id := range dashIds {
if err := deleteAlertDefinition(id.Id, sess); err != nil {
return nil
}
}
} }
if err := deleteAlertDefinition(dashboard.Id, sess); err != nil { if err := deleteAlertDefinition(dashboard.Id, sess); err != nil {
return nil return nil
} }
for _, sql := range deletes {
_, err := sess.Exec(sql, dashboard.Id)
if err != nil {
return err
}
}
return nil return nil
}) })
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment