mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 05:39:54 +05:00
Added RemoveActionPlans.Fixes#1517
This commit is contained in:
committed by
Dan Christian Bogos
parent
9a4299dcde
commit
11bd70735a
@@ -722,6 +722,39 @@ func (self *ApierV1) GetActionPlan(attr AttrGetActionPlan, reply *[]*engine.Acti
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *ApierV1) RemoveActionPlan(attr AttrGetActionPlan, reply *string) (err error) {
|
||||
if missing := utils.MissingStructFields(&attr, []string{"ID"}); len(missing) != 0 {
|
||||
return utils.NewErrMandatoryIeMissing(missing...)
|
||||
}
|
||||
if _, err = guardian.Guardian.Guard(func() (interface{}, error) {
|
||||
var prevAccountIDs utils.StringMap
|
||||
if prevAP, err := self.DataManager.DataDB().GetActionPlan(attr.ID, false, utils.NonTransactional); err != nil && err != utils.ErrNotFound {
|
||||
return 0, err
|
||||
} else if prevAP != nil {
|
||||
prevAccountIDs = prevAP.AccountIDs
|
||||
}
|
||||
if err := self.DataManager.DataDB().RemoveActionPlan(attr.ID, utils.NonTransactional); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
for acntID := range prevAccountIDs {
|
||||
if err := self.DataManager.DataDB().RemAccountActionPlans(acntID, []string{attr.ID}); err != nil {
|
||||
return 0, utils.NewErrServerError(err)
|
||||
}
|
||||
}
|
||||
if len(prevAccountIDs) != 0 {
|
||||
if err = self.DataManager.CacheDataFromDB(utils.AccountActionPlansPrefix, prevAccountIDs.Slice(), true); err != nil &&
|
||||
err.Error() != utils.ErrNotFound.Error() {
|
||||
return 0, utils.NewErrServerError(err)
|
||||
}
|
||||
}
|
||||
return 0, nil
|
||||
}, config.CgrConfig().GeneralCfg().LockingTimeout, utils.ACTION_PLAN_PREFIX); err != nil {
|
||||
return err
|
||||
}
|
||||
*reply = OK
|
||||
return nil
|
||||
}
|
||||
|
||||
// Process dependencies and load a specific AccountActions profile from storDb into dataDb.
|
||||
func (self *ApierV1) LoadAccountActions(attrs utils.TPAccountActions, reply *string) error {
|
||||
if len(attrs.TPid) == 0 {
|
||||
|
||||
65
console/actionplan_remove.go
Normal file
65
console/actionplan_remove.go
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
Real-time Online/Offline Charging System (OCS) for Telecom & ISP environments
|
||||
Copyright (C) ITsysCOM GmbH
|
||||
|
||||
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 (
|
||||
v1 "github.com/cgrates/cgrates/apier/v1"
|
||||
)
|
||||
|
||||
func init() {
|
||||
c := &CmdRemoveActionPlan{
|
||||
name: "actionplan_remove",
|
||||
rpcMethod: "ApierV1.RemoveActionPlan",
|
||||
rpcParams: &v1.AttrGetActionPlan{},
|
||||
}
|
||||
commands[c.Name()] = c
|
||||
c.CommandExecuter = &CommandExecuter{c}
|
||||
}
|
||||
|
||||
// Commander implementation
|
||||
type CmdRemoveActionPlan struct {
|
||||
name string
|
||||
rpcMethod string
|
||||
rpcParams *v1.AttrGetActionPlan
|
||||
*CommandExecuter
|
||||
}
|
||||
|
||||
func (self *CmdRemoveActionPlan) Name() string {
|
||||
return self.name
|
||||
}
|
||||
|
||||
func (self *CmdRemoveActionPlan) RpcMethod() string {
|
||||
return self.rpcMethod
|
||||
}
|
||||
|
||||
func (self *CmdRemoveActionPlan) RpcParams(reset bool) interface{} {
|
||||
if reset || self.rpcParams == nil {
|
||||
self.rpcParams = &v1.AttrGetActionPlan{}
|
||||
}
|
||||
return self.rpcParams
|
||||
}
|
||||
|
||||
func (self *CmdRemoveActionPlan) PostprocessRpcParams() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *CmdRemoveActionPlan) RpcResult() interface{} {
|
||||
var s string
|
||||
return &s
|
||||
}
|
||||
Reference in New Issue
Block a user