From 66cc75d9ac943209b5afd85d96ababebefa77929 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 15 Jun 2021 11:38:51 +0200 Subject: [PATCH] Bug 25078: Re-introduce NewVersion This is ugly, we re-add the code we removed in the previous patch. We need to continue supporting "old" versions. Signed-off-by: Martin Renvoize --- C4/Installer.pm | 37 ++++++++++++++---- installer/install.pl | 39 +++++++++++++++++-- .../prog/en/modules/installer/step3.tt | 34 +++++++++++++++- 3 files changed, 96 insertions(+), 14 deletions(-) diff --git a/C4/Installer.pm b/C4/Installer.pm index 3a7833244bf..c25c85aaeed 100644 --- a/C4/Installer.pm +++ b/C4/Installer.pm @@ -31,8 +31,7 @@ use Koha; use vars qw(@ISA @EXPORT); BEGIN { require Exporter; - @ISA = qw( Exporter ); - push @EXPORT, qw( primary_key_exists foreign_key_exists index_exists column_exists TableExists marc_framework_sql_list TransformToNum CheckVersion sanitize_zero_date update get_db_entries ); + push @EXPORT, qw( primary_key_exists foreign_key_exists index_exists column_exists TableExists marc_framework_sql_list TransformToNum CheckVersion NewVersion sanitize_zero_date update get_db_entries ); }; =head1 NAME @@ -763,7 +762,11 @@ sub output_version { my $DBversion = $db_entry->{version}; my $bug_number = $db_entry->{bug_number}; my $time = $db_entry->{time}; - my $done = $db_entry->{done} ? "done" : "failed"; + my $done = defined $db_entry->{done} + ? $db_entry->{done} + ? " done" + : " failed" + : ""; # For old versions, we don't know if we succeed or failed unless ( ref($descriptions) ) { $descriptions = [ $descriptions ]; @@ -775,17 +778,17 @@ sub output_version { if ( @$descriptions > 1 ) { if ( $first ) { unless ( $bug_number ) { - push @output, sprintf "Upgrade to %s %s [%s]:", $DBversion, $done, $time; + push @output, sprintf "Upgrade to %s%s [%s]:", $DBversion, $done, $time; } else { - push @output, sprintf "Upgrade to %s %s [%s]: Bug %5s", $DBversion, $done, $time, $bug_number; + push @output, sprintf "Upgrade to %s%s [%s]: Bug %5s", $DBversion, $done, $time, $bug_number; } } push @output, sprintf "\t\t\t\t\t\t - %s", $description; } else { unless ( $bug_number ) { - push @output, sprintf "Upgrade to %s %s [%s]: %s", $DBversion, $done, $time, $description; + push @output, sprintf "Upgrade to %s%s [%s]: %s", $DBversion, $done, $time, $description; } else { - push @output, sprintf "Upgrade to %s %s [%s]: Bug %5s - %s", $DBversion, $done, $time, $bug_number, $description; + push @output, sprintf "Upgrade to %s%s [%s]: Bug %5s - %s", $DBversion, $done, $time, $bug_number, $description; } } $first = 0; @@ -861,8 +864,26 @@ sub SetVersion { C4::Context::clear_syspref_cache(); # invalidate cached preferences } +# DEPRECATED Don't use it! +# Used for compatibility with older versions (from updatedatabase.pl) sub NewVersion { - # void FIXME replace me + my ( $DBversion, $bug_number, $descriptions ) = @_; + + SetVersion($DBversion); + + unless ( ref($descriptions) ) { + $descriptions = [ $descriptions ]; + } + + my $output = output_version( { + bug_number => $bug_number, + description => $descriptions, + version => $DBversion, + time => POSIX::strftime( "%H:%M:%S", localtime ), + }); + + say join "\n", @$output; + } =head2 CheckVersion diff --git a/installer/install.pl b/installer/install.pl index 3547d6a5648..3d410f34cb5 100755 --- a/installer/install.pl +++ b/installer/install.pl @@ -393,14 +393,45 @@ elsif ( $step && $step == 3 ) { chk_log( $logdir, "updatedatabase-error_$filename_suffix" ) ); - my $updatedatabase_path = C4::Context->config("intranetdir") - . "/installer/data/$info{dbms}/updatedatabase.pl"; + my $cmd = C4::Context->config("intranetdir") + . "/installer/data/$info{dbms}/updatedatabase.pl >> $logfilepath 2>> $logfilepath_errors"; + + system( $cmd ); + + my $fh; + open( $fh, "<:encoding(utf-8)", $logfilepath ) + or die "Cannot open log file $logfilepath: $!"; + my @report = <$fh>; + close $fh; + if (@report) { + $template->param( update_report => + [ map { { line => $_ =~ s/\t/  /gr } } split( /\n/, join( '', @report ) ) ] + ); + $template->param( has_update_succeeds => 1 ); + } + else { + eval { `rm $logfilepath` }; + } + open( $fh, "<:encoding(utf-8)", $logfilepath_errors ) + or die "Cannot open log file $logfilepath_errors: $!"; + @report = <$fh>; + close $fh; + if (@report) { + $template->param( update_errors => + [ map { { line => $_ } } split( /\n/, join( '', @report ) ) ] + ); + $template->param( has_update_errors => 1 ); + warn +"The following errors were returned while attempting to run the updatedatabase.pl script:\n"; + foreach my $line (@report) { warn "$line\n"; } + } + else { + eval { `rm $logfilepath_errors` }; + } my $db_entries = get_db_entries(); my $report = update( $db_entries ); - # FIXME restore log to logfilepath and logfilepath_errors - $template->param( success => $report->{success}, error => $report->{error} ); #warn "The following errors were returned while attempting to run the updatedatabase.pl script:\n"; #FIXME restore this 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 04f9976c56a..2fca0c40dcf 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step3.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/installer/step3.tt @@ -244,8 +244,26 @@ [% IF ( updatestructure ) %]

Updating database structure

+ [% IF has_update_succeeds || success %] +

Update report :

+ [% END %] + + [%# Success for old versions %] + [% IF has_update_succeeds %] + + [% END %] + + [%# Success for new versions %] [% IF success %] -

Update report:

[% END %] + + [%# Errors for old versions %] + [% IF has_update_errors %] +

Update errors :

+ + [% END %] + + [%# Errors for new versions %] [% IF error %]

Update error :

[% END %] - [% UNLESS error %] + [% UNLESS error OR has_update_errors %]

Everything went okay. Update done.

Continue to log in to Koha

[% ELSE %] -- 2.20.1