|
|
@@ -3,7 +3,6 @@ package sqlstore
|
|
|
import (
|
|
|
"bytes"
|
|
|
"fmt"
|
|
|
- "strings"
|
|
|
"time"
|
|
|
|
|
|
"github.com/go-xorm/xorm"
|
|
|
@@ -252,31 +251,18 @@ func SetAlertState(cmd *m.SetAlertStateCommand) error {
|
|
|
|
|
|
func PauseAlert(cmd *m.PauseAlertCommand) error {
|
|
|
return inTransaction(func(sess *xorm.Session) error {
|
|
|
- if len(cmd.AlertIds) == 0 {
|
|
|
- return fmt.Errorf("command contains no alertids")
|
|
|
- }
|
|
|
-
|
|
|
- var buffer bytes.Buffer
|
|
|
params := make([]interface{}, 0)
|
|
|
|
|
|
- buffer.WriteString(`UPDATE alert SET state = ?`)
|
|
|
+ sql := `UPDATE alert SET state = ? WHERE id = ?`
|
|
|
if cmd.Paused {
|
|
|
params = append(params, string(m.AlertStatePaused))
|
|
|
} else {
|
|
|
params = append(params, string(m.AlertStatePending))
|
|
|
}
|
|
|
+ params = append(params, cmd.AlertId)
|
|
|
|
|
|
- buffer.WriteString(` WHERE id IN (?` + strings.Repeat(",?", len(cmd.AlertIds)-1) + `)`)
|
|
|
- for _, v := range cmd.AlertIds {
|
|
|
- params = append(params, v)
|
|
|
- }
|
|
|
-
|
|
|
- res, err := sess.Exec(buffer.String(), params...)
|
|
|
- if err != nil {
|
|
|
- return err
|
|
|
- }
|
|
|
- cmd.ResultCount, _ = res.RowsAffected()
|
|
|
- return nil
|
|
|
+ _, err := sess.Exec(sql, params...)
|
|
|
+ return err
|
|
|
})
|
|
|
}
|
|
|
|