From 312c5f16d8bb0d8c58bd6deb1350a47ba526cb77 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 Signed-off-by: Kyle M Hall Signed-off-by: Jonathan Druart --- C4/Installer.pm | 36 +++++++++++++---- installer/install.pl | 39 +++++++++++++++++-- .../prog/en/modules/installer/step3.tt | 34 +++++++++++++++- 3 files changed, 96 insertions(+), 13 deletions(-) diff --git a/C4/Installer.pm b/C4/Installer.pm index 4b62d5deac..04e7e9f5d1 100644 --- a/C4/Installer.pm +++ b/C4/Installer.pm @@ -32,7 +32,7 @@ use vars qw(@ISA @EXPORT); BEGIN { require Exporter; @ISA = qw( Exporter ); - push @EXPORT, qw( primary_key_exists unique_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 unique_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 @@ -770,7 +770,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 ]; @@ -782,17 +786,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; @@ -868,8 +872,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 3547d6a564..3d410f34cb 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 04f9976c56..2fca0c40dc 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 %] +
    + [% FOREACH l IN update_report %] + [% SET line = l.line %] + [% IF line.match('^Upgrade to') %] +
  • [% line | $raw %]
  • + [% ELSE %] + [% line | $raw %]
    + [% END %] + [% END %] +
+ [% END %] + + [%# Success for new versions %] [% IF success %] -

Update report:

    [% FOR s IN success %] [% FOR o IN s.output %] @@ -257,6 +275,18 @@ [% END %]
[% END %] + + [%# Errors for old versions %] + [% IF has_update_errors %] +

Update errors :

+
    + [% FOREACH update_error IN update_errors %] +
  • [% update_error.line | html %]
  • + [% END %] +
+ [% END %] + + [%# Errors for new versions %] [% IF error %]

Update error :

    @@ -275,7 +305,7 @@ [% END %]
[% END %] - [% UNLESS error %] + [% UNLESS error OR has_update_errors %]

Everything went okay. Update done.

Continue to log in to Koha

[% ELSE %] -- 2.39.5