MT#5009 Properly re-use free numbers.

Don't try to insert a number into billing.voip_numbers directly,
rather than using the update_subscriber_numbers helper, which
handles the re-using of free numbers.
agranig/rest
Andreas Granig 12 years ago
parent 059607a8c7
commit e3ba8b4243

@ -148,28 +148,25 @@ sub create_subscriber {
# TODO: check if we find a reseller and contract and domains
my ($number, $cli);
if(defined $params->{e164}{cc} && $params->{e164}{cc} ne '') {
$cli = $params->{e164}{cc} .
($params->{e164}{ac} || '') .
$params->{e164}{sn};
$number = $reseller->voip_numbers->create({
cc => $params->{e164}{cc},
ac => $params->{e164}{ac} || '',
sn => $params->{e164}{sn},
status => 'active',
});
}
my $billing_subscriber = $contract->voip_subscribers->create({
uuid => $uuid_string,
username => $params->{username},
domain_id => $billing_domain->id,
status => $params->{status},
primary_number_id => defined $number ? $number->id : undef,
primary_number_id => undef, # will be filled in next step
});
if(defined $number) {
$number->update({ subscriber_id => $billing_subscriber->id });
my ($cli);
if(defined $params->{e164}{cc} && $params->{e164}{cc} ne '') {
$cli = $params->{e164}{cc} .
($params->{e164}{ac} || '') .
$params->{e164}{sn};
update_subscriber_numbers(
schema => $schema,
subscriber_id => $billing_subscriber->id,
reseller_id => $reseller->id,
primary_number => $params->{e164},
);
}
unless(exists $params->{password}) {

Loading…
Cancel
Save