Bugfix: Enabling guide box configuration parameter
[koha_fer] / installer / install.pl
index 088d0f7..9d152dd 100755 (executable)
@@ -1,5 +1,7 @@
-#!/usr/bin/perl -w # please develop with -w
+#!/usr/bin/perl
 
+use strict;
+use warnings;
 use diagnostics;
 
 # use Install;
@@ -9,9 +11,8 @@ use C4::Output;
 use C4::Languages qw(getAllLanguages getTranslatedLanguages);
 use C4::Installer;
 
-use strict;    # please develop with the strict pragma
-
 use CGI;
+use IPC::Cmd;
 
 my $query = new CGI;
 my $step  = $query->param('step');
@@ -130,6 +131,18 @@ if ( $step && $step == 1 ) {
               { name => "GD::Barcode", usagebarcode => 1, usagespine => 1 };
         }
     }
+    unless ( eval { require GD } ) {
+        if ( $#missing >= 0 ) {   # only when $#missing >= 0 so this isn't fatal
+            push @missing,
+              { name => "GD", usagepatronimages => 1 };
+        }
+    }
+    unless ( eval { require Graphics::Magick } ) {
+        if ( $#missing >= 0 ) {   # only when $#missing >= 0 so this isn't fatal
+            push @missing,
+              { name => "Graphics::Magick", usagepatroncards => 1 };
+        }
+    }
     unless ( eval { require Data::Random } ) {
         if ( $#missing >= 0 ) {   # only when $#missing >= 0 so this isn't fatal
             push @missing, { name => "Data::Random", usagebarcode => 1 };
@@ -229,7 +242,7 @@ elsif ( $step && $step == 2 ) {
                 }
                 $template->param( "checkgrantaccess" => $grantaccess );
             }  # End mysql connect check...
-           
+
            elsif ( $info{dbms} eq "Pg" ) {
                # Check if database has been created...
                my $rv = $dbh->do( "SELECT * FROM pg_catalog.pg_database WHERE datname = \'$info{dbname}\';" );
@@ -256,7 +269,7 @@ elsif ( $step && $step == 3 ) {
 #
 # STEP 3 : database setup
 #
-# 
+#
     my $op = $query->param('op');
     if ( $op && $op eq 'finished' ) {
         #
@@ -297,14 +310,14 @@ elsif ( $step && $step == 3 ) {
         #
         #
         # (note that the term "selectframeworks is not correct. The user can select various files, not only frameworks)
-        
+
         #Framework Selection
         #sql data for import are supposed to be located in installer/data/<language>/<level>
         # Where <language> is en|fr or any international abbreviation (provided language hash is updated... This will be a problem with internationlisation.)
         # Where <level> is a category of requirement : required, recommended optional
         # level should contain :
         #   SQL File for import With a readable name.
-        #   txt File taht explains what this SQL File is meant for.
+        #   txt File that explains what this SQL File is meant for.
         # Could be VERY useful to have A Big file for a kind of library.
         # But could also be useful to have some Authorised values data set prepared here.
         # Framework Selection is achieved through checking boxes.
@@ -313,15 +326,15 @@ elsif ( $step && $step == 3 ) {
         my $marcflavour = $query->param('marcflavour');
         if ($marcflavour){
             $installer->set_marcflavour_syspref($marcflavour);
-        };    
+        };
         $marcflavour = C4::Context->preference('marcflavour') unless ($marcflavour);
         #Insert into database the selected marcflavour
-        undef $/; 
+        undef $/;
         my ($marc_defaulted_to_en, $fwklist) = $installer->marc_framework_sql_list($langchoice, $marcflavour);
         $template->param('en_marc_frameworks' => $marc_defaulted_to_en);
         $template->param( "frameworksloop" => $fwklist );
         $template->param( "marcflavour" => ucfirst($marcflavour));
-       
+
         my ($sample_defaulted_to_en, $levellist) = $installer->sample_data_sql_list($langchoice, $marcflavour);
         $template->param( "en_sample_data" => $sample_defaulted_to_en);
         $template->param( "levelloop" => $levellist );
@@ -333,7 +346,7 @@ elsif ( $step && $step == 3 ) {
         # 1ST install, 2nd sub-step : show the user the marcflavour available.
         #
         #
-        
+
         #Choose Marc Flavour
         #sql data are supposed to be located in installer/data/<dbms>/<language>/marcflavour/marcflavourname
        # Where <dbms> is database type according to DBD syntax
@@ -361,13 +374,13 @@ elsif ( $step && $step == 3 ) {
         }
         my @listdir = grep { !/^\./ && -d "$dir/$_" } readdir(MYDIR);
         closedir MYDIR;
-        my $marcflavour=C4::Context->preference("marcflavour");    
+        my $marcflavour=C4::Context->preference("marcflavour");
         my @flavourlist;
         foreach my $marc (@listdir) {
-            my %cell=(    
+            my %cell=(
             "label"=> ucfirst($marc),
             "code"=>uc($marc),
-            "checked"=> defined($marcflavour) ? uc($marc) eq $marcflavour : 0);      
+            "checked"=> defined($marcflavour) ? uc($marc) eq $marcflavour : 0);
 #             $cell{"description"}= do { local $/ = undef; open INPUT "<$dir/$marc.txt"||"";<INPUT> };
             push @flavourlist, \%cell;
         }
@@ -391,16 +404,20 @@ elsif ( $step && $step == 3 ) {
         # Not 1st install, the only sub-step : update database
         #
         #Do updatedatabase And report
-        my $execstring =
-          C4::Context->config("intranetdir") . "/installer/data/$info{dbms}/updatedatabase.pl";
-        undef $/;
-        my $string = qx($execstring 2>&1 1>/dev/null);                         # added '1>/dev/null' to return only stderr in $string. Needs testing here. -fbcit
-        if ($string) {
-            $string =~ s/\n|\r/<br \/>/g;
-            $string =~
-                s/(DBD::mysql.*? failed: .*? line [0-9]*.|=================.*?====================)/<font color=red>$1<\/font>/g;
-            $template->param( "updatereport" => $string );
+        my $cmd = C4::Context->config("intranetdir") . "/installer/data/$info{dbms}/updatedatabase.pl";
+        my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf) = IPC::Cmd::run(command => $cmd, verbose => 0);
+
+        if (@$stdout_buf) {
+            $template->param(update_report => [ map { { line => $_ } } split(/\n/, join('', @$stdout_buf)) ] );
+            $template->param(has_update_succeeds => 1);
         }
+        if (@$stderr_buf) {
+            $template->param(update_errors => [ map { { line => $_ } } split(/\n/, join('', @$stderr_buf)) ] );
+            $template->param(has_update_errors => 1);
+            warn "The following errors were returned while attempting to run the updatedatabase.pl script:\n";
+            foreach my $line (@$stderr_buf) {warn "$line\n";}
+        }
+
         $template->param( $op => 1 );
     }
     else {