Bug 20256: Update database
[srvgit] / installer / install.pl
index 3547d6a..0638325 100755 (executable)
@@ -54,7 +54,7 @@ if ( defined($language) ) {
 
 my $installer = C4::Installer->new();
 my %info;
-$info{'dbname'} = C4::Context->config("database");
+$info{'dbname'} = C4::Context->config("database_test") || C4::Context->config("database");
 $info{'dbms'}   = (
       C4::Context->config("db_scheme")
     ? C4::Context->config("db_scheme")
@@ -393,17 +393,60 @@ 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";
 
-        my $db_entries = get_db_entries();
-        my $report = update( $db_entries );
+        system( $cmd );
 
-        # FIXME restore log to logfilepath and logfilepath_errors
+        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;
+        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"; }
+        }
+        else {
+            eval { `rm $logfilepath_errors` };
+        }
 
-        $template->param( success => $report->{success}, error => $report->{error} );
+        unless ( $update_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 );
+
+            $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 );
     }
     else {