Bug 25078: Keep atomic updates in "atomicupdate" dir
[koha-ffzg.git] / installer / install.pl
index 3547d6a..abb3897 100755 (executable)
@@ -393,15 +393,55 @@ 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/&emsp;&emsp;/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 );
+        my $atomic_update_files = get_atomic_updates;
+        my $atomic_update_report = run_atomic_updates( $atomic_update_files );
 
-        # FIXME restore log to logfilepath and logfilepath_errors
-
-        $template->param( success => $report->{success}, error => $report->{error} );
+        $template->param(
+            success        => $report->{success},
+            error          => $report->{error},
+            atomic_updates => {
+                success => $atomic_update_report->{success},
+                error   => $atomic_update_report->{error}
+            }
+        );
 
         #warn "The following errors were returned while attempting to run the updatedatabase.pl script:\n"; #FIXME restore this
         $template->param( $op => 1 );