|
@@ -3,6 +3,7 @@ package sqlstore
|
|
|
import (
|
|
import (
|
|
|
"bytes"
|
|
"bytes"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
|
|
+ "strings"
|
|
|
"time"
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/go-xorm/xorm"
|
|
"github.com/go-xorm/xorm"
|
|
@@ -251,18 +252,31 @@ func SetAlertState(cmd *m.SetAlertStateCommand) error {
|
|
|
|
|
|
|
|
func PauseAlert(cmd *m.PauseAlertCommand) error {
|
|
func PauseAlert(cmd *m.PauseAlertCommand) error {
|
|
|
return inTransaction(func(sess *xorm.Session) 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)
|
|
params := make([]interface{}, 0)
|
|
|
|
|
|
|
|
- sql := `UPDATE alert SET state = ? WHERE id = ?`
|
|
|
|
|
|
|
+ buffer.WriteString(`UPDATE alert SET state = ?`)
|
|
|
if cmd.Paused {
|
|
if cmd.Paused {
|
|
|
params = append(params, string(m.AlertStatePaused))
|
|
params = append(params, string(m.AlertStatePaused))
|
|
|
} else {
|
|
} else {
|
|
|
params = append(params, string(m.AlertStatePending))
|
|
params = append(params, string(m.AlertStatePending))
|
|
|
}
|
|
}
|
|
|
- params = append(params, cmd.AlertId)
|
|
|
|
|
|
|
|
|
|
- _, err := sess.Exec(sql, params...)
|
|
|
|
|
- return err
|
|
|
|
|
|
|
+ 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
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|