From 2e88081bd06e92cb1309430cc4c03fc6d3f1dda5 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 16 Mar 2020 18:21:56 +0100 Subject: [PATCH] Bug 23590: Update new fields with relevant values We are filling lastmodificationdate and lastmodificationby depending on the max dates between manageddate, accepteddate and rejecteddate Signed-off-by: Katrin Fischer --- installer/data/mysql/atomicupdate/bug_23590.perl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/installer/data/mysql/atomicupdate/bug_23590.perl b/installer/data/mysql/atomicupdate/bug_23590.perl index d71862fc13..cc80154a4a 100644 --- a/installer/data/mysql/atomicupdate/bug_23590.perl +++ b/installer/data/mysql/atomicupdate/bug_23590.perl @@ -13,6 +13,28 @@ if( CheckVersion( $DBversion ) ) { $dbh->do(q| ALTER TABLE suggestions ADD COLUMN lastmodificationdate DATE DEFAULT NULL AFTER lastmodificationby |); + + my $suggestions = $dbh->selectall_arrayref(q| + SELECT suggestionid, managedby, manageddate, acceptedby, accepteddate, rejectedby, rejecteddate + FROM suggestions + |, { Slice => {} }); + for my $suggestion ( @$suggestions ) { + my ( $max_date ) = sort ( $suggestion->{manageddate} || (), $suggestion->{accepteddate} || (), $suggestion->{rejecteddate} || () ); + next unless $max_date; + my $last_modif_by = ( defined $suggestion->{manageddate} and $max_date eq $suggestion->{manageddate} ) + ? $suggestion->{managedby} + : ( defined $suggestion->{accepteddate} and $max_date eq $suggestion->{accepteddate} ) + ? $suggestion->{acceptedby} + : ( defined $suggestion->{rejecteddate} and $max_date eq $suggestion->{rejecteddate} ) + ? $suggestion->{rejectedby} + : undef; + next unless $last_modif_by; + $dbh->do(q| + UPDATE suggestions + SET lastmodificationdate = ?, lastmodificationby = ? + WHERE suggestionid = ? + |, undef, $max_date, $last_modif_by, $suggestion->{suggestionid}); + } } # Always end with this (adjust the bug info) -- 2.11.0