From fc951f6ed5fab5c3b36f79f9f413556f76e75e0c Mon Sep 17 00:00:00 2001 From: Mark Wells Date: Fri, 19 Feb 2016 13:44:54 -0800 Subject: [PATCH] clean up dangling cust_svc records, related to #32043 --- FS/FS/cust_svc.pm | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/FS/FS/cust_svc.pm b/FS/FS/cust_svc.pm index 0223f934b..13e2e0f26 100644 --- a/FS/FS/cust_svc.pm +++ b/FS/FS/cust_svc.pm @@ -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"; + } } ''; -- 2.11.0