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
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 ];
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;
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
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
[% IF ( updatestructure ) %]
<h2>Updating database structure</h2>
+ [% IF has_update_succeeds || success %]
+ <p>Update report :</p>
+ [% END %]
+
+ [%# Success for old versions %]
+ [% IF has_update_succeeds %]
+ <ul>
+ [% FOREACH l IN update_report %]
+ [% SET line = l.line %]
+ [% IF line.match('^Upgrade to') %]
+ <li>[% line | $raw %]</li>
+ [% ELSE %]
+ [% line | $raw %]<br/>
+ [% END %]
+ [% END %]
+ </ul>
+ [% END %]
+
+ [%# Success for new versions %]
[% IF success %]
- <p>Update report:</p>
<ul>
[% FOR s IN success %]
[% FOR o IN s.output %]
[% END %]
</ul>
[% END %]
+
+ [%# Errors for old versions %]
+ [% IF has_update_errors %]
+ <p>Update errors :</p>
+ <ul>
+ [% FOREACH update_error IN update_errors %]
+ <li class="update_error">[% update_error.line | html %]</li>
+ [% END %]
+ </ul>
+ [% END %]
+
+ [%# Errors for new versions %]
[% IF error %]
<p>Update error :</p>
<ul>
[% END %]
</ul>
[% END %]
- [% UNLESS error %]
+ [% UNLESS error OR has_update_errors %]
<p>Everything went okay. Update done.</p>
<p><a href="install.pl?step=3&op=finished" class="btn btn-primary">Continue to log in to Koha</a></p>
[% ELSE %]