From: Mark Wells Date: Fri, 19 Feb 2016 21:44:54 +0000 (-0800) Subject: clean up dangling cust_svc records, related to #32043 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=fc951f6ed5fab5c3b36f79f9f413556f76e75e0c clean up dangling cust_svc records, related to #32043 --- 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"; + } } '';