clean up dangling cust_svc records, related to #32043
authorMark Wells <mark@freeside.biz>
Fri, 19 Feb 2016 21:44:54 +0000 (13:44 -0800)
committerMark Wells <mark@freeside.biz>
Wed, 24 Feb 2016 19:33:51 +0000 (11:33 -0800)
FS/FS/cust_svc.pm

index 0223f93..13e2e0f 100644 (file)
@@ -1300,13 +1300,19 @@ sub _upgrade_data {
     my $svcdb = $cust_svc->part_svc->svcdb;
     $h_search{'hashref'}{'svcnum'} = $svcnum;
     $h_search{'table'} = "h_$svcdb";
-    my $h_svc_x = qsearchs(\%h_search)
-      or next;
-    my $class = "FS::$svcdb";
-    my $new_svc_x = $class->new({ $h_svc_x->hash });
-    my $error = $new_svc_x->insert;
-    warn "error repairing svcnum $svcnum ($svcdb) from history:\n$error\n"
-      if $error;
+    my $h_svc_x = qsearchs(\%h_search);
+    if ( $h_svc_x ) {
+      my $class = "FS::$svcdb";
+      my $new_svc_x = $class->new({ $h_svc_x->hash });
+      my $error = $new_svc_x->insert;
+      warn "error repairing svcnum $svcnum ($svcdb) from history:\n$error\n"
+        if $error;
+    } else {
+      # can't be fixed, so remove the dangling cust_svc to avoid breaking
+      # stuff
+      my $error = $cust_svc->delete;
+      warn "error cleaning up missing svcnum $svcnum ($svcdb):\n$error\n";
+    }
   }
 
   '';