Bug 23590: DBRev 19.12.00.055
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Wed, 25 Mar 2020 09:38:32 +0000 (09:38 +0000)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Wed, 25 Mar 2020 09:38:51 +0000 (09:38 +0000)
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Koha.pm
installer/data/mysql/atomicupdate/bug_23590.perl [deleted file]
installer/data/mysql/updatedatabase.pl

diff --git a/Koha.pm b/Koha.pm
index da2820a..3c332df 100644 (file)
--- 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 (file)
index 9ca1220..0000000
+++ /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";
-}
index 0f51b28..8a7c08b 100755 (executable)
@@ -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/';