- my $info = $cdr_info{$format};
-
- my $type = exists($info->{'type'}) ? lc($info->{'type'}) : 'csv';
-
- my $parser;
- if ( $type eq 'csv' ) {
- eval "use Text::CSV_XS;";
- die $@ if $@;
- $parser = new Text::CSV_XS;
- } elsif ( $type eq 'fixedlength' ) {
- eval "use Parse::FixedLength;";
- die $@ if $@;
- $parser = new Parse::FixedLength $info->{'fixedlength_format'};
- } else {
- die "Unknown CDR format type $type for format $format\n";
- }
-
- my $imported = 0;
- #my $columns;
-
- 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 $header_lines = exists($info->{'header'}) ? $info->{'header'} : 0;
-
- my $line;
- while ( defined($line=<$fh>) ) {
-
- next if $header_lines-- > 0; #&& $line =~ /^[\w, "]+$/
-
- my @columns = ();
- if ( $type eq 'csv' ) {
-
- $parser->parse($line) or do {
- $dbh->rollback if $oldAutoCommit;
- return "can't parse: ". $parser->error_input();
- };
-
- @columns = $parser->fields();
-
- } elsif ( $type eq 'fixedlength' ) {
-
- @columns = $parser->parse($line);
-
- } else {
- die "Unknown CDR format type $type for format $format\n";
- }