From e11f4561162c0b0bc15672dbf9ed3b880db8da27 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 29 Jan 2021 12:50:27 +0100 Subject: [PATCH] Bug 25078: [POC] Lazy version This is the lazy, quick and dirty, version. We use a try catch block and execute the db entry in a transaction. When I error is found, we stop. The main problem is that we cannot do anything with the raw output in the template. execute_entry + try + txn_do Why do /var/log/koha/kohadev/updatedatabase_*.log (not -error) contain Status: 500 Content-type: text/html

Software error:

etc. ??? --- Koha.pm | 2 +- installer/data/mysql/updatedatabase.pl | 36 +++++++++++++++++-- .../prog/en/modules/installer/step3.tt | 2 +- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/Koha.pm b/Koha.pm index 3f97959709..d2206842d6 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 = "20.12.00.005"; +$VERSION = "20.12.00.006"; sub version { return $VERSION; diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 8ef697a7a4..b9c7041570 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -47,6 +47,8 @@ use MARC::File::XML ( BinaryEncoding => 'utf8' ); use File::Path qw[remove_tree]; # perl core module use File::Slurp; +use Try::Tiny; + # FIXME - The user might be installing a new database, so can't rely # on /etc/koha.conf anyway. @@ -23451,8 +23453,38 @@ if( CheckVersion( $DBversion ) ) { $DBversion = '20.12.00.005'; if( CheckVersion( $DBversion ) ) { - $dbh->do(q{UPDATE systempreferences set variable="OPACLanguages" WHERE variable="opaclanguages"}); - NewVersion( $DBversion, 27491, "Rename system preference 'opaclanguages' to 'OPACLanguages'"); + execute_entry( + $DBversion, 27491, "Rename system preference 'opaclanguages' to 'OPACLanguages'", + sub { + $dbh->do( + q{UPDATE systempreferences set variable="OPACLanguages" WHERE variable="opaclanguages"} + ); + } + ); +} + +$DBversion = '20.12.00.006'; +if( CheckVersion( $DBversion ) ) { + execute_entry( $DBversion, 12345, "Testing failure", + sub { + $dbh->do( + q{ALTER TABLE foo} + ); + } + ); +} + + +sub execute_entry { + my ( $DBversion, $bug_number, $description, $sub ) = @_; + + try { + Koha::Database->schema->txn_do($sub); + } catch { + die sprintf "Something wrong happened during %s (%s):\n%s", $DBversion, $description, $_; + }; + + NewVersion( $DBversion, $bug_number, $description ); } # SEE bug 13068 diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step3.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step3.tt index 685fd7f116..370c1646b5 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step3.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step3.tt @@ -249,7 +249,7 @@ [% IF ( updatestructure ) %]

Updating database structure

[% IF ( has_update_succeeds ) %] -

Update report :

+

Update report: