X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fcdr%2FImport.pm;h=39a7772a36735eaf8de6ed2a098aff3f5834797c;hb=2b2dd969f3c18751afc583ad1e836ab8e6f73b5d;hp=7a377587866446fabbf6b9c919022c1870a25f89;hpb=3cd31aafeee3516bbea80e4b426dd1f3282bacf6;p=freeside.git diff --git a/FS/FS/cdr/Import.pm b/FS/FS/cdr/Import.pm index 7a3775878..39a7772a3 100644 --- a/FS/FS/cdr/Import.pm +++ b/FS/FS/cdr/Import.pm @@ -34,7 +34,7 @@ CDR importing =head1 CLASS METHODS -=item do_cli_import +=item dbi_import =cut @@ -74,11 +74,19 @@ sub dbi_import { # else { # print "freesidestatus column present\n"; # } + # or if using a status_table: + # CREATE TABLE FREESIDE_BILLING ( + # BILLING_ID BIGINT, + # FREESIDESTATUS VARCHAR(32) + # ) #my @cols = values %{ $args{column_map} }; - my $sql = "SELECT * FROM $table ". # join(',', @cols). " FROM $table ". + my $sql = "SELECT $table.* FROM $table "; # join(',', @cols). " FROM $table ". + $sql .= 'LEFT JOIN '. $args{status_table}. + " ON ( $table.$pkey = ". $args{status_table}. ".$pkey )" + if $args{status_table}; + $sql .= ' WHERE freesidestatus IS NULL '; - ' WHERE freesidestatus IS NULL '; #$sql .= ' LIMIT '. $opt{L} if $opt{L}; my $sth = $dbi->prepare($sql); $sth->execute or die $sth->errstr. " executing $sql"; @@ -109,21 +117,37 @@ sub dbi_import { $cdr->cdrtypenum($opt{c}) if $opt{c}; - #print $row->{$pkey},"\n" if $opt{v}; + my $pkey_value = $row->{$pkey}; + + #print "$pkey_value\n" if $opt{v}; my $error = $cdr->insert; + if ($error) { - #die $row->{$pkey} . ": failed import: $error\n"; - print $row->{$pkey} . ": failed import: $error\n"; + + #die "$pkey_value: failed import: $error\n"; + print "$pkey_value: failed import: $error\n"; + } else { + $imported++; - my $updated = $dbi->do( - "UPDATE $table SET freesidestatus = 'done' WHERE $pkey = ?", - undef, - $row->{$pkey} - ); + my $st_sql; + if ( $args{status_table} ) { + + $st_sql = + 'INSERT INTO '. $args{status_table}. " ( $pkey, freesidestatus ) ". + " VALUES ( ?, 'done' )"; + + } else { + + $st_sql = "UPDATE $table SET freesidestatus = 'done' WHERE $pkey = ?"; + + } + + my $updated = $dbi->do($st_sql, undef, $pkey_value ); #$updates += $updated; die "failed to set status: ".$dbi->errstr."\n" unless $updated; + } if ( $opt{L} && $imported >= $opt{L} ) {