From d7b1a575ccef91f704b1573c431235441d52e47d Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 17 Feb 2009 02:28:48 +0000 Subject: [PATCH] per-user preference for turning on profiling display when DBIx::Profile is loaded, RT#4830 --- FS/FS/Mason.pm | 84 ++++++++++++++++++++++++++------------- httemplate/autohandler | 5 ++- httemplate/pref/pref-process.html | 3 +- httemplate/pref/pref.html | 4 ++ 4 files changed, 66 insertions(+), 30 deletions(-) diff --git a/FS/FS/Mason.pm b/FS/FS/Mason.pm index e0f58b814..ee777a485 100644 --- a/FS/FS/Mason.pm +++ b/FS/FS/Mason.pm @@ -233,20 +233,35 @@ Initializes the Mason environment, loads all Freeside and RT libraries, etc. use vars qw($m); # false laziness w/below - if ( defined(@DBIx::Profile::ISA) ) { #profiling redirect - - my $page = - qq!Redirect to $location!. - '

'.
-          ( UNIVERSAL::can(dbh, 'sprintProfile')
-              ? encode_entities(dbh->sprintProfile())
-              : 'DBIx::Profile missing sprintProfile method;'.
-                'unpatched or too old?'                        ).
-        #"\n\n". &sprintAutoProfile().  '
'. - "\n\n". ''. - ''; - dbh->{'private_profile'} = {}; - return $page; + if ( defined(@DBIx::Profile::ISA) ) { + + if ( $FS::CurrentUser::CurrentUser->option('show_db_profile') ) { + + #profiling redirect + + my $page = + qq!Redirect to $location!. + '

'.
+            ( UNIVERSAL::can(dbh, 'sprintProfile')
+                ? encode_entities(dbh->sprintProfile())
+                : 'DBIx::Profile missing sprintProfile method;'.
+                  'unpatched or too old?'                        ).
+          #"\n\n". &sprintAutoProfile().  '
'. + "\n\n". ''. + ''; + + + dbh->{'private_profile'} = {}; + return $page; + + } else { + + #clear db profile, but normal redirect + dbh->{'private_profile'} = {}; + $m->redirect($location); + ''; + + } } else { #normal redirect @@ -272,20 +287,33 @@ Initializes the Mason environment, loads all Freeside and RT libraries, etc. use vars qw($m); $m->clear_buffer; #false laziness w/above - if ( defined(@DBIx::Profile::ISA) ) { #profiling redirect - - $m->print( - qq!Redirect to $location!. - '

'.
-          ( UNIVERSAL::can(dbh, 'sprintProfile')
-              ? encode_entities(dbh->sprintProfile())
-              : 'DBIx::Profile missing sprintProfile method;'.
-                'unpatched or too old?'                        ).
-        #"\n\n". &sprintAutoProfile().  '
'. - "\n\n". ''. - '' - ); - dbh->{'private_profile'} = {}; + if ( defined(@DBIx::Profile::ISA) ) { + + if ( $FS::CurrentUser::CurrentUser->option('show_db_profile') ) { + + #profiling redirect + + $m->print( + qq!Redirect to $location!. + '

'.
+            ( UNIVERSAL::can(dbh, 'sprintProfile')
+                ? encode_entities(dbh->sprintProfile())
+                : 'DBIx::Profile missing sprintProfile method;'.
+                  'unpatched or too old?'                        ).
+          #"\n\n". &sprintAutoProfile().  '
'. + "\n\n". ''. + '' + ); + + dbh->{'private_profile'} = {}; + + } else { + + #clear db profile, but normal redirect + dbh->{'private_profile'} = {}; + $m->redirect($location); + + } } else { #normal redirect diff --git a/httemplate/autohandler b/httemplate/autohandler index bdea50534..ee37934cf 100644 --- a/httemplate/autohandler +++ b/httemplate/autohandler @@ -7,7 +7,10 @@ my $profile = ''; if ( UNIVERSAL::can(dbh, 'sprintProfile') ) { - if ( lc($r->content_type) eq 'text/html' ) { + if ( lc($r->content_type) eq 'text/html' + && $FS::CurrentUser::CurrentUser->option('show_db_profile') + ) + { ## barely worth it, just in case someone tries to use profiling on a ## non-RT install diff --git a/httemplate/pref/pref-process.html b/httemplate/pref/pref-process.html index 09eb71a7e..466218947 100644 --- a/httemplate/pref/pref-process.html +++ b/httemplate/pref/pref-process.html @@ -30,9 +30,10 @@ % my %param = $access_user->options; % % #XXX autogen -% my @paramlist = qw( menu_position show_pkgnum +% my @paramlist = qw( menu_position % email_address % vonage-fromnumber vonage-username vonage-password +% show_pkgnum show_db_profile % height width availHeight availWidth colorDepth % ); % diff --git a/httemplate/pref/pref.html b/httemplate/pref/pref.html index 4007bb9f1..44b844891 100644 --- a/httemplate/pref/pref.html +++ b/httemplate/pref/pref.html @@ -64,6 +64,10 @@ Development Show internal package numbers: option('show_pkgnum') ? 'CHECKED' : '' %>> + + Show database profiling (when available): + option('show_db_profile') ? 'CHECKED' : '' %>> +
-- 2.11.0