4 # cdr.reimport user format filename
8 use FS::UID qw(adminsuidsetup);
9 use FS::Record qw(qsearch);
12 my $user = shift or die &usage;
15 my $format = shift or die &usage;
19 my($new, $rep, $skip) = (0, 0, 0);
21 #this is what makes it a reimport and should probably be moved to cdr.pm
23 my($cdr, $param) = @_;
25 my @exists = qsearch('cdr', {
26 map { $_ => $cdr->$_() }
27 qw( uniqueid startdate enddate src dst charged_party )
30 unless ( scalar(@exists) ) {
35 if ( scalar(@exists) == 2 ) {
36 if ( $exists[0]->freesidestatus || $exists[1]->freesidestatus ) {
37 return "processed double record for uniqueid ". $cdr->uniqueid. "\n";
39 warn "deleting double record for uniqueid ". $cdr->uniqueid. "\n";
40 my $extra = shift @exists;
41 my $error = $extra->delete;
42 return $error if $error;
45 return "too many matches (". scalar(@exists). ") found!"
46 if scalar(@exists) > 1;
48 my $exists = $exists[0];
49 if ( $exists->freesidestatus ) {
51 $param->{skiprow} = 1;
54 my $error = $exists->delete;
55 return $error if $error;
62 my $error = FS::cdr::batch_import( {
65 'batch_namevalue' => $file."-REIMPORT$$",
66 'preinsert_callback' => $cb,
70 warn "$skip skipped, $rep replaced, $new new\n";
73 "Usage: \n cdr.reimport user format filename\n";