From bae8904ba11dd86b1c9cd2cb02b771c97034c9bd Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 17 Nov 2020 12:18:48 +0100 Subject: [PATCH] Bug 26940: Put in sync borrowers.debarredcomment with comments from borrower_debarment --- .../data/mysql/atomicupdate/bug_26940.perl | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 installer/data/mysql/atomicupdate/bug_26940.perl diff --git a/installer/data/mysql/atomicupdate/bug_26940.perl b/installer/data/mysql/atomicupdate/bug_26940.perl new file mode 100644 index 0000000000..a58d14a5e7 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_26940.perl @@ -0,0 +1,22 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + my $debar = $dbh->selectall_arrayref(q| + SELECT d.borrowernumber, GROUP_CONCAT(comment SEPARATOR '\n') AS comment + FROM borrower_debarments d + LEFT JOIN borrowers b ON b.borrowernumber=d.borrowernumber + WHERE b.debarredcomment IS NULL AND ( expiration > CURRENT_DATE() OR expiration IS NULL ) + GROUP BY d.borrowernumber + |, { Slice => {} }); + + + my $update_sth = $dbh->prepare(q| + UPDATE borrowers + SET debarredcomment=? + WHERE borrowernumber=? + |); + for my $d ( @$debar ) { + $update_sth->execute($d->{comment}, $d->{borrowernumber}); + } + + NewVersion( $DBversion, 26940, "Put in sync borrowers.debarredcomment with comments from borrower_debarments"); +} -- 2.20.1