diff options
author | Mark Wells <mark@freeside.biz> | 2016-05-19 16:57:06 -0700 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2016-05-19 16:59:18 -0700 |
commit | 02efed3da5453ada38ba386c7226fcfd99b44ba3 (patch) | |
tree | e8b01f8c43d1d5e4dc2dab9518b1ad5034fd5f66 /FS/FS/password_history.pm | |
parent | 71b0cae95c75843bcb80855b696d49d4752dbe35 (diff) |
fix some dangling records on upgrade, #32456 and #38765
Diffstat (limited to 'FS/FS/password_history.pm')
-rw-r--r-- | FS/FS/password_history.pm | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/FS/FS/password_history.pm b/FS/FS/password_history.pm index dd527b9..a34f616 100644 --- a/FS/FS/password_history.pm +++ b/FS/FS/password_history.pm @@ -160,6 +160,29 @@ sub password_equals { } +sub _upgrade_schema { + # clean up history records where linked_acct has gone away + my @where; + for my $fk ( grep /__/, __PACKAGE__->dbdef_table->columns ) { + my ($table, $key) = split(/__/, $fk); + push @where, " + ( $fk IS NOT NULL AND NOT EXISTS(SELECT 1 FROM $table WHERE $table.$key = $fk) )"; + } + my @recs = qsearch({ + 'table' => 'password_history', + 'extra_sql' => ' WHERE ' . join(' AND ', @where), + }); + my $error; + if (@recs) { + warn "Removing unattached password_history records (".scalar(@recs).").\n"; + foreach my $password_history (@recs) { + $error = $password_history->delete; + die $error if $error; + } + } + ''; +} + =back =head1 BUGS |