X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=bin%2Fcdr.reimport;h=23060387d7d0491ba88d1bc7d96e4f18148471e9;hp=42492b0ee15e62305aa508dbad40618fb5ba7748;hb=de549dfea65bf78508b508f03e4f9637122166a6;hpb=811c95da18776232da103fd445e2def019f98d5b diff --git a/bin/cdr.reimport b/bin/cdr.reimport index 42492b0ee..23060387d 100644 --- a/bin/cdr.reimport +++ b/bin/cdr.reimport @@ -22,19 +22,28 @@ my($new, $rep, $skip) = (0, 0, 0); my $cb = sub { my($cdr, $param) = @_; - my @exists = qsearch({ - 'table' => 'cdr', - 'hashref' => { 'uniqueid' => $cdr->uniqueid, - 'src' => $cdr->src, - 'startdate' => $cdr->startdate, - }, + my @exists = qsearch('cdr', { + map { $_ => $cdr->$_() } + qw( uniqueid startdate enddate src dst charged_party ) }); unless ( scalar(@exists) ) { $new++; return; } - die "too many matches found!" if scalar(@exists) > 1; + + if ( scalar(@exists) == 2 ) { + if ( $exists[0]->freesidestatus || $exists[1]->freesidestatus ) { + return "processed double record for uniqueid ". $cdr->uniqueid. "\n"; + } + warn "deleting double record for uniqueid ". $cdr->uniqueid. "\n"; + my $extra = shift @exists; + my $error = $extra->delete; + return $error if $error; + } + + return "too many matches (". scalar(@exists). ") found!" + if scalar(@exists) > 1; my $exists = $exists[0]; if ( $exists->freesidestatus ) { @@ -43,15 +52,17 @@ my $cb = sub { } else { $rep++; my $error = $exists->delete; - die $error if $error; + return $error if $error; } + return ''; + }; my $error = FS::cdr::batch_import( { 'file' => $file, 'format' => $format, - 'batch_namevalue' => $file, + 'batch_namevalue' => $file."-REIMPORT$$", 'preinsert_callback' => $cb, } ); die $error if $error;