From 47fa09e85c9e3c22fa1c17624f4ddac3a0efb009 Mon Sep 17 00:00:00 2001 From: Chris Nighswonger Date: Wed, 13 Jan 2010 13:33:30 -0500 Subject: [PATCH] Enhancement: Make web installer log errors to error log The web installer should log errors to the error log instead of only dumping them to the browser. This will allow a record of the errors which may be useful for later debugging. --- C4/Installer.pm | 29 ++++++++++++++++------------- installer/install.pl | 2 ++ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/C4/Installer.pm b/C4/Installer.pm index 2e1fe1aaa0..442ea73953 100644 --- a/C4/Installer.pm +++ b/C4/Installer.pm @@ -74,13 +74,13 @@ sub new { $self->{'port'} = C4::Context->config("port"); $self->{'user'} = C4::Context->config("user"); $self->{'password'} = C4::Context->config("pass"); - $self->{'dbh'} = DBI->connect("DBI:$self->{dbms}:dbname=$self->{dbname};host=$self->{hostname}" . + $self->{'dbh'} = DBI->connect("DBI:$self->{dbms}:dbname=$self->{dbname};host=$self->{hostname}" . ( $self->{port} ? ";port=$self->{port}" : "" ), $self->{'user'}, $self->{'password'}); $self->{'language'} = undef; $self->{'marcflavour'} = undef; $self->{'dbh'}->do('set NAMES "utf8"'); - $self->{'dbh'}->{'mysql_enable_utf8'}=1; + $self->{'dbh'}->{'mysql_enable_utf8'}=1; bless $self, $class; return $self; @@ -150,7 +150,7 @@ sub marc_framework_sql_list { } my @listdir = sort grep { !/^\.|marcflavour/ && -d "$dir/$_" } readdir(MYDIR); closedir MYDIR; - + my @fwklist; my $request = $self->{'dbh'}->prepare("SELECT value FROM systempreferences WHERE variable='FrameworksLoaded'"); $request->execute; @@ -192,7 +192,7 @@ sub marc_framework_sql_list { $cell{"code"} = lc($requirelevel); push @fwklist, \%cell; } - + return ($defaulted_to_en, \@fwklist); } @@ -300,9 +300,9 @@ sub sql_file_list { my ($marc_defaulted_to_en, $marc_sql) = $self->marc_framework_sql_list($lang, $marcflavour); my ($sample_defaulted_to_en, $sample_sql) = $self->sample_data_sql_list($lang); - + my @sql_list = (); - map { + map { map { if ($subset_wanted->{'mandatory'}) { push @sql_list, $_->{'fwkfile'} if $_->{'mandatory'}; @@ -312,11 +312,11 @@ sub sql_file_list { } } @{ $_->{'frameworks'} } } (@$marc_sql, @$sample_sql); - + return \@sql_list } -=head2 load_db_schema +=head2 load_db_schema =over 4 @@ -356,7 +356,7 @@ directory path). This means that dependencies among the scripts are to be resolved by carefully naming them, keeping in mind that the directory name does *not* currently count. -FIXME: this is a rather delicate way of dealing with dependencies between +FIXME: this is a rather delicate way of dealing with dependencies between the install scripts. The return value C<$list> is an arrayref containing a hashref for each @@ -429,7 +429,7 @@ sub load_sql_in_order { return ($fwk_language, \@list); } -=head2 set_marcflavour_syspref +=head2 set_marcflavour_syspref =over 4 @@ -462,7 +462,7 @@ sub set_marcflavour_syspref { $request->execute; } -=head2 set_indexing_engine +=head2 set_indexing_engine =over 4 @@ -569,9 +569,12 @@ sub load_sql { . " $self->{dbname} "; # Therefore, be sure to run 'trust' on localhost in pg_hba.conf -fbcit $error = qx($strcmd -f $filename 2>&1 1>/dev/null); # Be sure to set 'client_min_messages = error' in postgresql.conf - # so that only true errors are returned to stderr or else the installer will + # so that only true errors are returned to stderr or else the installer will # report the import a failure although it really succeded -fbcit } +# errors thrown while loading installer data should be logged + warn "C4::Installer::load_sql returned the following errors while attempting to load $filename:\n"; + warn $error; return $error; } @@ -596,7 +599,7 @@ sub get_file_path_from_name { my $partialname = shift; my $lang = 'en'; # FIXME: how do I know what language I want? - + my ($defaulted_to_en, $list) = $self->sample_data_sql_list($lang); # warn( Data::Dumper->Dump( [ $list ], [ 'list' ] ) ); diff --git a/installer/install.pl b/installer/install.pl index 9d2196207a..80d4bc68e6 100755 --- a/installer/install.pl +++ b/installer/install.pl @@ -402,6 +402,8 @@ elsif ( $step && $step == 3 ) { 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 ); -- 2.39.5