MT#5929 More external_id fixes.

Set external_id to NULL in db if it's empty.
Properly clear ext_xxx_id preferences if external_id gets unset.
agranig/dummydel
Andreas Granig 11 years ago
parent 4456bd02e4
commit 432080d384

@ -281,6 +281,7 @@ sub peering_create :Chained('peering_list') :PathPart('create') :Args(0) {
delete $form->params->{contract};
my $bprof_id = $form->params->{billing_profile}{id};
delete $form->params->{billing_profile};
$form->params->{external_id} = $form->field('external_id')->value;
$form->{create_timestamp} = $form->{modify_timestamp} = NGCP::Panel::Utils::DateTime::current_local;
my $contract = $schema->resultset('contracts')->create($form->params);
my $billing_profile = $schema->resultset('billing_profiles')->find($bprof_id);
@ -406,6 +407,7 @@ sub reseller_create :Chained('reseller_list') :PathPart('create') :Args(0) {
delete $form->params->{contract};
my $bprof_id = $form->params->{billing_profile}{id};
delete $form->params->{billing_profile};
$form->params->{external_id} = $form->field('external_id')->value;
$form->{create_timestamp} = $form->{modify_timestamp} = NGCP::Panel::Utils::DateTime::current_local;
my $contract = $schema->resultset('contracts')->create($form->params);
my $billing_profile = $schema->resultset('billing_profiles')->find($bprof_id);

@ -157,6 +157,7 @@ sub create :Chained('list_customer') :PathPart('create') :Args(0) {
my $bprof_id = $form->params->{billing_profile}{id};
delete $form->params->{billing_profile};
$form->{create_timestamp} = $form->{modify_timestamp} = NGCP::Panel::Utils::DateTime::current_local;
$form->params->{external_id} = $form->field('external_id')->value;
my $product_id = $form->params->{product}{id};
delete $form->params->{product};
unless($product_id) {
@ -361,16 +362,18 @@ sub edit :Chained('base') :PathPart('edit') :Args(0) {
$form->{modify_timestamp} = NGCP::Panel::Utils::DateTime::current_local;
my $product_id = $form->params->{product}{id} || $billing_mapping->product_id;
delete $form->params->{product};
$form->params->{external_id} = $form->field('external_id')->value;
unless($form->params->{max_subscribers} && length($form->params->{max_subscribers})) {
$form->params->{max_subscribers} = undef;
}
my $old_bprof_id = $billing_mapping->billing_profile_id;
$c->log->debug(">>>>>>>>>>> old bprof_id=$old_bprof_id");
my $old_prepaid = $billing_mapping->billing_profile->prepaid;
my $old_ext_id = $contract->external_id;
my $old_ext_id = $contract->external_id // '';
$contract->update($form->params);
my $new_ext_id = $contract->external_id // '';
if($contract->external_id ne $old_ext_id) {
if($old_ext_id ne $new_ext_id) { # undef is '' so we don't bail out here
foreach my $sub($contract->voip_subscribers->all) {
my $prov_sub = $sub->provisioning_voip_subscriber;
next unless($prov_sub);

@ -167,6 +167,7 @@ sub create_list :Chained('sub_list') :PathPart('create') :Args(0) :Does(ACL) :AC
username => $c->request->params->{username},
domain_id => $billing_domain->id,
status => $c->request->params->{status},
external_id => $form->field('external_id')->value, # null if empty
});
my $prov_subscriber = $schema->resultset('provisioning_voip_subscribers')->create({
@ -1965,10 +1966,12 @@ sub edit_master :Chained('master') :PathPart('edit') :Args(0) :Does(ACL) :ACLDet
domain => $subscriber->domain->domain,
) if($pbx_ext && defined $old_group_id && $old_group_id != $prov_subscriber->pbx_group_id);
my $old_ext_id = $subscriber->external_id;
$subscriber->update({
status => $form->params->{status},
external_id => $form->params->{external_id},
external_id => $form->field('external_id')->value, # null if empty
});
if(defined $subscriber->external_id) {
my $ext_pref = NGCP::Panel::Utils::Preferences::get_usr_preference_rs(
c => $c, attribute => 'ext_subscriber_id', prov_subscriber => $prov_subscriber);
@ -1977,6 +1980,10 @@ sub edit_master :Chained('master') :PathPart('edit') :Args(0) :Does(ACL) :ACLDet
} else {
$ext_pref->first->update({ value => $subscriber->external_id });
}
} elsif(defined $old_ext_id) {
NGCP::Panel::Utils::Preferences::get_usr_preference_rs(
c => $c, attribute => 'ext_subscriber_id', prov_subscriber => $prov_subscriber)
->delete;
}
if($subscriber->status eq 'locked') {
$form->values->{lock} = 4; # update lock below

@ -231,13 +231,17 @@ sub update_preferences {
my $pref = NGCP::Panel::Utils::Preferences::get_usr_preference_rs(
c => $c, attribute => $k, prov_subscriber => $prov_subscriber);
if($pref->first && $pref->first->attribute->max_occur == 1) {
$pref->first->update({
'value' => $preferences->{$k},
});
unless(defined $preferences->{$k}) {
$pref->first->delete;
} else {
$pref->first->update({
'value' => $preferences->{$k},
});
}
} else {
$pref->create({
'value' => $preferences->{$k},
});
}) if(defined $preferences->{$k});
}
}
}

Loading…
Cancel
Save