(no commit message)
[freeside.git] / FS / FS / cust_pay.pm
index 90a14ea..358dfdc 100644 (file)
@@ -432,8 +432,6 @@ sub check {
 #           " already exists";
 #  }
 
-  $self->otaker(getotaker);
-
   $self->SUPER::check;
 }
 
@@ -675,8 +673,11 @@ sub _upgrade_data {  #class method
 
   #not the most efficient, but hey, it only has to run once
 
-  my $count_sql =
-    "SELECT COUNT(*) FROM cust_pay WHERE otaker IS NULL OR otaker = ''";
+  my $where = "WHERE ( otaker IS NULL OR otaker = '' OR otaker = 'ivan' ) ".
+              "  AND 0 < ( SELECT COUNT(*) FROM cust_main                 ".
+              "              WHERE cust_main.custnum = cust_pay.custnum ) ";
+
+  my $count_sql = "SELECT COUNT(*) FROM cust_pay $where";
 
   my $sth = dbh->prepare($count_sql) or die dbh->errstr;
   $sth->execute or die $sth->errstr;
@@ -686,16 +687,15 @@ sub _upgrade_data {  #class method
 
   my $count = 0;
   my $lastprog = 0;
-  while (1) {
 
-    my $cust_pay = qsearchs( {
+  my @cust_pay = qsearch( {
       'table'     => 'cust_pay',
       'hashref'   => {},
-      'extra_sql' => "WHERE otaker IS NULL OR otaker = ''",
-      'order_by'  => 'ORDER BY paynum LIMIT 1',
-    } );
+      'extra_sql' => $where,
+      'order_by'  => 'ORDER BY paynum',
+  } );
 
-    return unless $cust_pay;
+  foreach my $cust_pay (@cust_pay) {
 
     my $h_cust_pay = $cust_pay->h_search('insert');
     if ( $h_cust_pay ) {
@@ -706,7 +706,13 @@ sub _upgrade_data {  #class method
 
     delete $FS::payby::hash{'COMP'}->{cust_pay}; #quelle kludge
     my $error = $cust_pay->replace;
-    die $error if $error;
+
+    if ( $error ) {
+      warn " *** WARNING: Error updaating order taker for payment paynum".
+           $cust_pay->paynun. ": $error\n";
+      next;
+    }
+
     $FS::payby::hash{'COMP'}->{cust_pay} = ''; #restore it
 
     $count++;