From e4963322557f7dfda080e401a5dbcfcc22684020 Mon Sep 17 00:00:00 2001 From: Mason James Date: Thu, 27 Sep 2007 18:03:01 -0500 Subject: [PATCH] adding CGI::Carp handling handle_errors() sub to top of Context.pm Signed-off-by: Chris Cormack --- C4/Context.pm | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/C4/Context.pm b/C4/Context.pm index 7661a5723e..15a09d5e1d 100644 --- a/C4/Context.pm +++ b/C4/Context.pm @@ -18,6 +18,39 @@ package C4::Context; # $Id$ use strict; + +use CGI::Carp qw(fatalsToBrowser set_message); +BEGIN { + sub handle_errors { + my $msg = shift; + my $debug_level = C4::Context->preference("DebugLevel"); + + if ($debug_level eq "2"){ + # debug 2 , print extra info too. + my %versions = get_versions(); + +# a little example table with various version info"; + print " +

debug level $debug_level

+

Got an error: $msg

+ + + + + + +
Apache $versions{apacheVersion}
Koha $versions{kohaVersion}
MySQL $versions{mysqlVersion}
OS $versions{osVersion}
Perl $versions{perlVersion}
"; + + } elsif ($debug_level eq "1"){ + print "

debug level $debug_level

"; + print "

Got an error: $msg

"; + } else { + print "production mode - trapped fatal"; + } + } + set_message(\&handle_errors); +} + use DBI; use ZOOM; use XML::Simple; @@ -860,6 +893,31 @@ sub _unset_userenv } +=item get_versions + + C4::Context->get_versions + +Gets various version info, for core Koha packages, Currently called from carp handle_errors() sub, to send to browser if 'DebugLevel' syspref is set to '2'. + +=cut + +#' + +# A little example sub to show more debugging info for CGI::Carp +sub get_versions { + my %versions; + $versions{kohaVersion} = C4::Context->config("kohaversion"); + $versions{osVersion} = `uname -a`; + $versions{perlVersion} = $]; + $versions{mysqlVersion} = `mysql -V`; + $versions{apacheVersion} = `httpd -v`; + $versions{apacheVersion} = `httpd2 -v` unless $versions{apacheVersion} ; + $versions{apacheVersion} = `apache2 -v` unless $versions{apacheVersion} +; + $versions{apacheVersion} = `/usr/sbin/apache2 -v` unless $versions{apacheVersion} ; + return %versions; +} + 1; __END__ -- 2.39.5