From f698899ab6802f378634d6a363006767233170ab Mon Sep 17 00:00:00 2001 From: JT Smith Date: Thu, 8 Aug 2002 03:50:02 +0000 Subject: [PATCH] Added a debug mode. --- docs/upgrades/upgrade_4.4.1-4.5.0.sql | 4 +- lib/WebGUI.pm | 55 +++++++++++++++------------ lib/WebGUI/ErrorHandler.pm | 1 + lib/WebGUI/Operation/Settings.pm | 2 + 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/docs/upgrades/upgrade_4.4.1-4.5.0.sql b/docs/upgrades/upgrade_4.4.1-4.5.0.sql index 70dde00a5..5139da48a 100644 --- a/docs/upgrades/upgrade_4.4.1-4.5.0.sql +++ b/docs/upgrades/upgrade_4.4.1-4.5.0.sql @@ -27,8 +27,8 @@ insert into international values (76,'EventsCalendar',1,'Delete only this event. insert into international values (77,'EventsCalendar',1,'Delete this event and all of its recurrences.'); insert into international values (78,'EventsCalendar',1,'Don\'t delete anything, I made a mistake.'); update wobject set editTimeout=editTimeout*3600; - - +insert into international values (707,"WebGUI",1,"Show debugging?"); +insert into settings values ('showDebug',0); diff --git a/lib/WebGUI.pm b/lib/WebGUI.pm index 0f484cd8f..3cba31510 100644 --- a/lib/WebGUI.pm +++ b/lib/WebGUI.pm @@ -29,21 +29,6 @@ sub page { my ($debug, %contentHash, $w, $cmd, $pageEdit, $wobject, $wobjectOutput, $extra, $originalWobject, $proxyWobjectId, $sth, $httpHeader, $header, $footer, $content, $operationOutput, $adminBar, %hash); WebGUI::Session::open($_[0],$_[1]); - if ($session{form}{debug}==1 && WebGUI::Privilege::isInGroup(3)) { - $debug = ''; - while (my ($section, $hash) = each %session) { - while (my ($key, $value) = each %$hash) { - if (ref $value eq 'ARRAY') { - $value = '['.join(', ',@$value).']'; - } elsif (ref $value eq 'HASH') { - $value = '{'.join(', ',map {"$_ => $value->{$_}"} keys %$value).'}'; - } - $debug .= ''; - } - $debug .= ''; - } - $debug .='
'.$section.'.'.$key.':'.$value.'
  
'; - } if (exists $session{form}{op}) { $cmd = "WebGUI::Operation::www_".$session{form}{op}; $operationOutput = eval($cmd); @@ -55,11 +40,13 @@ sub page { } else { $wobject = WebGUI::SQL->quickHashRef("select * from wobject where wobjectId=".$session{form}{wid}); if (${$wobject}{namespace} eq "") { - WebGUI::ErrorHandler::warn("Wobject [$session{form}{wid}] appears to be missing or corrupt, but was requested " + WebGUI::ErrorHandler::warn("Wobject [$session{form}{wid}] appears to be missing or " + ."corrupt, but was requested " ."by $session{user}{username} [$session{user}{userId}]."); $wobject = (); } else { - $extra = WebGUI::SQL->quickHashRef("select * from ${$wobject}{namespace} where wobjectId=${$wobject}{wobjectId}"); + $extra = WebGUI::SQL->quickHashRef("select * from ${$wobject}{namespace} + where wobjectId=${$wobject}{wobjectId}"); tie %hash, 'Tie::CPHash'; %hash = (%{$wobject},%{$extra}); $wobject = \%hash; @@ -68,21 +55,24 @@ sub page { if ($wobject) { if (${$wobject}{pageId} != $session{page}{pageId}) { ($proxyWobjectId) = WebGUI::SQL->quickArray("select wobject.wobjectId from wobject,WobjectProxy - where wobject.wobjectId=WobjectProxy.wobjectId and wobject.pageId=".$session{page}{pageId}." + where wobject.wobjectId=WobjectProxy.wobjectId + and wobject.pageId=".$session{page}{pageId}." and WobjectProxy.proxiedWobjectId=".${$wobject}{wobjectId}); ${$wobject}{_WobjectProxy} = $proxyWobjectId; } unless (${$wobject}{pageId} == $session{page}{pageId} || ${$wobject}{pageId} == 2 || ${$wobject}{_WobjectProxy} ne "") { $wobjectOutput .= WebGUI::International::get(417); - WebGUI::ErrorHandler::warn($session{user}{username}." [".$session{user}{userId}."] attempted to access wobject [" - .$session{form}{wid}."] on page '".$session{page}{title}."' [".$session{page}{pageId}."]."); + WebGUI::ErrorHandler::warn($session{user}{username}." [".$session{user}{userId} + ."] attempted to access wobject [" + .$session{form}{wid}."] on page '".$session{page}{title}."' [" + .$session{page}{pageId}."]."); } else { $cmd = "WebGUI::Wobject::".${$wobject}{namespace}; $w = eval{$cmd->new($wobject)}; - WebGUI::ErrorHandler::fatalError("Couldn't instanciate wojbect: ${$wobject}{namespace}.") if($@); + WebGUI::ErrorHandler::fatalError("Couldn't instanciate wojbect: ${$wobject}{namespace}. Root Cause: ".$@) if($@); $cmd = "www_".$session{form}{func}; $wobjectOutput = eval{$w->$cmd}; - WebGUI::ErrorHandler::fatalError("Web method doesn't exist in wojbect: ${$wobject}{namespace} / $session{form}{func}.") if($@); + WebGUI::ErrorHandler::fatalError("Web method doesn't exist in wojbect: ${$wobject}{namespace} / $session{form}{func}. Root Cause: ".$@) if($@); } } } @@ -135,12 +125,12 @@ sub page { $wobject = \%hash; $cmd = "WebGUI::Wobject::".${$wobject}{namespace}; $w = eval{$cmd->new($wobject)}; - WebGUI::ErrorHandler::fatalError("Couldn't instanciate wojbect: ${$wobject}{namespace}.") if($@); + WebGUI::ErrorHandler::fatalError("Couldn't instanciate wojbect: ${$wobject}{namespace}. Root cause: ".$@) if($@); if ($w->inDateRange) { $contentHash{${$wobject}{templatePosition}} .= '
'; $contentHash{${$wobject}{templatePosition}} .= ''; $contentHash{${$wobject}{templatePosition}} .= eval{$w->www_view}; - WebGUI::ErrorHandler::fatalError("No view method in wojbect: ${$wobject}{namespace}.") if($@); + WebGUI::ErrorHandler::fatalError("No view method in wojbect: ${$wobject}{namespace}. Root cause: ".$@) if($@); $contentHash{${$wobject}{templatePosition}} .= "
\n\n"; } } @@ -151,6 +141,23 @@ sub page { $content = WebGUI::Template::generate(\%contentHash,1); } } + if ($session{setting}{showDebug} || ($session{form}{debug}==1 && WebGUI::Privilege::isInGroup(3))) { + $debug = '
' + .$session{debug}{warning}.'
'; + $debug .= ''; + while (my ($section, $hash) = each %session) { + while (my ($key, $value) = each %$hash) { + if (ref $value eq 'ARRAY') { + $value = '['.join(', ',@$value).']'; + } elsif (ref $value eq 'HASH') { + $value = '{'.join(', ',map {"$_ => $value->{$_}"} keys %$value).'}'; + } + $debug .= ''; + } + $debug .= ''; + } + $debug .='
'.$section.'.'.$key.':'.$value.'
  
'; + } if ($session{header}{redirect} ne "") { return $session{header}{redirect}; } else { diff --git a/lib/WebGUI/ErrorHandler.pm b/lib/WebGUI/ErrorHandler.pm index 8cf11131f..0a5c7c144 100644 --- a/lib/WebGUI/ErrorHandler.pm +++ b/lib/WebGUI/ErrorHandler.pm @@ -84,6 +84,7 @@ sub warn { } $log = FileHandle->new(">>".$logfile) or fatalError("Can't open log file for warning."); print $log localtime(time)." ".$0." WARNING: ".$_[0]."\n"; + $session{debug}{warning} .= localtime(time)." ".$0." WARNING: ".$_[0]."

"; $log->close; } diff --git a/lib/WebGUI/Operation/Settings.pm b/lib/WebGUI/Operation/Settings.pm index 2121de857..bbeb1cbf9 100644 --- a/lib/WebGUI/Operation/Settings.pm +++ b/lib/WebGUI/Operation/Settings.pm @@ -210,6 +210,7 @@ sub www_editMiscSettings { $f = WebGUI::HTMLForm->new; $f->hidden("op","editMiscSettingsSave"); $f->yesNo("preventProxyCache",WebGUI::International::get(400),$session{setting}{preventProxyCache}); + $f->yesNo("showDebug",WebGUI::International::get(707),$session{setting}{showDebug}); $f->select("onCriticalError",\%criticalError,WebGUI::International::get(413),[$session{setting}{onCriticalError}]); $f->submit; $output .= $f->print; @@ -223,6 +224,7 @@ sub www_editMiscSettings { sub www_editMiscSettingsSave { if (WebGUI::Privilege::isInGroup(3)) { _saveSetting("preventProxyCache"); + _saveSetting("showDebug"); _saveSetting("onCriticalError"); return www_manageSettings(); } else {