Bug 30250: Use ApplyFrameworkDefaults when importing a record
[srvgit] / installer / install.pl
index 5bd3806..0638325 100755 (executable)
 use Modern::Perl;
 use diagnostics;
 
-use C4::InstallAuth;
+use C4::InstallAuth qw( get_template_and_user );
 use CGI qw ( -utf8 );
-use POSIX qw(strftime);
+use POSIX;
 
 use C4::Context;
-use C4::Output;
+use C4::Output qw( output_html_with_http_headers );
 use C4::Templates;
-use C4::Languages qw(getAllLanguages getTranslatedLanguages);
+use C4::Languages qw( getAllLanguages getTranslatedLanguages );
 use C4::Installer;
 use C4::Installer::PerlModules;
 
 use Koha;
 
-my $query = new CGI;
+my $query = CGI->new;
 my $step  = $query->param('step');
 
 my $language = $query->param('language');
@@ -49,14 +49,12 @@ if ( defined($language) ) {
         template_name => "installer/step" . ( $step ? $step : 1 ) . ".tt",
         query         => $query,
         type          => "intranet",
-        authnotrequired => 0,
-        debug           => 1,
     }
 );
 
 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")
@@ -221,9 +219,10 @@ elsif ( $step && $step == 3 ) {
 
     my $op = $query->param('op');
     if ( $op && $op eq 'finished' ) {
-        #
+        # Remove the HandleError set at the beginning of the installer process
+        C4::Context->dbh->disconnect;
+
         # we have finished, just redirect to mainpage.
-        #
         print $query->redirect("/cgi-bin/koha/mainpage.pl");
         exit;
     }
@@ -245,9 +244,12 @@ elsif ( $step && $step == 3 ) {
     elsif ( $op && $op eq 'addframeworks' ) {
 
         # 1ST install, 3rd sub-step : insert the SQL files the user has selected
+        my $langchoice = $query->param('fwklanguage');
+        $langchoice = $query->cookie('KohaOpacLanguage') unless ($langchoice);
+        $langchoice =~ s/[^a-zA-Z_-]*//g;
 
         my ( $fwk_language, $list ) =
-          $installer->load_sql_in_order( $all_languages,
+          $installer->load_sql_in_order( $langchoice, $all_languages,
             $query->multi_param('framework') );
         $template->param(
             "fwklanguage" => $fwk_language,
@@ -394,7 +396,7 @@ elsif ( $step && $step == 3 ) {
         my $cmd = C4::Context->config("intranetdir")
           . "/installer/data/$info{dbms}/updatedatabase.pl >> $logfilepath 2>> $logfilepath_errors";
 
-        system($cmd );
+        system( $cmd );
 
         my $fh;
         open( $fh, "<:encoding(utf-8)", $logfilepath )
@@ -403,7 +405,7 @@ elsif ( $step && $step == 3 ) {
         close $fh;
         if (@report) {
             $template->param( update_report =>
-                  [ map { local $_ = $_; $_ =~ s/\t/&emsp;&emsp;/g; { line => $_ } } split( /\n/, join( '', @report ) ) ]
+                  [ map { { line => $_ =~ s/\t/&emsp;&emsp;/gr } } split( /\n/, join( '', @report ) ) ]
             );
             $template->param( has_update_succeeds => 1 );
         }
@@ -414,10 +416,12 @@ elsif ( $step && $step == 3 ) {
           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";
@@ -426,6 +430,23 @@ elsif ( $step && $step == 3 ) {
         else {
             eval { `rm $logfilepath_errors` };
         }
+
+        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}
+                }
+            );
+        }
+
         $template->param( $op => 1 );
     }
     else {