From ef6bfee65b336092c2def47db05b6f034db2352a Mon Sep 17 00:00:00 2001 From: Gerhard Jungwirth Date: Fri, 20 Dec 2013 13:27:23 +0100 Subject: [PATCH] MT#4967 update cloud_pbx_base_cli and other settings on cloudpbx-subscribers This includes: primary_number, dbaliases, cfs --- lib/NGCP/Panel/Controller/Subscriber.pm | 29 --------------- lib/NGCP/Panel/Utils/Subscriber.pm | 47 +++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 29 deletions(-) diff --git a/lib/NGCP/Panel/Controller/Subscriber.pm b/lib/NGCP/Panel/Controller/Subscriber.pm index a4ab12f46b..8dea718170 100644 --- a/lib/NGCP/Panel/Controller/Subscriber.pm +++ b/lib/NGCP/Panel/Controller/Subscriber.pm @@ -1867,10 +1867,6 @@ sub edit_master :Chained('master') :PathPart('edit') :Args(0) :Does(ACL) :ACLDet $form->params->{e164}{sn} = $base_number->{sn} . $form->params->{extension}; } - my $old_cc = $subscriber->primary_number->cc; - my $old_ac = $subscriber->primary_number->ac; - my $old_sn = $subscriber->primary_number->sn; - NGCP::Panel::Utils::Subscriber::update_subscriber_numbers( schema => $schema, subscriber_id =>$subscriber->id, @@ -1878,31 +1874,6 @@ sub edit_master :Chained('master') :PathPart('edit') :Args(0) :Does(ACL) :ACLDet primary_number => $form->params->{e164}, $subadmin_pbx ? () : (alias_numbers => $form->values->{alias_number}), ); - - # TODO: if it's an admin for pbx, update all other subscribers as well! - # this means cloud_pbx_base_cli pref, primary number, dbaliases, voicemail, cf - # now implemented for primary number - if ( $subscriber->contract->billing_mappings->first->product->class eq "pbxaccount" - && ! defined $prov_subscriber->voip_pbx_group - && ($c->user->roles eq "admin" || $c->user->roles eq "reseller")) { - my $customer_subscribers_rs = $subscriber->contract->voip_subscribers; - my $my_cc = $form->params->{e164}{cc}; - my $my_ac = $form->params->{e164}{ac}; - my $my_sn = $form->params->{e164}{sn}; - for my $sub ($customer_subscribers_rs->all) { - next if $sub->id == $subscriber->id; # myself - next unless $sub->primary_number; - next unless $sub->primary_number->cc == $old_cc; - next unless $sub->primary_number->cc == $old_cc; - next unless $sub->primary_number->ac == $old_ac; - next unless $sub->primary_number->sn =~ /^$old_sn/; - $sub->primary_number->update({ - cc => $my_cc, - ac => $my_ac, - sn => $sub->primary_number->sn =~ s/^$old_sn/$my_sn/r, - }); - } - } } else { NGCP::Panel::Utils::Subscriber::update_subscriber_numbers( schema => $schema, diff --git a/lib/NGCP/Panel/Utils/Subscriber.pm b/lib/NGCP/Panel/Utils/Subscriber.pm index dfd48e92ef..a0fa7b4b9f 100644 --- a/lib/NGCP/Panel/Utils/Subscriber.pm +++ b/lib/NGCP/Panel/Utils/Subscriber.pm @@ -329,6 +329,15 @@ sub update_subscriber_numbers { if (defined $primary_number) { + my $old_cc; + my $old_ac; + my $old_sn; + if (defined $billing_subs->primary_number) { + $old_cc = $billing_subs->primary_number->cc; + $old_ac = $billing_subs->primary_number->ac; + $old_sn = $billing_subs->primary_number->sn; + } + my $number; if (defined $primary_number->{cc} && $primary_number->{cc} ne '') { @@ -404,8 +413,46 @@ sub update_subscriber_numbers { $prov_subs->voicemail_user->update({ mailbox => '0' }); } } + + if ( (defined $old_cc && defined $old_sn) + && $billing_subs->contract->billing_mappings->first->product->class eq "pbxaccount" + && ! defined $prov_subs->voip_pbx_group + && $prov_subs->admin ) { + my $customer_subscribers_rs = $billing_subs->contract->voip_subscribers; + my $my_cc = $primary_number->{cc}; + my $my_ac = $primary_number->{ac}; + my $my_sn = $primary_number->{sn}; + my $new_base_cli = $my_cc . ($my_ac // '') . $my_sn; + my $usr_preferences_base_cli_rs = $schema->resultset('voip_preferences')->find({ + attribute => 'cloud_pbx_base_cli', + })->voip_usr_preferences; + $usr_preferences_base_cli_rs->search_rs({subscriber_id=>$prov_subs->id})->update_all({value => $new_base_cli}); + for my $sub ($customer_subscribers_rs->all) { + next if $sub->id == $billing_subs->id; # myself + next unless $sub->primary_number; + next unless $sub->primary_number->cc == $old_cc; + next unless $sub->primary_number->ac == $old_ac; + next unless $sub->primary_number->sn =~ /^$old_sn/; + $usr_preferences_base_cli_rs->search_rs({subscriber_id=>$sub->provisioning_voip_subscriber->id})->update_all({value => $new_base_cli}); + $schema->resultset('voip_dbaliases')->search_rs({ + username => $old_cc . ($old_ac // '') . $sub->primary_number->sn, + })->delete; + update_subscriber_numbers( + schema => $schema, + subscriber_id => $sub->id, + reseller_id => $reseller_id, + primary_number => { + cc => $my_cc, + ac => $my_ac, + sn => $sub->primary_number->sn =~ s/^$old_sn/$my_sn/r, + } + ); + } + } + } + if(defined $alias_numbers && ref($alias_numbers) eq 'ARRAY') { # note that this only adds new alias numbers # old entries in voip_numbers and voip_dbaliases are usually deleted