From a0b8805ce39fb5ea8ba147466f82f5af41815cd0 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 25 Mar 2020 09:38:32 +0000 Subject: [PATCH] Bug 23590: DBRev 19.12.00.055 Signed-off-by: Martin Renvoize --- Koha.pm | 2 +- .../data/mysql/atomicupdate/bug_23590.perl | 48 ------------------- installer/data/mysql/updatedatabase.pl | 48 +++++++++++++++++++ 3 files changed, 49 insertions(+), 49 deletions(-) delete mode 100644 installer/data/mysql/atomicupdate/bug_23590.perl diff --git a/Koha.pm b/Koha.pm index da2820a647..3c332dffe6 100644 --- a/Koha.pm +++ b/Koha.pm @@ -29,7 +29,7 @@ use vars qw{ $VERSION }; # - #4 : the developer version. The 4th number is the database subversion. # used by developers when the database changes. updatedatabase take care of the changes itself # and is automatically called by Auth.pm when needed. -$VERSION = "19.12.00.054"; +$VERSION = "19.12.00.055"; sub version { return $VERSION; diff --git a/installer/data/mysql/atomicupdate/bug_23590.perl b/installer/data/mysql/atomicupdate/bug_23590.perl deleted file mode 100644 index 9ca122086e..0000000000 --- a/installer/data/mysql/atomicupdate/bug_23590.perl +++ /dev/null @@ -1,48 +0,0 @@ -$DBversion = 'XXX'; # will be replaced by the RM -if( CheckVersion( $DBversion ) ) { - if( !column_exists( 'suggestions', 'lastmodificationby' ) ) { - $dbh->do(q| - ALTER TABLE suggestions ADD COLUMN lastmodificationby INT(11) DEFAULT NULL AFTER rejecteddate - |); - - $dbh->do(q| - ALTER TABLE suggestions ADD CONSTRAINT `suggestions_ibfk_lastmodificationby` FOREIGN KEY (`lastmodificationby`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE - |); - } - if( !column_exists( 'suggestions', 'lastmodificationdate' ) ) { - $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}); - } - - } - - $dbh->do( q| - INSERT IGNORE INTO letter(module, code, branchcode, name, is_html, title, content, message_transport_type, lang) VALUES ('suggestions', 'NOTIFY_MANAGER', '', 'Notify manager of a suggestion', 0, "A suggestion has been assigned to you", "Dear [% borrower.firstname %] [% borrower.surname %],\nA suggestion has been assigned to you: [% suggestion.title %].\nThank you,\n[% branch.branchname %]", 'email', 'default'); - | ); - - # Always end with this (adjust the bug info) - SetVersion( $DBversion ); - print "Upgrade to $DBversion done (Bug 23590 - Add lastmodificationby and lastmodificationdate to the suggestions table)\n"; -} diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 0f51b288f5..8a7c08b70e 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -21287,6 +21287,54 @@ if( CheckVersion( $DBversion ) ) { NewVersion( $DBversion, 13881, "Add desk management"); } +$DBversion = '19.12.00.055'; +if( CheckVersion( $DBversion ) ) { + if( !column_exists( 'suggestions', 'lastmodificationby' ) ) { + $dbh->do(q| + ALTER TABLE suggestions ADD COLUMN lastmodificationby INT(11) DEFAULT NULL AFTER rejecteddate + |); + + $dbh->do(q| + ALTER TABLE suggestions ADD CONSTRAINT `suggestions_ibfk_lastmodificationby` FOREIGN KEY (`lastmodificationby`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE + |); + } + + if( !column_exists( 'suggestions', 'lastmodificationdate' ) ) { + $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}); + } + + } + + $dbh->do( q| + INSERT IGNORE INTO letter(module, code, branchcode, name, is_html, title, content, message_transport_type, lang) VALUES ('suggestions', 'NOTIFY_MANAGER', '', 'Notify manager of a suggestion', 0, "A suggestion has been assigned to you", "Dear [% borrower.firstname %] [% borrower.surname %],\nA suggestion has been assigned to you: [% suggestion.title %].\nThank you,\n[% branch.branchname %]", 'email', 'default'); + | ); + + NewVersion( $DBversion, 23590, "Add lastmodificationby and lastmodificationdate to the suggestions table"); +} + # SEE bug 13068 # if there is anything in the atomicupdate, read and execute it. my $update_dir = C4::Context->config('intranetdir') . '/installer/data/mysql/atomicupdate/'; -- 2.39.5