summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--FS/FS.pm2
-rw-r--r--FS/FS/Schema.pm14
-rw-r--r--FS/FS/part_export/globalpops_voip.pm54
-rw-r--r--FS/FS/phone_avail.pm145
-rw-r--r--FS/MANIFEST2
-rw-r--r--FS/t/phone_avail.t5
6 files changed, 222 insertions, 0 deletions
diff --git a/FS/FS.pm b/FS/FS.pm
index b3a6dcd79..e3580f553 100644
--- a/FS/FS.pm
+++ b/FS/FS.pm
@@ -134,6 +134,8 @@ L<FS::part_virtual_field> - Broadband virtual field class
L<FS::svc_phone> - Phone service class
+L<FS::phone_avail> - Phone number availability cache
+
L<FS::cdr> - Call Detail Record class
L<FS::cdr_calltype> - CDR calltype class
diff --git a/FS/FS/Schema.pm b/FS/FS/Schema.pm
index 22a731784..807be999e 100644
--- a/FS/FS/Schema.pm
+++ b/FS/FS/Schema.pm
@@ -2037,6 +2037,20 @@ sub tables_hashref {
'index' => [ [ 'countrycode', 'phonenum' ] ],
},
+ 'phone_avail' => {
+ 'columns' => [
+ 'availnum', 'int', '', '', '', '',
+ 'exportnum', 'int', '', '', '', '',
+ 'countrycode', 'varchar', '', 3, '', '',
+ 'state', 'char', 'NULL', 2, '', '',
+ 'npa', 'char', '', 3, '', '',
+ 'nxx', 'char', 'NULL', 3, '', '',
+ ],
+ 'primary_key' => 'availnum',
+ 'unique' => [],
+ 'index' => [ [ 'exportnum', 'countrycode', 'state' ] ],
+ },
+
'reason_type' => {
'columns' => [
'typenum', 'serial', '', '', '', '',
diff --git a/FS/FS/part_export/globalpops_voip.pm b/FS/FS/part_export/globalpops_voip.pm
index 13c263b9a..49bc2152f 100644
--- a/FS/FS/part_export/globalpops_voip.pm
+++ b/FS/FS/part_export/globalpops_voip.pm
@@ -2,7 +2,9 @@ package FS::part_export::globalpops_voip;
use vars qw(@ISA %info);
use Tie::IxHash;
+use FS::Record qw(qsearch dbh);
use FS::part_export;
+use FS::phone_avail;
@ISA = qw(FS::part_export);
@@ -38,7 +40,21 @@ sub get_dids {
} elsif ( $opt{'areacode'} ) { #return city (npa-nxx-XXXX)
%getdids = ( 'npa' => $opt{'areacode'} );
} elsif ( $opt{'state'} ) {
+
+ my @avail = qsearch({
+ 'table' => 'phone_avail',
+ 'hashref' => { 'exportnum' => $self->exportnum,
+ 'countrycode' => '1', #don't hardcode me when gp goes int'l
+ 'state' => $opt{'state'},
+ },
+ 'order_by' => 'ORDER BY npa',
+ });
+
+ return [ map $_->npa, @avail ] if @avail; #return cached area codes instead
+
+ #otherwise, search for em
%getdids = ( 'state' => $opt{'state'} );
+
}
my $dids = $self->gp_command('getDIDs', %getdids);
@@ -173,6 +189,44 @@ sub get_dids {
} elsif ( $opt{'areacode'} ) { #return city (npa-nxx-XXXX)
@return = sort { lc($a) cmp lc($b) } @return;
} elsif ( $opt{'state'} ) { #and not other things, then return areacode
+
+ #populate cache
+
+ local $SIG{HUP} = 'IGNORE';
+ local $SIG{INT} = 'IGNORE';
+ local $SIG{QUIT} = 'IGNORE';
+ local $SIG{TERM} = 'IGNORE';
+ local $SIG{TSTP} = 'IGNORE';
+ local $SIG{PIPE} = 'IGNORE';
+
+ my $oldAutoCommit = $FS::UID::AutoCommit;
+ local $FS::UID::AutoCommit = 0;
+ my $dbh = dbh;
+
+ my $errmsg = 'WARNING: error populating phone availability cache: ';
+ my $error = '';
+ foreach my $return (@return) {
+ my $phone_avail = new FS::phone_avail {
+ 'exportnum' => $self->exportnum,
+ 'countrycode' => '1', #don't hardcode me when gp goes int'l
+ 'state' => $opt{'state'},
+ 'npa' => $return,
+ };
+ $error = $phone_avail->insert();
+ if ( $error ) {
+ warn $errmsg.$error;
+ last;
+ }
+ }
+
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ } else {
+ $dbh->commit or warn $errmsg.$dbh->errstr if $oldAutoCommit;
+ }
+
+ #end populate cache
+
#@return = sort { (split(' ', $a))[0] <=> (split(' ', $b))[0] } @return;
@return = sort { $a <=> $b } @return;
} else {
diff --git a/FS/FS/phone_avail.pm b/FS/FS/phone_avail.pm
new file mode 100644
index 000000000..68aeca159
--- /dev/null
+++ b/FS/FS/phone_avail.pm
@@ -0,0 +1,145 @@
+package FS::phone_avail;
+
+use strict;
+use vars qw( @ISA );
+use FS::Record qw( qsearch qsearchs );
+
+@ISA = qw(FS::Record);
+
+=head1 NAME
+
+FS::phone_avail - Phone number availability cache
+
+=head1 SYNOPSIS
+
+ use FS::phone_avail;
+
+ $record = new FS::phone_avail \%hash;
+ $record = new FS::phone_avail { 'column' => 'value' };
+
+ $error = $record->insert;
+
+ $error = $new_record->replace($old_record);
+
+ $error = $record->delete;
+
+ $error = $record->check;
+
+=head1 DESCRIPTION
+
+An FS::phone_avail object represents availability of phone service.
+FS::phone_avail inherits from FS::Record. The following fields are currently
+supported:
+
+=over 4
+
+=item availnum
+
+primary key
+
+=item exportnum
+
+exportnum
+
+=item countrycode
+
+countrycode
+
+=item state
+
+state
+
+=item npa
+
+npa
+
+=item nxx
+
+nxx
+
+=back
+
+=head1 METHODS
+
+=over 4
+
+=item new HASHREF
+
+Creates a new record. To add the record to the database, see L<"insert">.
+
+Note that this stores the hash reference, not a distinct copy of the hash it
+points to. You can ask the object for a copy with the I<hash> method.
+
+=cut
+
+# the new method can be inherited from FS::Record, if a table method is defined
+
+sub table { 'phone_avail'; }
+
+=item insert
+
+Adds this record to the database. If there is an error, returns the error,
+otherwise returns false.
+
+=cut
+
+# the insert method can be inherited from FS::Record
+
+=item delete
+
+Delete this record from the database.
+
+=cut
+
+# the delete method can be inherited from FS::Record
+
+=item replace OLD_RECORD
+
+Replaces the OLD_RECORD with this one in the database. If there is an error,
+returns the error, otherwise returns false.
+
+=cut
+
+# the replace method can be inherited from FS::Record
+
+=item check
+
+Checks all fields to make sure this is a valid record. If there is
+an error, returns the error, otherwise returns false. Called by the insert
+and replace methods.
+
+=cut
+
+# the check method should currently be supplied - FS::Record contains some
+# data checking routines
+
+sub check {
+ my $self = shift;
+
+ my $error =
+ $self->ut_numbern('availnum')
+ || $self->ut_foreign_key('exportnum', 'part_export', 'exportnum' )
+ || $self->ut_number('countrycode')
+ || $self->ut_alphan('state')
+ || $self->ut_number('npa')
+ || $self->ut_numbern('nxx')
+ ;
+ return $error if $error;
+
+ $self->SUPER::check;
+}
+
+=back
+
+=head1 BUGS
+
+Sparse documentation.
+
+=head1 SEE ALSO
+
+L<FS::Record>, schema.html from the base documentation.
+
+=cut
+
+1;
+
diff --git a/FS/MANIFEST b/FS/MANIFEST
index 74342e9ab..7a6e05d01 100644
--- a/FS/MANIFEST
+++ b/FS/MANIFEST
@@ -411,3 +411,5 @@ FS/part_pkg_taxrate.pm
t/part_pkg_taxrate.t
FS/pkg_category.pm
t/pkg_category.t
+FS/phone_avail.pm
+t/phone_avail.t
diff --git a/FS/t/phone_avail.t b/FS/t/phone_avail.t
new file mode 100644
index 000000000..67f7e9a73
--- /dev/null
+++ b/FS/t/phone_avail.t
@@ -0,0 +1,5 @@
+BEGIN { $| = 1; print "1..1\n" }
+END {print "not ok 1\n" unless $loaded;}
+use FS::phone_avail;
+$loaded=1;
+print "ok 1\n";