diff --git a/lib/NGCP/Panel/Controller/Customer.pm b/lib/NGCP/Panel/Controller/Customer.pm index fdb498a6cf..69b5d336c1 100644 --- a/lib/NGCP/Panel/Controller/Customer.pm +++ b/lib/NGCP/Panel/Controller/Customer.pm @@ -1058,26 +1058,14 @@ sub pbx_group_edit :Chained('pbx_group_base') :PathPart('edit') :Args(0) { my $schema = $c->model('DB'); $schema->txn_do(sub { $c->stash->{pbx_group}->provisioning_voip_subscriber->update($form->params); - my $hunt_policy = NGCP::Panel::Utils::Preferences::get_usr_preference_rs( + NGCP::Panel::Utils::Subscriber::update_subscriber_pbx_policy( c => $c, prov_subscriber => $c->stash->{pbx_group}->provisioning_voip_subscriber, - attribute => 'cloud_pbx_hunt_policy' - ); - if($hunt_policy->first) { - $hunt_policy->first->update({ value => $form->params->{pbx_hunt_policy} }); - } else { - $hunt_policy->create({ value => $form->params->{pbx_hunt_policy} }); - } - my $hunt_timeout = NGCP::Panel::Utils::Preferences::get_usr_preference_rs( - c => $c, - prov_subscriber => $c->stash->{pbx_group}->provisioning_voip_subscriber, - attribute => 'cloud_pbx_hunt_timeout' + 'values' => { + cloud_pbx_hunt_policy => $form->params->{pbx_hunt_policy}, + cloud_pbx_hunt_timeout => $form->params->{pbx_hunt_timeout}, + } ); - if($hunt_timeout->first) { - $hunt_timeout->first->update({ value => $form->params->{pbx_hunt_timeout} }); - } else { - $hunt_timeout->create({ value => $form->params->{pbx_hunt_timeout} }); - } }); NGCP::Panel::Utils::Message->info( c => $c, diff --git a/lib/NGCP/Panel/Role/API/Subscribers.pm b/lib/NGCP/Panel/Role/API/Subscribers.pm index 645c1128b3..91f383d63b 100644 --- a/lib/NGCP/Panel/Role/API/Subscribers.pm +++ b/lib/NGCP/Panel/Role/API/Subscribers.pm @@ -590,6 +590,14 @@ sub update_item { if($self->is_true($resource->{is_pbx_group})) { $provisioning_res->{pbx_hunt_policy} = $resource->{pbx_hunt_policy}; $provisioning_res->{pbx_hunt_timeout} = $resource->{pbx_hunt_timeout}; + NGCP::Panel::Utils::Subscriber::update_subscriber_pbx_policy( + c => $c, + prov_subscriber => $subscriber->provisioning_voip_subscriber, + 'values' => { + cloud_pbx_hunt_policy => $resource->{pbx_hunt_policy}, + cloud_pbx_hunt_timeout => $resource->{pbx_hunt_timeout}, + } + ); } my $old_profile = $prov_subscriber->profile_id; diff --git a/lib/NGCP/Panel/Utils/Subscriber.pm b/lib/NGCP/Panel/Utils/Subscriber.pm index b5554bf8eb..53572e5933 100644 --- a/lib/NGCP/Panel/Utils/Subscriber.pm +++ b/lib/NGCP/Panel/Utils/Subscriber.pm @@ -351,7 +351,29 @@ sub create_subscriber { return $billing_subscriber; }); } - +sub update_subscriber_pbx_policy { + my (%params) = @_; + my $c = $params{c}; + my $prov_subscriber = $params{prov_subscriber}; + my $values = $params{values}; + + #todo: use update_preferences instead? + + foreach(qw/cloud_pbx_hunt_policy cloud_pbx_hunt_timeout/){ + my $preference = NGCP::Panel::Utils::Preferences::get_usr_preference_rs( + c => $c, + prov_subscriber => $prov_subscriber, + attribute => $_ + ); + if($preference) { + if($preference && $preference->first) { + $preference->first->update({ value => $values->{$_} }); + } else { + $preference->create({ value => $values->{$_} }); + } + } + } +} sub update_preferences { my (%params) = @_; my $c = $params{c};