mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 18:16:24 +05:00
Merge branch 'master' into faststart
This commit is contained in:
@@ -321,6 +321,47 @@ func (self *ApierV1) SetAccountActionTriggers(attr AttrSetAccountActionTriggers,
|
||||
return nil
|
||||
}
|
||||
|
||||
type AttrRemoveActionTrigger struct {
|
||||
GroupID string
|
||||
UniqueID string
|
||||
}
|
||||
|
||||
func (self *ApierV1) RemoveActionTrigger(attr AttrRemoveActionTrigger, reply *string) error {
|
||||
if missing := utils.MissingStructFields(&attr, []string{"GroupID"}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if attr.UniqueID == "" {
|
||||
err := self.RatingDb.RemoveActionTriggers(attr.GroupID)
|
||||
if err != nil {
|
||||
*reply = err.Error()
|
||||
} else {
|
||||
*reply = utils.OK
|
||||
}
|
||||
return err
|
||||
} else {
|
||||
atrs, err := self.RatingDb.GetActionTriggers(attr.GroupID)
|
||||
if err != nil {
|
||||
*reply = err.Error()
|
||||
return err
|
||||
}
|
||||
var remainingAtrs engine.ActionTriggers
|
||||
for _, atr := range atrs {
|
||||
if atr.UniqueID == attr.UniqueID {
|
||||
continue
|
||||
}
|
||||
remainingAtrs = append(remainingAtrs, atr)
|
||||
}
|
||||
// set the cleared list back
|
||||
err = self.RatingDb.SetActionTriggers(attr.GroupID, remainingAtrs)
|
||||
if err != nil {
|
||||
*reply = err.Error()
|
||||
} else {
|
||||
*reply = utils.OK
|
||||
}
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
type AttrSetActionTrigger struct {
|
||||
GroupID string
|
||||
UniqueID string
|
||||
|
||||
63
console/trigger_remove.go
Normal file
63
console/trigger_remove.go
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
Rating system designed to be used in VoIP Carriers World
|
||||
Copyright (C) 2012-2015 ITsysCOM
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*/
|
||||
|
||||
package console
|
||||
|
||||
import "github.com/cgrates/cgrates/apier/v1"
|
||||
|
||||
func init() {
|
||||
c := &CmdRemoveTriggers{
|
||||
name: "triggers_remove",
|
||||
rpcMethod: "ApierV1.RemoveActionTrigger",
|
||||
rpcParams: &v1.AttrRemoveActionTrigger{},
|
||||
}
|
||||
commands[c.Name()] = c
|
||||
c.CommandExecuter = &CommandExecuter{c}
|
||||
}
|
||||
|
||||
// Commander implementation
|
||||
type CmdRemoveTriggers struct {
|
||||
name string
|
||||
rpcMethod string
|
||||
rpcParams *v1.AttrRemoveActionTrigger
|
||||
*CommandExecuter
|
||||
}
|
||||
|
||||
func (self *CmdRemoveTriggers) Name() string {
|
||||
return self.name
|
||||
}
|
||||
|
||||
func (self *CmdRemoveTriggers) RpcMethod() string {
|
||||
return self.rpcMethod
|
||||
}
|
||||
|
||||
func (self *CmdRemoveTriggers) RpcParams(reset bool) interface{} {
|
||||
if reset || self.rpcParams == nil {
|
||||
self.rpcParams = &v1.AttrRemoveActionTrigger{}
|
||||
}
|
||||
return self.rpcParams
|
||||
}
|
||||
|
||||
func (self *CmdRemoveTriggers) PostprocessRpcParams() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *CmdRemoveTriggers) RpcResult() interface{} {
|
||||
var s string
|
||||
return &s
|
||||
}
|
||||
@@ -64,6 +64,7 @@ type RatingStorage interface {
|
||||
SetSharedGroup(*SharedGroup) error
|
||||
GetActionTriggers(string) (ActionTriggers, error)
|
||||
SetActionTriggers(string, ActionTriggers) error
|
||||
RemoveActionTriggers(string) error
|
||||
GetActionPlan(string, bool) (*ActionPlan, error)
|
||||
SetActionPlan(string, *ActionPlan, bool) error
|
||||
GetAllActionPlans() (map[string]*ActionPlan, error)
|
||||
|
||||
@@ -731,6 +731,13 @@ func (ms *MapStorage) SetActionTriggers(key string, atrs ActionTriggers) (err er
|
||||
return
|
||||
}
|
||||
|
||||
func (ms *MapStorage) RemoveActionTriggers(key string) (err error) {
|
||||
ms.mu.Lock()
|
||||
defer ms.mu.Unlock()
|
||||
delete(ms.dict, utils.ACTION_TRIGGER_PREFIX+key)
|
||||
return
|
||||
}
|
||||
|
||||
func (ms *MapStorage) GetActionPlan(key string, skipCache bool) (ats *ActionPlan, err error) {
|
||||
ms.mu.RLock()
|
||||
defer ms.mu.RUnlock()
|
||||
|
||||
@@ -1393,6 +1393,12 @@ func (ms *MongoStorage) SetActionTriggers(key string, atrs ActionTriggers) (err
|
||||
return err
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) RemoveActionTriggers(key string) error {
|
||||
session, col := ms.conn(colAtr)
|
||||
defer session.Close()
|
||||
return col.Remove(bson.M{"key": key})
|
||||
}
|
||||
|
||||
func (ms *MongoStorage) GetActionPlan(key string, skipCache bool) (ats *ActionPlan, err error) {
|
||||
if !skipCache {
|
||||
if x, err := CacheGet(utils.ACTION_PLAN_PREFIX + key); err == nil {
|
||||
|
||||
@@ -1031,6 +1031,11 @@ func (rs *RedisStorage) SetActionTriggers(key string, atrs ActionTriggers) (err
|
||||
return conn.Cmd("SET", utils.ACTION_TRIGGER_PREFIX+key, result).Err
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) RemoveActionTriggers(key string) (err error) {
|
||||
err = rs.db.Cmd("DEL", utils.ACTION_TRIGGER_PREFIX+key).Err
|
||||
return
|
||||
}
|
||||
|
||||
func (rs *RedisStorage) GetActionPlan(key string, skipCache bool) (ats *ActionPlan, err error) {
|
||||
key = utils.ACTION_PLAN_PREFIX + key
|
||||
if !skipCache {
|
||||
|
||||
Reference in New Issue
Block a user