diff options
author | Mark Wells <mark@freeside.biz> | 2013-09-27 16:02:16 -0700 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2013-09-27 16:02:16 -0700 |
commit | c64ff892b9067f7aa719e78b20379d3274907946 (patch) | |
tree | 517ffedfe776cb492ed0a7a8c75c638aa41455d7 /FS | |
parent | e171647bc34d730d982c0e08d9731bbeb414be31 (diff) |
clean up invalid ticket links on upgrade, #25067
Diffstat (limited to 'FS')
-rw-r--r-- | FS/FS/TicketSystem.pm | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/FS/FS/TicketSystem.pm b/FS/FS/TicketSystem.pm index c1c69fa3f..fa54e0bbd 100644 --- a/FS/FS/TicketSystem.pm +++ b/FS/FS/TicketSystem.pm @@ -342,6 +342,21 @@ sub _upgrade_data { or die $dbh->errstr; $cve_2013_3373_sth->execute or die $cve_2013_3373_sth->errstr; + # Remove dangling customer links, if any + my %target_pkey = ('cust_main' => 'custnum', 'cust_svc' => 'svcnum'); + for my $table (keys %target_pkey) { + my $pkey = $target_pkey{$table}; + my $rows = $dbh->do( + "DELETE FROM links WHERE id IN(". + "SELECT links.id FROM links LEFT JOIN $table ON (links.target = ". + "'freeside://freeside/$table/' || $table.$pkey) ". + "WHERE links.target like 'freeside://freeside/$table/%' ". + "AND $table.$pkey IS NULL". + ")" + ) or die $dbh->errstr; + warn "Removed $rows dangling ticket-$table links\n" if $rows > 0; + } + return; } |