X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;ds=sidebyside;f=installer%2Finstall.pl;h=508496aa66d7e52df204337c5134faf3aef802e3;hb=a191bcaf323f7effd66e7b46dfdcbd722ba0a647;hp=d9feac4b4373c634ac8b6cedf0758528938248dc;hpb=98a207ef955effae8d6b26a1c74bddd9a3c9a801;p=koha.git diff --git a/installer/install.pl b/installer/install.pl index d9feac4b43..508496aa66 100755 --- a/installer/install.pl +++ b/installer/install.pl @@ -4,9 +4,9 @@ use strict; use warnings; use diagnostics; -use InstallAuth; -use CGI; -use IPC::Cmd; +use C4::InstallAuth; +use CGI qw ( -utf8 ); +use POSIX qw(strftime); use C4::Context; use C4::Output; @@ -14,6 +14,8 @@ use C4::Templates; use C4::Languages qw(getAllLanguages getTranslatedLanguages); use C4::Installer; +use Koha; + my $query = new CGI; my $step = $query->param('step'); @@ -27,7 +29,7 @@ if ( defined($language) ) { } ( $template, $loggedinuser, $cookie ) = get_template_and_user( { - template_name => "installer/step" . ( $step ? $step : 1 ) . ".tmpl", + template_name => "installer/step" . ( $step ? $step : 1 ) . ".tt", query => $query, type => "intranet", authnotrequired => 0, @@ -46,16 +48,27 @@ $info{'hostname'} = C4::Context->config("hostname"); $info{'port'} = C4::Context->config("port"); $info{'user'} = C4::Context->config("user"); $info{'password'} = C4::Context->config("pass"); +$info{'tls'} = C4::Context->config("tls"); + if ($info{'tls'} && $info{'tls'} eq 'yes'){ + $info{'ca'} = C4::Context->config('ca'); + $info{'cert'} = C4::Context->config('cert'); + $info{'key'} = C4::Context->config('key'); + $info{'tlsoptions'} = ";mysql_ssl=1;mysql_ssl_client_key=".$info{key}.";mysql_ssl_client_cert=".$info{cert}.";mysql_ssl_ca_file=".$info{ca}; + $info{'tlscmdline'} = " --ssl-cert ". $info{cert} . " --ssl-key " . $info{key} . " --ssl-ca ".$info{ca}." " + } + my $dbh = DBI->connect( "DBI:$info{dbms}:dbname=$info{dbname};host=$info{hostname}" - . ( $info{port} ? ";port=$info{port}" : "" ), + . ( $info{port} ? ";port=$info{port}" : "" ) + . ( $info{tlsoptions} ? $info{tlsoptions} : "" ), $info{'user'}, $info{'password'} ); if ( $step && $step == 1 ) { - #First Step + #First Step (for both fresh installations and upgrades) #Checking ALL perl Modules and services needed are installed. #Whenever there is an error, adding a report to the page + my $op = $query->param('op') || 'noop'; $template->param( language => 1 ); $template->param( 'checkmodule' => 1 ); # we start with the assumption that there are no problems and set this to 0 if there are @@ -64,7 +77,7 @@ if ( $step && $step == 1 ) { } my $perl_modules = C4::Installer::PerlModules->new; - $perl_modules->version_info; + $perl_modules->versions_info; my $modules = $perl_modules->get_attr('missing_pm'); if (scalar(@$modules)) { @@ -84,7 +97,7 @@ if ( $step && $step == 1 ) { ); } @components = sort {$a->{'name'} cmp $b->{'name'}} @components; - $template->param( missing_modules => \@components, checkmodule => $checkmodule ); + $template->param( missing_modules => \@components, checkmodule => $checkmodule, op => $op ); } } elsif ( $step && $step == 2 ) { @@ -189,7 +202,6 @@ elsif ( $step && $step == 3 ) { } elsif ( $op && $op eq 'finish' ) { $installer->set_version_syspref(); - $installer->set_indexing_engine(0); # use Zebra # Installation is finished. # We just deny anybody access to install @@ -207,6 +219,8 @@ elsif ( $step && $step == 3 ) { "fwklanguage" => $fwk_language, "list" => $list ); + use Koha::SearchEngine::Elasticsearch; + Koha::SearchEngine::Elasticsearch->reset_elasticsearch_mappings; $template->param( "$op" => 1 ); } elsif ( $op && $op eq 'selectframeworks' ) { @@ -242,7 +256,7 @@ elsif ( $step && $step == 3 ) { $template->param( "frameworksloop" => $fwklist ); $template->param( "marcflavour" => ucfirst($marcflavour)); - my ($sample_defaulted_to_en, $levellist) = $installer->sample_data_sql_list($langchoice, $marcflavour); + my ($sample_defaulted_to_en, $levellist) = $installer->sample_data_sql_list($langchoice); $template->param( "en_sample_data" => $sample_defaulted_to_en); $template->param( "levelloop" => $levellist ); $template->param( "$op" => 1 ); @@ -313,28 +327,48 @@ elsif ( $step && $step == 3 ) { # #Do updatedatabase And report - 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"; - } + 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"; - my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf) = IPC::Cmd::run(command => $cmd, verbose => 0); + my $cmd = C4::Context->config("intranetdir") . "/installer/data/$info{dbms}/updatedatabase.pl >> $logfilepath 2>> $logfilepath_errors"; - if (@$stdout_buf) { - $template->param(update_report => [ map { { line => $_ } } split(/\n/, join('', @$stdout_buf)) ] ); - $template->param(has_update_succeeds => 1); + system($cmd ); + + my $fh; + open( $fh, "<", $logfilepath ) or die "Cannot open log file $logfilepath: $!"; + my @report = <$fh>; + close $fh; + if (@report) { + $template->param( update_report => [ map { { line => $_ } } split( /\n/, join( '', @report ) ) ] ); + $template->param( has_update_succeeds => 1 ); + } else { + eval{ `rm $logfilepath` }; } - if (@$stderr_buf) { - $template->param(update_errors => [ map { { line => $_ } } split(/\n/, join('', @$stderr_buf)) ] ); - $template->param(has_update_errors => 1); + open( $fh, "<", $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 (@$stderr_buf) {warn "$line\n";} + foreach my $line (@report) { warn "$line\n"; } + } else { + eval{ `rm $logfilepath_errors` }; } - $template->param( $op => 1 ); } else { @@ -346,7 +380,8 @@ elsif ( $step && $step == 3 ) { #I put it there because it implied a data import if condition was not satisfied. my $dbh = DBI->connect( "DBI:$info{dbms}:dbname=$info{dbname};host=$info{hostname}" - . ( $info{port} ? ";port=$info{port}" : "" ), + . ( $info{port} ? ";port=$info{port}" : "" ) + . ( $info{tlsoptions} ? $info{tlsoptions} : "" ), $info{'user'}, $info{'password'} ); my $rq; @@ -379,12 +414,10 @@ elsif ( $step && $step == 3 ) { $dbversion = "$1.$2.$3.$4"; $template->param("upgrading" => 1, "dbversion" => $dbversion, - "kohaversion" => C4::Context->KOHAVERSION, + "kohaversion" => Koha::version(), ); } } - - $dbh->disconnect; } } else { @@ -400,10 +433,22 @@ else { if ( $rq->execute ) { my ($version) = $rq->fetchrow; if ($version) { - $query->redirect("install.pl?step=3"); - exit; + print $query->redirect("/cgi-bin/koha/installer/install.pl?step=3"); + exit; } } } } output_html_with_http_headers $query, $cookie, $template->output; + +sub chk_log { #returns a logfile in $dir or - if that failed - in temp dir + my ($dir, $name) = @_; + my $fn=$dir.'/'.$name.'.log'; + if( ! open my $fh, '>', $fn ) { + $name.= '_XXXX'; + require File::Temp; + ($fh, $fn)= File::Temp::tempfile( $name, TMPDIR => 1, SUFFIX => '.log'); + #if this should not work, let croak take over + } + return $fn; +}