+ if ( $opt{'tollfree'} ) {
+ # XXX: no caching for now
+ # XXX: limit option
+
+ my $command = 'listtollfree';
+ $command = 'listdids' if $self->option('fax');
+ my @tollfree = $self->vitelity_command($command);
+ my @ret = ();
+
+ if (scalar(@tollfree)) {
+ 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: ';
+
+ foreach my $did ( @tollfree ) {
+ $did =~ /^(\d{3})(\d{3})(\d{4})/ or die "unparsable did $did\n";
+ my($npa, $nxx, $station) = ($1, $2, $3);
+ push @ret, $did;
+
+ my $phone_avail = new FS::phone_avail {
+ 'exportnum' => $self->exportnum,
+ 'countrycode' => '1', # vitelity is US/CA only now
+ 'npa' => $npa,
+ 'nxx' => $nxx,
+ 'station' => $station,
+ };
+
+ $error = $phone_avail->insert();
+ if ( $error ) {
+ $dbh->rollback if $oldAutoCommit;
+ die $errmsg.$error;
+ }
+ }
+ $dbh->commit or warn $errmsg.$dbh->errstr if $oldAutoCommit;