TT#6735 TT#5850 refactor "profile" events to track number changes

Change-Id: I59a01ebe0ddb440bc9a4f091c85b84641ae460b1
changes/85/10985/6
Rene Krenn 8 years ago
parent 42b06ca2e9
commit 7b646044d8

@ -413,11 +413,9 @@ sub POST :Allow {
subscriber => $subscriber,
);
NGCP::Panel::Utils::Events::insert_deferred(
c => $c,
schema => $schema,
c => $c, schema => $schema,
events_to_create => \@events_to_create,
);
#ready for number change events here
} catch(DBIx::Class::Exception $e where { /Duplicate entry '([^']+)' for key 'number_idx'/ }) {
$e =~ /Duplicate entry '([^']+)' for key 'number_idx'/;
$c->log->error("failed to create subscriber, number $1 already exists"); # TODO: user, message, trace, ...

@ -874,11 +874,9 @@ sub subscriber_create :Chained('base') :PathPart('subscriber/create') :Args(0) {
);
}
NGCP::Panel::Utils::Events::insert_deferred(
c => $c,
schema => $schema,
c => $c, schema => $schema,
events_to_create => \@events_to_create,
);
#ready for number change events here
});
delete $c->session->{created_objects}->{domain};
@ -1379,11 +1377,9 @@ sub pbx_group_create :Chained('base') :PathPart('pbx/group/create') :Args(0) {
);
NGCP::Panel::Utils::ProfilePackages::underrun_lock_subscriber(c => $c, subscriber => $billing_subscriber);
NGCP::Panel::Utils::Events::insert_deferred(
c => $c,
schema => $schema,
c => $c, schema => $schema,
events_to_create => \@events_to_create,
);
#ready for number change events here
$c->session->{created_objects}->{group} = { id => $billing_subscriber->id };
});
NGCP::Panel::Utils::Message::info(

@ -997,8 +997,8 @@ sub preferences_callforward :Chained('base') :PathPart('preferences/callforward'
}
my $d = $cf_form->field('destination')->field('destination')->value;
NGCP::Panel::Utils::Subscriber::check_cf_ivr(
c => $c, schema => $c->model('DB'),
subscriber => $c->stash->{subscriber},
schema => $c->model('DB'),
old_aa => $old_autoattendant,
new_aa => ($d eq 'autoattendant'),
);
@ -1209,8 +1209,8 @@ sub preferences_callforward_advanced :Chained('base') :PathPart('preferences/cal
while ($autoattendant_count != 0) {
$autoattendant_count--;
NGCP::Panel::Utils::Events::insert(
schema => $c->model('DB'),
subscriber => $c->stash->{subscriber},
c => $c, schema => $c->model('DB'),
subscriber_id => $c->stash->{subscriber}->id,
type => 'end_ivr',
);
}
@ -1218,8 +1218,8 @@ sub preferences_callforward_advanced :Chained('base') :PathPart('preferences/cal
while ($autoattendant_count != 0) {
$autoattendant_count++;
NGCP::Panel::Utils::Events::insert(
schema => $c->model('DB'),
subscriber => $c->stash->{subscriber},
c => $c, schema => $c->model('DB'),
subscriber_id => $c->stash->{subscriber}->id,
type => 'start_ivr',
);
}
@ -1445,8 +1445,8 @@ sub preferences_callforward_destinationset_edit :Chained('preferences_callforwar
if($cf_type eq "cft" && $ringtimeout_preference->first);
$mapping->delete;
NGCP::Panel::Utils::Subscriber::check_cf_ivr( # one event per affected mapping
c => $c, schema => $schema,
subscriber => $c->stash->{subscriber},
schema => $schema,
old_aa => NGCP::Panel::Utils::Subscriber::check_dset_autoattendant_status($set),
new_aa => 0,
);
@ -1480,8 +1480,8 @@ sub preferences_callforward_destinationset_edit :Chained('preferences_callforwar
if ($event_type) {
foreach my $mapping ($set->voip_cf_mappings->all) { # one event per affected mapping
NGCP::Panel::Utils::Events::insert(
schema => $schema,
subscriber => $c->stash->{subscriber},
c => $c, schema => $schema,
subscriber_id => $c->stash->{subscriber}->id,
type => $event_type,
);
}
@ -1535,8 +1535,8 @@ sub preferences_callforward_destinationset_delete :Chained('preferences_callforw
$map->delete;
if ($autoattendant) {
NGCP::Panel::Utils::Events::insert(
schema => $schema,
subscriber => $c->stash->{subscriber},
c => $c, schema => $schema,
subscriber_id => $c->stash->{subscriber}->id,
type => 'end_ivr',
);
}
@ -2135,8 +2135,8 @@ sub preferences_callforward_delete :Chained('base') :PathPart('preferences/callf
while ($autoattendant_count > 0) {
$autoattendant_count--;
NGCP::Panel::Utils::Events::insert(
schema => $schema,
subscriber => $c->stash->{subscriber},
c => $c, schema => $schema,
subscriber_id => $c->stash->{subscriber}->id,
type => 'end_ivr',
);
}
@ -2743,22 +2743,11 @@ sub edit_master :Chained('master') :PathPart('edit') :Args(0) :Does(ACL) :ACLDet
level => $form->values->{lock},
) if ($subscriber->provisioning_voip_subscriber);
if(($prov_subscriber->profile_id // 0) != ($old_profile // 0)) {
my $type;
if(defined $prov_subscriber->profile_id && defined $old_profile) {
$type = "update_profile";
} elsif(defined $prov_subscriber->profile_id) {
$type = "start_profile";
} else {
$type = "end_profile";
}
NGCP::Panel::Utils::Events::insert(
c => $c, schema => $schema, subscriber => $subscriber,
type => $type, old => $old_profile, new => $prov_subscriber->profile_id,
%$aliases_before,
);
}
#ready for number change events here
NGCP::Panel::Utils::Events::insert_profile_events(
c => $c, schema => $schema, subscriber_id => $subscriber->id,
old => $old_profile, new => $prov_subscriber->profile_id,
%$aliases_before,
);
});
delete $c->session->{created_objects}->{group};

@ -159,4 +159,10 @@ has_field 'pilot_first_non_primary_alias_username_after' => (
required => 0,
);
has_field 'non_primary_alias_username' => (
type => 'Text',
label => 'The non-primary alias of an \'update_profile\', \'start_profile\' or \'end_profile\' event to track number changes.',
required => 0,
);
1;

@ -162,7 +162,7 @@ sub update_item {
my $new_aa = NGCP::Panel::Utils::Subscriber::check_dset_autoattendant_status($item);
foreach ($item->voip_cf_mappings->all) {
NGCP::Panel::Utils::Subscriber::check_cf_ivr( # one event per affected mapping
schema => $schema,
c => $c, schema => $schema,
subscriber => $item->subscriber->voip_subscriber,
old_aa => $old_aa,
new_aa => $new_aa,

@ -187,8 +187,8 @@ sub update_item {
while ($autoattendant_count != 0) {
$autoattendant_count--;
NGCP::Panel::Utils::Events::insert(
schema => $c->model('DB'),
subscriber => $item,
c => $c, schema => $c->model('DB'),
subscriber_id => $item->id,
type => 'end_ivr',
);
}
@ -196,8 +196,8 @@ sub update_item {
while ($autoattendant_count != 0) {
$autoattendant_count++;
NGCP::Panel::Utils::Events::insert(
schema => $c->model('DB'),
subscriber => $item,
c => $c, schema => $c->model('DB'),
subscriber_id => $item->id,
type => 'start_ivr',
);
}

@ -252,8 +252,8 @@ sub update_item {
$dset->discard_changes if $dset; # update destinations
my $new_autoattendant = NGCP::Panel::Utils::Subscriber::check_dset_autoattendant_status($dset);
NGCP::Panel::Utils::Subscriber::check_cf_ivr(
c => $c, schema => $c->model('DB'),
subscriber => $item,
schema => $c->model('DB'),
old_aa => $old_autoattendant,
new_aa => $new_autoattendant,
);

@ -71,6 +71,8 @@ sub hal_from_item {
$resource{pilot_first_non_primary_alias_username_before} = NGCP::Panel::Utils::Events::get_tag_value(c => $c, event => $item, type => 'pilot_first_non_primary_alias_username_before');
$resource{pilot_first_non_primary_alias_username_after} = NGCP::Panel::Utils::Events::get_tag_value(c => $c, event => $item, type => 'pilot_first_non_primary_alias_username_after');
$resource{non_primary_alias_username} = NGCP::Panel::Utils::Events::get_tag_value(c => $c, event => $item, type => 'non_primary_alias_username');
my $hal = Data::HAL->new(
links => [
Data::HAL::Link->new(

@ -688,22 +688,11 @@ sub update_item {
$prov_subscriber->update($provisioning_res);
$prov_subscriber->discard_changes;
if(($prov_subscriber->profile_id // 0) != ($old_profile // 0)) {
my $type;
if(defined $prov_subscriber->profile_id && defined $old_profile) {
$type = "update_profile";
} elsif(defined $prov_subscriber->profile_id) {
$type = "start_profile";
} else {
$type = "end_profile";
}
NGCP::Panel::Utils::Events::insert(
c => $c, schema => $schema, subscriber => $subscriber,
type => $type, old => $old_profile, new => $prov_subscriber->profile_id,
%$aliases_before,
);
}
#ready for number change events here
NGCP::Panel::Utils::Events::insert_profile_events(
c => $c, schema => $schema, subscriber_id => $subscriber->id,
old => $old_profile, new => $prov_subscriber->profile_id,
%$aliases_before,
);
NGCP::Panel::Utils::Subscriber::update_preferences(
c => $c,

@ -4,166 +4,326 @@ use Sipwise::Base;
use NGCP::Panel::Utils::DateTime qw();
use constant ENABLE_EVENTS => 1;
use constant CREATE_EVENT_PER_ALIAS => 1;
sub insert_deferred {
my %params = @_;
my $c = $params{c};
my $schema = $params{schema} // $c->model('DB');
my $events_to_create = $params{events_to_create} // [];
my $inserted = 0;
while (my $event = shift @$events_to_create) {
insert(c => $c, schema => $schema,
%$event
);
if ('profile' eq $event->{type}) {
$inserted += insert_profile_events(c => $c, schema => $schema,
%$event
);
} else {
$inserted += insert(c => $c, schema => $schema,
%$event
);
}
}
return $inserted;
}
sub insert_profile_events {
my %params = @_;
return 0 unless ENABLE_EVENTS;
my $c = $params{c};
my $schema = $params{schema} // $c->model('DB');
#my $type = $params{type};
#my $subscriber = $params{subscriber};
my $old_profile_id = $params{old};
my $new_profile_id = $params{new};
my $now_hires = NGCP::Panel::Utils::DateTime::current_local_hires;
#reload it usually:
my $subscriber = $params{subscriber} // $schema->resultset('voip_subscribers')->find({
id => $params{subscriber_id},
});
my $prov_subscriber = $subscriber->provisioning_voip_subscriber;
my $is_pilot = ($prov_subscriber && $prov_subscriber->is_pbx_pilot ? 1 : 0);
my $pilot_subscriber = _get_pilot_subscriber(
c => $c,
schema => $schema,
subscriber => $subscriber,
prov_subscriber => $prov_subscriber,
now_hires => $now_hires,
);
my $pilot_prov_subscriber;
$pilot_prov_subscriber = $pilot_subscriber->provisioning_voip_subscriber if $pilot_subscriber;
my ($old_aliases,$old_aliases_map) = _get_aliases_map($params{old_aliases},$prov_subscriber);
my ($old_pilot_aliases,$old_pilot_aliases_map) = _get_aliases_map($params{old_pilot_aliases},$pilot_prov_subscriber);
my ($new_aliases,$new_aliases_map) = _get_aliases_map($params{new_aliases},$prov_subscriber);
my ($new_pilot_aliases,$new_pilot_aliases_map) = _get_aliases_map($params{new_pilot_aliases},$pilot_prov_subscriber);
my $context = { c => $c, schema => $schema,
subscriber => $subscriber,
old_aliases => $params{old_aliases},
new_aliases => $params{new_aliases},
old_pilot_aliases => $params{old_pilot_aliases},
new_pilot_aliases => $params{new_pilot_aliases},
create_event_per_alias => 0,
now_hires => $now_hires};
my $inserted = 0;
foreach my $new_alias (@$new_aliases) {
$context->{alias} = $new_alias;
if (not exists $old_aliases_map->{$new_alias}) {
if (not $is_pilot and exists $old_pilot_aliases_map->{$new_alias}) {
#aliases moved from pilot to subs
if ($pilot_prov_subscriber) {
$context->{old} = $pilot_prov_subscriber->profile_id;
$context->{new} = $new_profile_id;
$inserted += _insert_profile_event($context);
}
} else {
#aliases added
$context->{old} = undef;
$context->{new} = $new_profile_id;
$inserted += _insert_profile_event($context);
}
} else {
#no number change
$context->{old} = $old_profile_id;
$context->{new} = $new_profile_id;
$inserted += _insert_profile_event($context);
}
}
foreach my $old_alias (@$old_aliases) {
$context->{alias} = $old_alias;
if (not exists $new_aliases_map->{$old_alias}) {
if (not $is_pilot and exists $new_pilot_aliases_map->{$old_alias}) {
#aliases moved from subs to pilot
if ($pilot_prov_subscriber) {
$context->{old} = $old_profile_id;
$context->{new} = $pilot_prov_subscriber->profile_id;
$inserted += _insert_profile_event($context);
}
} else {
#aliases deleted
$context->{old} = $old_profile_id;
$context->{new} = undef;
$inserted += _insert_profile_event($context);
}
} else {
#no number change
}
}
if ((scalar @$old_aliases) + (scalar @$new_aliases) == 0) {
$context->{alias} = undef;
$context->{old} = $old_profile_id;
$context->{new} = $new_profile_id;
$context->{create_event_per_alias} = undef;
$inserted += _insert_profile_event($context);
}
}
sub _insert_profile_event {
my ($context) = @_;
my $inserted = 0;
if(($context->{old} // 0) != ($context->{new} // 0)) {
if(defined $context->{old} && defined $context->{new}) {
$context->{type} = "update_profile";
} elsif(defined $context->{new}) {
$context->{type} = "start_profile";
} else {
$context->{type} = "end_profile";
}
$inserted += insert(%$context);
}
return $inserted;
}
sub insert {
my %params = @_;
return 0 unless ENABLE_EVENTS;
my $c = $params{c};
my $schema = $params{schema} // $c->model('DB');
my $type = $params{type};
my $subscriber = $params{subscriber};
#my $subscriber = $params{subscriber};
my $old = $params{old};
my $new = $params{new};
my $old_aliases = $params{old_aliases};
my $old_pilot_aliases = $params{old_pilot_aliases};
my $new_aliases = $params{new_aliases}; #to pass cleared aliases upon termination, as aliases are removed via trigger
my $new_pilot_aliases = $params{new_pilot_aliases};
my $create_event_per_alias = $params{create_event_per_alias} // CREATE_EVENT_PER_ALIAS;
my $event_alias = $params{alias};
my $now_hires = $params{now_hires} // NGCP::Panel::Utils::DateTime::current_local_hires;
#reload it usually:
$subscriber = $schema->resultset('voip_subscribers')->find({
id => (defined $subscriber ? $subscriber->id : $params{subscriber_id}),
my $subscriber = $params{subscriber} // $schema->resultset('voip_subscribers')->find({
id => $params{subscriber_id},
});
my $now_hires = NGCP::Panel::Utils::DateTime::current_local_hires;
my $customer = $subscriber->contract;
my $prov_subscriber = $subscriber->provisioning_voip_subscriber;
my $tags_rs = $schema->resultset('events_tag');
my $relations_rs = $schema->resultset('events_relation');
my $event = $schema->resultset('events')->create({
type => $type,
subscriber_id => $subscriber->id,
reseller_id => $customer->contact->reseller_id,
old_status => $old // '',
new_status => $new // '',
timestamp => $now_hires,
export_status => 'unexported',
exported_at => undef,
});
save_voip_number(
schema => $schema,
event => $event,
number => $subscriber->primary_number,
types_prefix => 'primary_number_',
now_hires => $now_hires,
tags_rs => $tags_rs,
relations_rs => $relations_rs,
);
save_subscriber_profile(
schema => $schema,
event => $event,
subscriber_profile => ($prov_subscriber ? $prov_subscriber->voip_subscriber_profile : undef),
types_prefix => 'subscriber_profile_',
now_hires => $now_hires,
tags_rs => $tags_rs,
relations_rs => $relations_rs,
);
save_subscriber_profile_set(
schema => $schema,
event => $event,
subscriber_profile_set => ($prov_subscriber ? $prov_subscriber->voip_subscriber_profile_set : undef),
types_prefix => 'subscriber_profile_set_',
now_hires => $now_hires,
tags_rs => $tags_rs,
relations_rs => $relations_rs,
);
save_first_non_primary_alias(
schema => $schema,
event => $event,
(defined $old_aliases ? (aliases => $old_aliases) : (prov_subscriber => $prov_subscriber)),
types_prefix => '',
types_suffix => '_before',
now_hires => $now_hires,
tags_rs => $tags_rs,
);
save_first_non_primary_alias(
schema => $schema,
event => $event,
(defined $new_aliases ? (aliases => $new_aliases) : (prov_subscriber => $prov_subscriber)),
types_prefix => '',
types_suffix => '_after',
now_hires => $now_hires,
tags_rs => $tags_rs,
);
my $pilot_subscriber = _get_pilot_subscriber(
my $pilot_subscriber = $params{pilot_subscriber} // _get_pilot_subscriber(
c => $c,
schema => $schema,
subscriber => $subscriber,
customer => $customer,
prov_subscriber => $prov_subscriber,
now_hires => $now_hires,
);
if ($pilot_subscriber) {
$event->create_related("relation_data", {
relation_id => $relations_rs->find({ type => 'pilot_subscriber_id' })->id,
val => $pilot_subscriber->id,
event_timestamp => $now_hires,
my $tags_rs = $schema->resultset('events_tag');
my $relations_rs = $schema->resultset('events_relation');
my @aliases = ();
if ($prov_subscriber) {
if ($create_event_per_alias) { #create events for all aliases
foreach my $alias (_get_aliases_sorted_rs($prov_subscriber)->all) {
push(@aliases,$alias->username);
}
} elsif (defined $event_alias) { #create event for a specific alias
push(@aliases,$event_alias);
}
unless ((scalar @aliases) > 0) { #create event for no alias
push(@aliases,undef);
}
}
my $inserted = 0;
foreach my $alias_username (@aliases) {
my $event = $schema->resultset('events')->create({
type => $type,
subscriber_id => $subscriber->id,
reseller_id => $customer->contact->reseller_id,
old_status => $old // '',
new_status => $new // '',
timestamp => $now_hires,
export_status => 'unexported',
exported_at => undef,
});
my $pilot_prov_subscriber = $pilot_subscriber->provisioning_voip_subscriber;
save_voip_number(
_save_voip_number(
schema => $schema,
event => $event,
number => $pilot_subscriber->primary_number,
types_prefix => 'pilot_primary_number_',
number => $subscriber->primary_number,
types_prefix => 'primary_number_',
now_hires => $now_hires,
tags_rs => $tags_rs,
relations_rs => $relations_rs,
);
save_subscriber_profile(
_save_subscriber_profile(
schema => $schema,
event => $event,
subscriber_profile => ($pilot_prov_subscriber ? $pilot_prov_subscriber->voip_subscriber_profile : undef),
types_prefix => 'pilot_subscriber_profile_',
subscriber_profile => ($prov_subscriber ? $prov_subscriber->voip_subscriber_profile : undef),
types_prefix => 'subscriber_profile_',
now_hires => $now_hires,
tags_rs => $tags_rs,
relations_rs => $relations_rs,
);
save_subscriber_profile_set(
_save_subscriber_profile_set(
schema => $schema,
event => $event,
subscriber_profile_set => ($pilot_prov_subscriber ? $pilot_prov_subscriber->voip_subscriber_profile_set : undef),
types_prefix => 'pilot_subscriber_profile_set_',
subscriber_profile_set => ($prov_subscriber ? $prov_subscriber->voip_subscriber_profile_set : undef),
types_prefix => 'subscriber_profile_set_',
now_hires => $now_hires,
tags_rs => $tags_rs,
relations_rs => $relations_rs,
);
save_first_non_primary_alias(
_save_first_non_primary_alias(
schema => $schema,
event => $event,
(defined $old_pilot_aliases ? (aliases => $old_pilot_aliases) : (prov_subscriber => $pilot_prov_subscriber)),
types_prefix => 'pilot_',
(defined $old_aliases ? (aliases => $old_aliases) : (prov_subscriber => $prov_subscriber)),
types_prefix => '',
types_suffix => '_before',
now_hires => $now_hires,
tags_rs => $tags_rs,
);
save_first_non_primary_alias(
_save_first_non_primary_alias(
schema => $schema,
event => $event,
(defined $new_pilot_aliases ? (aliases => $new_pilot_aliases) : (prov_subscriber => $pilot_prov_subscriber)),
types_prefix => 'pilot_',
(defined $new_aliases ? (aliases => $new_aliases) : (prov_subscriber => $prov_subscriber)),
types_prefix => '',
types_suffix => '_after',
now_hires => $now_hires,
tags_rs => $tags_rs,
);
}
_save_alias(
schema => $schema,
event => $event,
alias_username => $alias_username,
now_hires => $now_hires,
tags_rs => $tags_rs,
);
if ($pilot_subscriber) {
$event->create_related("relation_data", {
relation_id => $relations_rs->find({ type => 'pilot_subscriber_id' })->id,
val => $pilot_subscriber->id,
event_timestamp => $now_hires,
});
my $pilot_prov_subscriber = $pilot_subscriber->provisioning_voip_subscriber;
_save_voip_number(
schema => $schema,
event => $event,
number => $pilot_subscriber->primary_number,
types_prefix => 'pilot_primary_number_',
now_hires => $now_hires,
tags_rs => $tags_rs,
relations_rs => $relations_rs,
);
_save_subscriber_profile(
schema => $schema,
event => $event,
subscriber_profile => ($pilot_prov_subscriber ? $pilot_prov_subscriber->voip_subscriber_profile : undef),
types_prefix => 'pilot_subscriber_profile_',
now_hires => $now_hires,
tags_rs => $tags_rs,
relations_rs => $relations_rs,
);
_save_subscriber_profile_set(
schema => $schema,
event => $event,
subscriber_profile_set => ($pilot_prov_subscriber ? $pilot_prov_subscriber->voip_subscriber_profile_set : undef),
types_prefix => 'pilot_subscriber_profile_set_',
now_hires => $now_hires,
tags_rs => $tags_rs,
relations_rs => $relations_rs,
);
_save_first_non_primary_alias(
schema => $schema,
event => $event,
(defined $old_pilot_aliases ? (aliases => $old_pilot_aliases) : (prov_subscriber => $pilot_prov_subscriber)),
types_prefix => 'pilot_',
types_suffix => '_before',
now_hires => $now_hires,
tags_rs => $tags_rs,
);
_save_first_non_primary_alias(
schema => $schema,
event => $event,
(defined $new_pilot_aliases ? (aliases => $new_pilot_aliases) : (prov_subscriber => $pilot_prov_subscriber)),
types_prefix => 'pilot_',
types_suffix => '_after',
now_hires => $now_hires,
tags_rs => $tags_rs,
);
}
$inserted++;
$c->log->debug('edr event "'. $type .'" inserted: subscriber id ' . $subscriber->id . ($alias_username ? ", alias $alias_username" : ''));
}
return $inserted;
}
sub _get_pilot_subscriber {
@ -184,12 +344,12 @@ sub _get_pilot_subscriber {
/};
#now_hires
$schema //= $c->model('DB');
$now_hires //= NGCP::Panel::Utils::DateTime::current_local_hires;
#$now_hires //= NGCP::Panel::Utils::DateTime::current_local_hires;
$customer //= $subscriber->contract;
$prov_subscriber //= $subscriber->provisioning_voip_subscriber;
my $pilot_subscriber = undef;
my $bm_actual = get_actual_billing_mapping(c => $c,schema => $schema, contract => $customer, now => $now_hires);
if ($bm_actual->billing_mappings->first->product->class eq 'pbxaccount') {
#my $bm_actual = _get_actual_billing_mapping(c => $c,schema => $schema, contract => $customer, now => $now_hires);
#if ($bm_actual->billing_mappings->first->product->class eq 'pbxaccount') {
if ($prov_subscriber and $prov_subscriber->is_pbx_pilot) {
$pilot_subscriber = $subscriber;
} else {
@ -199,11 +359,11 @@ sub _get_pilot_subscriber {
join => 'provisioning_voip_subscriber',
})->first;
}
}
#}
return $pilot_subscriber;
}
sub save_voip_number {
sub _save_voip_number {
my %params = @_;
my ($schema,
$event,
@ -252,7 +412,7 @@ sub save_voip_number {
}
}
sub save_subscriber_profile {
sub _save_subscriber_profile {
my %params = @_;
my ($schema,
$event,
@ -286,7 +446,7 @@ sub save_subscriber_profile {
}
}
sub save_subscriber_profile_set {
sub _save_subscriber_profile_set {
my %params = @_;
my ($schema,
$event,
@ -320,7 +480,7 @@ sub save_subscriber_profile_set {
}
}
sub save_first_non_primary_alias {
sub _save_first_non_primary_alias {
my %params = @_;
my ($schema,
$event,
@ -359,8 +519,31 @@ sub save_first_non_primary_alias {
}
sub _save_alias {
my %params = @_;
my ($schema,
$event,
$alias_username,
$now_hires,
$tags_rs) = @params{qw/
schema
event
alias_username
now_hires
tags_rs
/};
if ($alias_username) {
$tags_rs //= $schema->resultset('events_tag');
$event->create_related("tag_data", {
tag_id => $tags_rs->find({ type => 'non_primary_alias_username' })->id,
val => $alias_username,
event_timestamp => $now_hires,
});
}
}
sub _get_aliases_sorted_rs {
my $prov_subscriber = shift;
my ($prov_subscriber) = @_;
return $prov_subscriber->voip_dbaliases->search_rs({
is_primary => 0,
},{
@ -369,44 +552,66 @@ sub _get_aliases_sorted_rs {
});
}
sub _get_aliases_map {
my ($aliases, $prov_subscriber) = @_;
my @alias_usernames = ();
my %alias_map = ();
if ('ARRAY' eq ref $aliases) {
foreach my $alias (@$aliases) {
$alias_map{$alias->{username}} = $alias;
push(@alias_usernames,$alias->{username});
}
} else {
if ($prov_subscriber) {
foreach my $alias (_get_aliases_sorted_rs($prov_subscriber)->all) {
$alias_map{$alias->username} = { $alias->get_inflated_columns };
push(@alias_usernames,$alias->username);
}
}
}
return (\@alias_usernames,\%alias_map);
}
sub get_aliases_snapshot {
my %params = @_;
my $c = $params{c};
my $schema = $params{schema} // $c->model('DB');
my @aliases = ();
my @pilot_aliases = ();
my $subscriber = $params{subscriber} // $schema->resultset('voip_subscribers')->find({
id => $params{subscriber_id},
});
my $prov_subscriber = $subscriber->provisioning_voip_subscriber;
foreach my $alias (_get_aliases_sorted_rs($prov_subscriber)->all) {
push(@aliases,{ $alias->get_inflated_columns });
}
my $pilot_subscriber = _get_pilot_subscriber(
c => $c,
schema => $schema,
subscriber => $subscriber,
prov_subscriber => $prov_subscriber,
);
if ($pilot_subscriber) {
my $pilot_prov_subscriber = $pilot_subscriber->provisioning_voip_subscriber;
foreach my $alias (_get_aliases_sorted_rs($pilot_prov_subscriber)->all) {
push(@pilot_aliases,{ $alias->get_inflated_columns });
if (ENABLE_EVENTS) {
my $subscriber = $params{subscriber} // $schema->resultset('voip_subscribers')->find({
id => $params{subscriber_id},
});
my $prov_subscriber = $subscriber->provisioning_voip_subscriber;
foreach my $alias (_get_aliases_sorted_rs($prov_subscriber)->all) {
push(@aliases,{ $alias->get_inflated_columns });
}
my $pilot_subscriber = _get_pilot_subscriber(
c => $c,
schema => $schema,
subscriber => $subscriber,
prov_subscriber => $prov_subscriber,
);
if ($pilot_subscriber) {
my $pilot_prov_subscriber = $pilot_subscriber->provisioning_voip_subscriber;
foreach my $alias (_get_aliases_sorted_rs($pilot_prov_subscriber)->all) {
push(@pilot_aliases,{ $alias->get_inflated_columns });
}
}
}
return { old_aliases => \@aliases, old_pilot_aliases => \@pilot_aliases };
}
sub get_actual_billing_mapping {
my %params = @_;
my ($c,$schema,$contract,$now) = @params{qw/c schema contract now/};
$schema //= $c->model('DB');
$now //= NGCP::Panel::Utils::DateTime::current_local;
my $contract_create = NGCP::Panel::Utils::DateTime::set_local_tz($contract->create_timestamp // $contract->modify_timestamp);
my $dtf = $schema->storage->datetime_parser;
$now = $contract_create if $now < $contract_create; #if there is no mapping starting with or before $now, it would returns the mapping with max(id):
return $schema->resultset('billing_mappings_actual')->search({ contract_id => $contract->id },{bind => [ ( $dtf->format_datetime($now) ) x 2, ($contract->id) x 2 ],})->first;
}
#sub _get_actual_billing_mapping {
# my %params = @_;
# my ($c,$schema,$contract,$now) = @params{qw/c schema contract now/};
# $schema //= $c->model('DB');
# $now //= NGCP::Panel::Utils::DateTime::current_local;
# my $contract_create = NGCP::Panel::Utils::DateTime::set_local_tz($contract->create_timestamp // $contract->modify_timestamp);
# my $dtf = $schema->storage->datetime_parser;
# $now = $contract_create if $now < $contract_create; #if there is no mapping starting with or before $now, it would returns the mapping with max(id):
# return $schema->resultset('billing_mappings_actual')->search({ contract_id => $contract->id },{bind => [ ( $dtf->format_datetime($now) ) x 2, ($contract->id) x 2 ],})->first;
#}
sub get_relation_value {
my %params = @_;

@ -359,22 +359,22 @@ sub create_subscriber {
NGCP::Panel::Utils::Email::new_subscriber($c, $billing_subscriber, $url);
}
if($prov_subscriber->profile_id) {
#if($prov_subscriber->profile_id) {
my $events_to_create = $event_context->{events_to_create};
if (defined $events_to_create) {
push(@$events_to_create,{
subscriber_id => $billing_subscriber->id,
type => 'start_profile', old => undef, new => $prov_subscriber->profile_id,
type => 'profile', old => undef, new => $prov_subscriber->profile_id,
%$aliases_before,
});
} else {
NGCP::Panel::Utils::Events::insert(
c => $c, schema => $schema, subscriber => $billing_subscriber,
type => 'start_profile', old => undef, new => $prov_subscriber->profile_id,
NGCP::Panel::Utils::Events::insert_profile_events(
c => $c, schema => $schema, subscriber_id => $billing_subscriber->id,
old => undef, new => $prov_subscriber->profile_id,
%$aliases_before,
);
}
}
#}
if($prov_subscriber->is_pbx_group) {
my $events_to_create = $event_context->{events_to_create};
if (defined $events_to_create) {
@ -385,7 +385,7 @@ sub create_subscriber {
});
} else {
NGCP::Panel::Utils::Events::insert(
c => $c, schema => $schema, subscriber => $billing_subscriber,
c => $c, schema => $schema, subscriber_id => $billing_subscriber->id,
type => 'start_huntgroup', old => undef, new => $prov_subscriber->profile_id,
%$aliases_before,
);
@ -1065,24 +1065,24 @@ sub terminate {
}
}
}
}
if($prov_subscriber && $prov_subscriber->is_pbx_group) {
$schema->resultset('voip_pbx_groups')->search({
group_id => $subscriber->provisioning_voip_subscriber->id,
})->delete;
push(@events_to_create,{
type => 'end_huntgroup',
subscriber_id => $subscriber->id,
if($prov_subscriber->is_pbx_group) {
$schema->resultset('voip_pbx_groups')->search({
group_id => $subscriber->provisioning_voip_subscriber->id,
})->delete;
push(@events_to_create,{
type => 'end_huntgroup',
subscriber_id => $subscriber->id,
old => $prov_subscriber->profile_id, new => undef,
%$aliases_before,%$aliases_after,
});
}
#if($prov_subscriber->profile_id) {
push(@events_to_create,{
subscriber_id => $subscriber->id, type => 'profile',
old => $prov_subscriber->profile_id, new => undef,
%$aliases_before,%$aliases_after,
});
}
if($prov_subscriber && $prov_subscriber->profile_id) {
push(@events_to_create,{
subscriber_id => $subscriber->id, type => 'stop_profile',
old => $prov_subscriber->profile_id, new => undef,
%$aliases_before,%$aliases_after,
});
#}
}
if($prov_subscriber && !$prov_subscriber->is_pbx_pilot) {
my $pilot_rs = $schema->resultset('voip_subscribers')->search({
@ -1142,8 +1142,7 @@ sub terminate {
}
}
NGCP::Panel::Utils::Events::insert_deferred(
c => $c,
schema => $schema,
c => $c, schema => $schema,
events_to_create => \@events_to_create,
);
#ready for number change events here
@ -1470,18 +1469,21 @@ sub apply_rewrite {
sub check_cf_ivr {
my (%params) = @_;
my $c = $params{c};
my $schema = $params{schema} // $c->model('DB');;
my $subscriber = $params{subscriber};
my $schema = $params{schema};
my $new_aa = $params{new_aa}; # boolean, false on delete
my $old_aa = $params{old_aa}; # boolean, false on create
if ($old_aa && !$new_aa) {
NGCP::Panel::Utils::Events::insert(
schema => $schema, subscriber => $subscriber,
c => $c, schema => $schema,
subscriber_id => $subscriber->id,
type => 'end_ivr',
);
} elsif (!$old_aa && $new_aa) {
NGCP::Panel::Utils::Events::insert(
schema => $schema, subscriber => $subscriber,
c => $c, schema => $schema,
subscriber_id => $subscriber->id,
type => 'start_ivr',
);
}

@ -89,6 +89,20 @@ $res = $ua->request($req);
is($res->code, 200, "fetch POSTed test subscriberprofileset 2");
my $subscriberprofile2set = JSON::from_json($res->decoded_content);
$req = HTTP::Request->new('POST', $uri.'/api/subscriberprofilesets/');
$req->header('Content-Type' => 'application/json');
$req->content(JSON::to_json({
name => "subscriber_profile_3_set_".$t,
reseller_id => $reseller_id,
description => "subscriber_profile_3_set_description_".$t,
}));
$res = $ua->request($req);
is($res->code, 201, "POST test subscriberprofileset 3");
$req = HTTP::Request->new('GET', $uri.'/'.$res->header('Location'));
$res = $ua->request($req);
is($res->code, 200, "fetch POSTed test subscriberprofileset 3");
my $subscriberprofile3set = JSON::from_json($res->decoded_content);
$req = HTTP::Request->new('GET', $uri.'/api/subscriberpreferencedefs/');
$res = $ua->request($req);
is($res->code, 200, "fetch profilepreferencedefs");
@ -129,7 +143,20 @@ $res = $ua->request($req);
is($res->code, 200, "fetch POSTed test subscriberprofile 2");
my $subscriberprofile2 = JSON::from_json($res->decoded_content);
$req = HTTP::Request->new('POST', $uri.'/api/subscriberprofiles/');
$req->header('Content-Type' => 'application/json');
$req->content(JSON::to_json({
name => "subscriber_profile_3_".$t,
profile_set_id => $subscriberprofile3set->{id},
attributes => \@subscriber_profile_attributes,
description => "subscriber_profile_3_description_".$t,
}));
$res = $ua->request($req);
is($res->code, 201, "POST test subscriberprofile 3");
$req = HTTP::Request->new('GET', $uri.'/'.$res->header('Location'));
$res = $ua->request($req);
is($res->code, 200, "fetch POSTed test subscriberprofile 3");
my $subscriberprofile3 = JSON::from_json($res->decoded_content);
$req = HTTP::Request->new('POST', $uri.'/api/customercontacts/');
$req->header('Content-Type' => 'application/json');
@ -154,9 +181,12 @@ my %customer_map = ();
my $customer = _create_customer(
type => "sipaccount",
);
my $cc = 800;
my $ac = '1'.(scalar keys %subscriber_map);
my $sn = $t;
my $subscriber = _create_subscriber($customer,
primary_number => { cc => 888, ac => '1'.(scalar keys %subscriber_map), sn => $t },
);
primary_number => { cc => $cc, ac => $ac, sn => $sn },
);
my $call_forwards = set_callforwards($subscriber,{ cfu => {
destinations => [
@ -175,6 +205,42 @@ my %customer_map = ();
]);
}
#SKIP:
{ #end_ivr:
my $customer = _create_customer(
type => "sipaccount",
);
my $cc = 800;
my $ac = '1'.(scalar keys %subscriber_map);
my $sn = $t;
my $aliases = [
{ cc => $cc, ac => $ac, sn => $sn.'0001' },
{ cc => $cc, ac => $ac, sn => $sn.'0002' },
];
my $subscriber = _create_subscriber($customer,
primary_number => { cc => $cc, ac => $ac, sn => $sn },
alias_numbers => $aliases,
);
my $call_forwards = set_callforwards($subscriber,{ cfu => {
destinations => [
{ destination => "5678" },
{ destination => "autoattendant", },
],
}});
$call_forwards = set_callforwards($subscriber,{ cfu => {
destinations => [
{ destination => "5678" },
],
}});
_check_event_history("multiple alaises - events generated using /api/callforwards: ",$subscriber->{id},"%ivr",[
{ subscriber_id => $subscriber->{id}, type => "start_ivr", non_primary_alias_username => $aliases->[0]->{cc}.$aliases->[0]->{ac}.$aliases->[0]->{sn} },
{ subscriber_id => $subscriber->{id}, type => "start_ivr", non_primary_alias_username => $aliases->[1]->{cc}.$aliases->[1]->{ac}.$aliases->[1]->{sn} },
{ subscriber_id => $subscriber->{id}, type => "end_ivr", non_primary_alias_username => $aliases->[0]->{cc}.$aliases->[0]->{ac}.$aliases->[0]->{sn} },
{ subscriber_id => $subscriber->{id}, type => "end_ivr", non_primary_alias_username => $aliases->[1]->{cc}.$aliases->[1]->{ac}.$aliases->[1]->{sn} },
]);
}
#$t = time;
#SKIP:
@ -183,8 +249,20 @@ my %customer_map = ();
my $customer = _create_customer(
type => "sipaccount",
);
my $cc = 800;
my $ac = '2'.(scalar keys %subscriber_map);
my $sn = $t;
my $aliases = [
{ cc => $cc, ac => $ac, sn => $sn.'0001' },
{ cc => $cc, ac => $ac, sn => $sn.'0002' },
];
my $subscriber = _create_subscriber($customer,
primary_number => { cc => $cc, ac => $ac, sn => $sn },
alias_numbers => $aliases,
);
my $subscriber = _create_subscriber($customer,
primary_number => { cc => 888, ac => '2'.(scalar keys %subscriber_map), sn => $t },
alias_numbers => $aliases,
);
my $destinationset_1 = _create_cfdestinationset($subscriber,"dest1_$t",[{ destination => "1234",
@ -233,29 +311,45 @@ my %customer_map = ();
priority => '1',
simple_destination => undef },
]);
_check_event_history("events generated by updating /api/cfdestinationsets: ",$subscriber->{id},"%ivr",[
{ subscriber_id => $subscriber->{id}, type => "start_ivr" },
{ subscriber_id => $subscriber->{id}, type => "start_ivr" },
{ subscriber_id => $subscriber->{id}, type => "end_ivr" },
_check_event_history("multiple alaises - events generated by updating /api/cfdestinationsets: ",$subscriber->{id},"%ivr",[
{ subscriber_id => $subscriber->{id}, type => "start_ivr", non_primary_alias_username => $aliases->[0]->{cc}.$aliases->[0]->{ac}.$aliases->[0]->{sn} },
{ subscriber_id => $subscriber->{id}, type => "start_ivr", non_primary_alias_username => $aliases->[1]->{cc}.$aliases->[1]->{ac}.$aliases->[1]->{sn} },
{ subscriber_id => $subscriber->{id}, type => "start_ivr", non_primary_alias_username => $aliases->[0]->{cc}.$aliases->[0]->{ac}.$aliases->[0]->{sn} },
{ subscriber_id => $subscriber->{id}, type => "start_ivr", non_primary_alias_username => $aliases->[1]->{cc}.$aliases->[1]->{ac}.$aliases->[1]->{sn} },
{ subscriber_id => $subscriber->{id}, type => "end_ivr", non_primary_alias_username => $aliases->[0]->{cc}.$aliases->[0]->{ac}.$aliases->[0]->{sn} },
{ subscriber_id => $subscriber->{id}, type => "end_ivr", non_primary_alias_username => $aliases->[1]->{cc}.$aliases->[1]->{ac}.$aliases->[1]->{sn} },
]);
#2. update cfmappings:
$mappings = _update_cfmapping($subscriber,"cfu",[]);
_check_event_history("events generated by updating /api/cfmappings: ",$subscriber->{id},"%ivr",[
{ subscriber_id => $subscriber->{id}, type => "start_ivr" },
{ subscriber_id => $subscriber->{id}, type => "start_ivr" },
{ subscriber_id => $subscriber->{id}, type => "end_ivr" },
{ subscriber_id => $subscriber->{id}, type => "end_ivr" },
_check_event_history("multiple alaises - events generated by updating /api/cfmappings: ",$subscriber->{id},"%ivr",[
{ subscriber_id => $subscriber->{id}, type => "start_ivr", non_primary_alias_username => $aliases->[0]->{cc}.$aliases->[0]->{ac}.$aliases->[0]->{sn} },
{ subscriber_id => $subscriber->{id}, type => "start_ivr", non_primary_alias_username => $aliases->[1]->{cc}.$aliases->[1]->{ac}.$aliases->[1]->{sn} },
{ subscriber_id => $subscriber->{id}, type => "start_ivr", non_primary_alias_username => $aliases->[0]->{cc}.$aliases->[0]->{ac}.$aliases->[0]->{sn} },
{ subscriber_id => $subscriber->{id}, type => "start_ivr", non_primary_alias_username => $aliases->[1]->{cc}.$aliases->[1]->{ac}.$aliases->[1]->{sn} },
{ subscriber_id => $subscriber->{id}, type => "end_ivr", non_primary_alias_username => $aliases->[0]->{cc}.$aliases->[0]->{ac}.$aliases->[0]->{sn} },
{ subscriber_id => $subscriber->{id}, type => "end_ivr", non_primary_alias_username => $aliases->[1]->{cc}.$aliases->[1]->{ac}.$aliases->[1]->{sn} },
{ subscriber_id => $subscriber->{id}, type => "end_ivr", non_primary_alias_username => $aliases->[0]->{cc}.$aliases->[0]->{ac}.$aliases->[0]->{sn} },
{ subscriber_id => $subscriber->{id}, type => "end_ivr", non_primary_alias_username => $aliases->[1]->{cc}.$aliases->[1]->{ac}.$aliases->[1]->{sn} },
]);
}
#SKIP:
{ #end_ivr:
my $customer = _create_customer(
type => "sipaccount",
);
my $cc = 800;
my $ac = '3'.(scalar keys %subscriber_map);
my $sn = $t;
my $aliases = [
{ cc => $cc, ac => $ac, sn => $sn.'0001' },
{ cc => $cc, ac => $ac, sn => $sn.'0002' },
];
my $subscriber = _create_subscriber($customer,
primary_number => { cc => 888, ac => '3'.(scalar keys %subscriber_map), sn => $t },
);
primary_number => { cc => $cc, ac => $ac, sn => $sn },
alias_numbers => $aliases,
);
my $call_forwards = set_callforwards($subscriber,{ cfu => {
destinations => [
@ -264,9 +358,11 @@ my %customer_map = ();
],
}});
_update_subscriber($subscriber, status => 'terminated');
_check_event_history("events generated when terminating the subscriber: ",$subscriber->{id},"%ivr",[
{ subscriber_id => $subscriber->{id}, type => "start_ivr" },
{ subscriber_id => $subscriber->{id}, type => "end_ivr" },
_check_event_history("multiple alaises - events generated when terminating the subscriber: ",$subscriber->{id},"%ivr",[
{ subscriber_id => $subscriber->{id}, type => "start_ivr", non_primary_alias_username => $aliases->[0]->{cc}.$aliases->[0]->{ac}.$aliases->[0]->{sn} },
{ subscriber_id => $subscriber->{id}, type => "start_ivr", non_primary_alias_username => $aliases->[1]->{cc}.$aliases->[1]->{ac}.$aliases->[1]->{sn} },
{ subscriber_id => $subscriber->{id}, type => "end_ivr", non_primary_alias_username => $aliases->[0]->{cc}.$aliases->[0]->{ac}.$aliases->[0]->{sn} },
{ subscriber_id => $subscriber->{id}, type => "end_ivr", non_primary_alias_username => $aliases->[1]->{cc}.$aliases->[1]->{ac}.$aliases->[1]->{sn} },
]);
}
@ -346,6 +442,7 @@ my %customer_map = ();
my $aliases = [
{ cc => $cc, ac => $ac, sn => $sn.'0003' },
{ cc => $cc, ac => $ac, sn => $sn.'0004' },
#{ cc => $cc, ac => $ac, sn => $sn.'0006' },
];
my $subscriber = _create_subscriber($customer,
pbx_extension => $ext,
@ -354,8 +451,8 @@ my %customer_map = ();
profile_set_id => $subscriberprofile1set->{id},
);
#_update_subscriber($subscriber,
_check_event_history("start_profile when creating a pbx pilot subscriber w alias: ",$pilot_subscriber->{id},"start_profile",[
{ subscriber_id => $pilot_subscriber->{id}, type => "start_profile",
my %pilot_event = (
subscriber_id => $pilot_subscriber->{id},
subscriber_profile_id => $subscriberprofile1->{id}, subscriber_profile_name => $subscriberprofile1->{name},
subscriber_profile_set_id => $subscriberprofile1set->{id}, subscriber_profile_set_name => $subscriberprofile1set->{name},
primary_number_cc => $cc, primary_number_ac => $ac, primary_number_sn => $sn,
@ -368,10 +465,33 @@ my %customer_map = ();
first_non_primary_alias_username_after => $pilot_aliases->[0]->{cc}.$pilot_aliases->[0]->{ac}.$pilot_aliases->[0]->{sn},
pilot_first_non_primary_alias_username_before => undef,
pilot_first_non_primary_alias_username_after => $pilot_aliases->[0]->{cc}.$pilot_aliases->[0]->{ac}.$pilot_aliases->[0]->{sn},
);
_check_event_history("start_profile when creating a pbx pilot subscriber w alias: ",$pilot_subscriber->{id},"%profile",[
{ %pilot_event,
type => "start_profile",
old_status => '',
new_status => $subscriberprofile1->{id},
non_primary_alias_username => $pilot_aliases->[0]->{cc}.$pilot_aliases->[0]->{ac}.$pilot_aliases->[0]->{sn},
},
{ %pilot_event,
type => "start_profile",
old_status => '',
new_status => $subscriberprofile1->{id},
non_primary_alias_username => $pilot_aliases->[1]->{cc}.$pilot_aliases->[1]->{ac}.$pilot_aliases->[1]->{sn},
},
#{ %pilot_event,
# type => "start_profile",
# non_primary_alias_username => $pilot_aliases->[2]->{cc}.$pilot_aliases->[2]->{ac}.$pilot_aliases->[2]->{sn},
#},
]);
_check_event_history("start_profile when creating a pbx extension subscriber w alias: ",$subscriber->{id},"start_profile",[
{ subscriber_id => $subscriber->{id}, type => "start_profile",
my %subscriber_event = (
subscriber_id => $subscriber->{id},
subscriber_profile_id => $subscriberprofile1->{id}, subscriber_profile_name => $subscriberprofile1->{name},
subscriber_profile_set_id => $subscriberprofile1set->{id}, subscriber_profile_set_name => $subscriberprofile1set->{name},
primary_number_cc => $cc, primary_number_ac => $ac, primary_number_sn => $sn.$ext,
@ -384,20 +504,38 @@ my %customer_map = ();
first_non_primary_alias_username_after => $aliases->[0]->{cc}.$aliases->[0]->{ac}.$aliases->[0]->{sn},
pilot_first_non_primary_alias_username_before => $pilot_aliases->[0]->{cc}.$pilot_aliases->[0]->{ac}.$pilot_aliases->[0]->{sn},
pilot_first_non_primary_alias_username_after => $pilot_aliases->[0]->{cc}.$pilot_aliases->[0]->{ac}.$pilot_aliases->[0]->{sn},
);
_check_event_history("start_profile when creating a pbx extension subscriber w alias: ",$subscriber->{id},"%profile",[
{ %subscriber_event,
type => "start_profile",
old_status => '',
new_status => $subscriberprofile1->{id},
non_primary_alias_username => $aliases->[0]->{cc}.$aliases->[0]->{ac}.$aliases->[0]->{sn},
},
{ %subscriber_event,
type => "start_profile",
old_status => '',
new_status => $subscriberprofile1->{id},
non_primary_alias_username => $aliases->[1]->{cc}.$aliases->[1]->{ac}.$aliases->[1]->{sn},
},
]);
my $new_aliases = [
{ cc => $cc, ac => $ac, sn => $sn.'0004' },
{ cc => $cc, ac => $ac, sn => $sn.'0005' },
{ cc => $cc, ac => $ac, sn => $sn.'0006' },
];
_update_subscriber($subscriber,
alias_numbers => $new_aliases,
profile_id => $subscriberprofile2->{id},
profile_set_id => $subscriberprofile2set->{id},
);
_check_event_history("update_profile when updating a pbx extension subscriber w alias: ",$subscriber->{id},"update_profile",[
{ subscriber_id => $subscriber->{id}, type => "update_profile",
%subscriber_event = (
subscriber_id => $subscriber->{id},
subscriber_profile_id => $subscriberprofile2->{id}, subscriber_profile_name => $subscriberprofile2->{name},
subscriber_profile_set_id => $subscriberprofile2set->{id}, subscriber_profile_set_name => $subscriberprofile2set->{name},
primary_number_cc => $cc, primary_number_ac => $ac, primary_number_sn => $sn.$ext,
@ -410,75 +548,203 @@ my %customer_map = ();
first_non_primary_alias_username_after => $new_aliases->[0]->{cc}.$new_aliases->[0]->{ac}.$new_aliases->[0]->{sn},
pilot_first_non_primary_alias_username_before => $pilot_aliases->[0]->{cc}.$pilot_aliases->[0]->{ac}.$pilot_aliases->[0]->{sn},
pilot_first_non_primary_alias_username_after => $pilot_aliases->[0]->{cc}.$pilot_aliases->[0]->{ac}.$pilot_aliases->[0]->{sn},
);
_check_event_history("start/update/end_profile when updating a pbx extension subscriber w alias: ",$subscriber->{id},"%profile",[
{},{},
{ %subscriber_event,
type => "update_profile",
old_status => $subscriberprofile1->{id},
new_status => $subscriberprofile2->{id},
non_primary_alias_username => $aliases->[1]->{cc}.$aliases->[1]->{ac}.$aliases->[1]->{sn},
},
{ %subscriber_event,
type => "start_profile",
old_status => '',
new_status => $subscriberprofile2->{id},
non_primary_alias_username => $new_aliases->[1]->{cc}.$new_aliases->[1]->{ac}.$new_aliases->[1]->{sn},
},
{ %subscriber_event,
type => "end_profile",
old_status => $subscriberprofile1->{id},
new_status => '',
non_primary_alias_username => $aliases->[0]->{cc}.$aliases->[0]->{ac}.$aliases->[0]->{sn},
},
]);
my $new_pilot_aliases = [
{ cc => $cc, ac => $ac, sn => $sn.'0002' },
{ cc => $cc, ac => $ac, sn => $sn.'0003' },
{ cc => $cc, ac => $ac, sn => $sn.'0004' },
];
_update_subscriber($pilot_subscriber,
alias_numbers => $new_pilot_aliases,
profile_id => $subscriberprofile2->{id},
profile_set_id => $subscriberprofile2set->{id},
profile_id => $subscriberprofile3->{id},
profile_set_id => $subscriberprofile3set->{id},
);
_check_event_history("update_profile when updating a pbx pilot subscriber w alias: ",$pilot_subscriber->{id},"update_profile",[
{ subscriber_id => $pilot_subscriber->{id}, type => "update_profile",
subscriber_profile_id => $subscriberprofile2->{id}, subscriber_profile_name => $subscriberprofile2->{name},
subscriber_profile_set_id => $subscriberprofile2set->{id}, subscriber_profile_set_name => $subscriberprofile2set->{name},
my %pilot_event = (
subscriber_id => $pilot_subscriber->{id},
subscriber_profile_id => $subscriberprofile3->{id}, subscriber_profile_name => $subscriberprofile3->{name},
subscriber_profile_set_id => $subscriberprofile3set->{id}, subscriber_profile_set_name => $subscriberprofile3set->{name},
primary_number_cc => $cc, primary_number_ac => $ac, primary_number_sn => $sn,
pilot_subscriber_id => $pilot_subscriber->{id},
pilot_subscriber_profile_id => $subscriberprofile2->{id}, pilot_subscriber_profile_name => $subscriberprofile2->{name},
pilot_subscriber_profile_set_id => $subscriberprofile2set->{id}, pilot_subscriber_profile_set_name => $subscriberprofile2set->{name},
pilot_subscriber_profile_id => $subscriberprofile3->{id}, pilot_subscriber_profile_name => $subscriberprofile3->{name},
pilot_subscriber_profile_set_id => $subscriberprofile3set->{id}, pilot_subscriber_profile_set_name => $subscriberprofile3set->{name},
pilot_primary_number_cc => $cc, pilot_primary_number_ac => $ac, pilot_primary_number_sn => $sn,
first_non_primary_alias_username_before => $pilot_aliases->[0]->{cc}.$pilot_aliases->[0]->{ac}.$pilot_aliases->[0]->{sn},
first_non_primary_alias_username_after => $new_pilot_aliases->[0]->{cc}.$new_pilot_aliases->[0]->{ac}.$new_pilot_aliases->[0]->{sn},
pilot_first_non_primary_alias_username_before => $pilot_aliases->[0]->{cc}.$pilot_aliases->[0]->{ac}.$pilot_aliases->[0]->{sn},
pilot_first_non_primary_alias_username_after => $new_pilot_aliases->[0]->{cc}.$new_pilot_aliases->[0]->{ac}.$new_pilot_aliases->[0]->{sn},
);
_check_event_history("start/update/end_profile when updating a pbx pilot subscriber w alias: ",$pilot_subscriber->{id},"%profile",[
{},{},
{ %pilot_event,
type => "update_profile",
old_status => $subscriberprofile1->{id},
new_status => $subscriberprofile3->{id},
non_primary_alias_username => $pilot_aliases->[1]->{cc}.$pilot_aliases->[1]->{ac}.$pilot_aliases->[1]->{sn},
},
{ %pilot_event,
type => "start_profile",
old_status => '',
new_status => $subscriberprofile3->{id},
non_primary_alias_username => $new_pilot_aliases->[1]->{cc}.$new_pilot_aliases->[1]->{ac}.$new_pilot_aliases->[1]->{sn},
},
{ %pilot_event,
type => "end_profile",
old_status => $subscriberprofile1->{id},
new_status => '',
non_primary_alias_username => $pilot_aliases->[0]->{cc}.$pilot_aliases->[0]->{ac}.$pilot_aliases->[0]->{sn},
},
]);
_update_subscriber($subscriber, status => 'terminated');
_check_event_history("stop_profile when terminating a pbx extension subscriber w alias: ",$subscriber->{id},"stop_profile",[
{ subscriber_id => $subscriber->{id}, type => "stop_profile",
%subscriber_event = (
subscriber_id => $subscriber->{id},
subscriber_profile_id => $subscriberprofile2->{id}, subscriber_profile_name => $subscriberprofile2->{name},
subscriber_profile_set_id => $subscriberprofile2set->{id}, subscriber_profile_set_name => $subscriberprofile2set->{name},
primary_number_cc => $cc, primary_number_ac => $ac, primary_number_sn => $sn.$ext,
pilot_subscriber_id => $pilot_subscriber->{id},
pilot_subscriber_profile_id => $subscriberprofile2->{id}, pilot_subscriber_profile_name => $subscriberprofile2->{name},
pilot_subscriber_profile_set_id => $subscriberprofile2set->{id}, pilot_subscriber_profile_set_name => $subscriberprofile2set->{name},
pilot_subscriber_profile_id => $subscriberprofile3->{id}, pilot_subscriber_profile_name => $subscriberprofile3->{name},
pilot_subscriber_profile_set_id => $subscriberprofile3set->{id}, pilot_subscriber_profile_set_name => $subscriberprofile3set->{name},
pilot_primary_number_cc => $cc, pilot_primary_number_ac => $ac, pilot_primary_number_sn => $sn,
first_non_primary_alias_username_before => $new_aliases->[0]->{cc}.$new_aliases->[0]->{ac}.$new_aliases->[0]->{sn},
first_non_primary_alias_username_after => undef,
pilot_first_non_primary_alias_username_before => $new_pilot_aliases->[0]->{cc}.$new_pilot_aliases->[0]->{ac}.$new_pilot_aliases->[0]->{sn},
#would be this:
#pilot_first_non_primary_alias_username_after => $new_pilot_aliases->[0]->{cc}.$new_pilot_aliases->[0]->{ac}.$new_pilot_aliases->[0]->{sn},
pilot_first_non_primary_alias_username_after => $new_pilot_aliases->[0]->{cc}.$new_pilot_aliases->[0]->{ac}.$new_pilot_aliases->[0]->{sn},
#but since api termination always returns aliases to the pilot:
pilot_first_non_primary_alias_username_after => $new_aliases->[0]->{cc}.$new_aliases->[0]->{ac}.$new_aliases->[0]->{sn},
#pilot_first_non_primary_alias_username_after => $new_aliases->[0]->{cc}.$new_aliases->[0]->{ac}.$new_aliases->[0]->{sn},
#pilot_first_non_primary_alias_username_after => $new_aliases->[0]->{cc}.$new_aliases->[0]->{ac}.$new_aliases->[0]->{sn},
),
_check_event_history("end_profile when terminating a pbx extension subscriber w alias: ",$subscriber->{id},"%profile",[
{},{},{},{},{},
{ %subscriber_event,
type => "update_profile",
old_status => $subscriberprofile2->{id},
new_status => $subscriberprofile3->{id},
non_primary_alias_username => $new_aliases->[0]->{cc}.$new_aliases->[0]->{ac}.$new_aliases->[0]->{sn},
},
{ %subscriber_event,
type => "update_profile",
old_status => $subscriberprofile2->{id},
new_status => $subscriberprofile3->{id},
non_primary_alias_username => $new_aliases->[1]->{cc}.$new_aliases->[1]->{ac}.$new_aliases->[1]->{sn},
},
]);
_update_subscriber($pilot_subscriber, status => 'terminated');
_check_event_history("stop_profile when terminating a pbx pilot subscriber w alias: ",$pilot_subscriber->{id},"stop_profile",[
{ subscriber_id => $pilot_subscriber->{id}, type => "stop_profile",
subscriber_profile_id => $subscriberprofile2->{id}, subscriber_profile_name => $subscriberprofile2->{name},
subscriber_profile_set_id => $subscriberprofile2set->{id}, subscriber_profile_set_name => $subscriberprofile2set->{name},
my %pilot_event = (
subscriber_id => $pilot_subscriber->{id},
subscriber_profile_id => $subscriberprofile3->{id}, subscriber_profile_name => $subscriberprofile3->{name},
subscriber_profile_set_id => $subscriberprofile3set->{id}, subscriber_profile_set_name => $subscriberprofile3set->{name},
primary_number_cc => $cc, primary_number_ac => $ac, primary_number_sn => $sn,
pilot_subscriber_id => $pilot_subscriber->{id},
pilot_subscriber_profile_id => $subscriberprofile2->{id}, pilot_subscriber_profile_name => $subscriberprofile2->{name},
pilot_subscriber_profile_set_id => $subscriberprofile2set->{id}, pilot_subscriber_profile_set_name => $subscriberprofile2set->{name},
pilot_subscriber_profile_id => $subscriberprofile3->{id}, pilot_subscriber_profile_name => $subscriberprofile3->{name},
pilot_subscriber_profile_set_id => $subscriberprofile3set->{id}, pilot_subscriber_profile_set_name => $subscriberprofile3set->{name},
pilot_primary_number_cc => $cc, pilot_primary_number_ac => $ac, pilot_primary_number_sn => $sn,
#would be this:
#$new_pilot_aliases->[0]->{cc}.$new_pilot_aliases->[0]->{ac}.$new_pilot_aliases->[0]->{sn},
#but since api termination always returns aliases to the pilot:
first_non_primary_alias_username_before => $new_aliases->[0]->{cc}.$new_aliases->[0]->{ac}.$new_aliases->[0]->{sn},
#first_non_primary_alias_username_before => $new_aliases->[0]->{cc}.$new_aliases->[0]->{ac}.$new_aliases->[0]->{sn},
pilot_first_non_primary_alias_username_after => $new_pilot_aliases->[0]->{cc}.$new_pilot_aliases->[0]->{ac}.$new_pilot_aliases->[0]->{sn},
first_non_primary_alias_username_after => undef,
pilot_first_non_primary_alias_username_before => $new_aliases->[0]->{cc}.$new_aliases->[0]->{ac}.$new_aliases->[0]->{sn},
#pilot_first_non_primary_alias_username_before => $new_aliases->[0]->{cc}.$new_aliases->[0]->{ac}.$new_aliases->[0]->{sn},
pilot_first_non_primary_alias_username_after => $new_pilot_aliases->[0]->{cc}.$new_pilot_aliases->[0]->{ac}.$new_pilot_aliases->[0]->{sn},
pilot_first_non_primary_alias_username_after => undef,
);
_check_event_history("end_profile when terminating a pbx pilot subscriber w alias: ",$pilot_subscriber->{id},"%profile",[
{},{},{},{},{},
#aliases ordered by id, so by the order they were created:
#id=2:0002
#id=6:0003
#--
#id=4:0004
#id=5:0005
#-->
#id=2:0002
#id=4:0004
#id=5:0005
#id=6:0003
{ %pilot_event,
type => "end_profile",
old_status => $subscriberprofile3->{id},
new_status => '',
non_primary_alias_username => $new_pilot_aliases->[0]->{cc}.$new_pilot_aliases->[0]->{ac}.$new_pilot_aliases->[0]->{sn},
},
{ %pilot_event,
type => "end_profile",
old_status => $subscriberprofile3->{id},
new_status => '',
non_primary_alias_username => $new_aliases->[0]->{cc}.$new_aliases->[0]->{ac}.$new_aliases->[0]->{sn},
},
{ %pilot_event,
type => "end_profile",
old_status => $subscriberprofile3->{id},
new_status => '',
non_primary_alias_username => $new_aliases->[1]->{cc}.$new_aliases->[1]->{ac}.$new_aliases->[1]->{sn},
},
{ %pilot_event,
type => "end_profile",
old_status => $subscriberprofile3->{id},
new_status => '',
non_primary_alias_username => $new_pilot_aliases->[1]->{cc}.$new_pilot_aliases->[1]->{ac}.$new_pilot_aliases->[1]->{sn},
},
]);
}

Loading…
Cancel
Save