+ if ( !defined $ENV{PERL5LIB} ) {
+ my $find = "C4/Context.pm";
+ my $path = $INC{$find};
+ $path =~ s/\Q$find\E//;
+ $ENV{PERL5LIB} = "$path:$path/installer";
+ warn "# plack? inserted PERL5LIB $ENV{PERL5LIB}\n";
+ }
+
+ my $now = POSIX::strftime( "%Y-%m-%dT%H:%M:%S", localtime() );
+ my $logdir = C4::Context->config('logdir');
+ my $dbversion = C4::Context->preference('Version');
+ my $kohaversion = Koha::version;
+ $kohaversion =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/;
+
+ my $filename_suffix = join '_', $now, $dbversion, $kohaversion;
+ my ( $logfilepath, $logfilepath_errors ) = (
+ chk_log( $logdir, "updatedatabase_$filename_suffix" ),
+ chk_log( $logdir, "updatedatabase-error_$filename_suffix" )
+ );
+
+ 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;
+ my $update_errors;
+ if (@report) {
+ $template->param( update_errors =>
+ [ map { { line => $_ } } split( /\n/, join( '', @report ) ) ]
+ );
+ $update_errors = 1;
+ $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"; }