fix 'Can't call method "setup" on an undefined value' error when using into rates...
[freeside.git] / FS / bin / freeside-cdrrewrited
index 7b4da10..846b0b9 100644 (file)
@@ -41,21 +41,15 @@ while (1) {
   # rewritten "skipped", i.e. why we're a daemon in the first place
   # instead of just doing this search like normal CDRs
 
-  my @recent = grep { ($accountcode_unmatch{$_} + $accountcode_retry) < time }
-                 keys %accountcode_unmatch;
   #hmm :/
-  my $extra_sql = '';
-  if ( @recent ) {
-    $extra_sql .= ' AND '.
-      join(' AND ',
-                    map { my($sessionnum,$src) = split(',', $_);
-                          "( sessionnum != '$sessionnum' OR src != '$src' )";
-                        }
-                      @recent
-          );
-  }
+  my @recent = grep { ($accountcode_unmatch{$_} + $accountcode_retry) > time }
+                 keys %accountcode_unmatch;
+  my $extra_sql = scalar(@recent)
+                    ? ' AND acctid NOT IN ('. join(',', @recent). ') '
+                    : '';
 
   my $found = 0;
+  my %skip = ();
   foreach my $cdr ( 
     qsearch( {
       'table'     => 'cdr',
@@ -68,6 +62,8 @@ while (1) {
     } )
   ) {
 
+    next if $skip{$cdr->acctid};
+
     $found = 1;
     my @status = ();
 
@@ -113,11 +109,13 @@ while (1) {
         my $cantfind = "can't find primary CDR with session ". $cdr->sessionnum.
                        ", src ". $cdr->subscriber;
         if ( $cdr->calldate_unix + $accountcode_giveup < time ) {
+          warn "ERROR: $cantfind; giving up\n";
           push @status, 'taqua-accountcode-NOTFOUND';
           $cdr->status('done'); #so it doesn't try to rate
+          delete $accountcode_unmatch{$cdr->acctid}; #so it doesn't suck mem
         } else {
           warn "WARNING: $cantfind; will keep trying\n";
-          $accountcode_unmatch{$cdr->sessionnum.','.$cdr->subscriber} = time;
+          $accountcode_unmatch{$cdr->acctid} = time;
           next;
         }
 
@@ -130,6 +128,7 @@ while (1) {
           warn "WARNING: error rewriting primary CDR (will retry): $error\n";
           next;
         }
+        $skip{$primary->acctid} = 1;
 
         push @status, 'taqua-accountcode';
         $cdr->status('done'); #so it doesn't try to rate