Bug 10403: (follow-up) fix test to use vendor created earlier during test
[koha.git] / C4 / Debug.pm
index ef4484c..b735ab8 100644 (file)
@@ -13,21 +13,21 @@ package C4::Debug;
 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 #
-# You should have received a copy of the GNU General Public License along with
-# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
-# Suite 330, Boston, MA  02111-1307 USA
+# You should have received a copy of the GNU General Public License along
+# with Koha; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 use strict;
 use warnings;
 
 use Exporter;
 
-use CGI;
+use CGI;
 use vars qw($VERSION @ISA @EXPORT $debug $cgi_debug);
 # use vars qw(@EXPORT_OK %EXPORT_TAGS);
 
 BEGIN {
-       $VERSION = 1.00;        # set the version for version checking
+    $VERSION = 3.07.00.049;    # set the version for version checking
        @ISA       = qw(Exporter);
        @EXPORT    = qw($debug $cgi_debug);
        # @EXPOR_OK    = qw();
@@ -37,15 +37,29 @@ BEGIN {
 BEGIN {
        # this stuff needs a begin block too, since dependencies might alter their compilations
        # for example, adding DataDumper
-       my $query = CGI->new();
+
        $debug = $ENV{KOHA_DEBUG} || $ENV{DEBUG} || 0;
-       $cgi_debug = $ENV{KOHA_CGI_DEBUG} || $query->param('debug') || 0;
-       unless (0 <= $debug and $debug <= 9) {
+
+       # CGI->new conflicts w/ some upload functionality, 
+       # since we would get the "first" CGI object here.
+       # Instead we have to parse for ourselves if we want QUERY_STRING triggers.
+       #       my $query = CGI->new();         # conflicts!
+       #       $cgi_debug = $ENV{KOHA_CGI_DEBUG} || $query->param('debug') || 0;
+
+       $cgi_debug = $ENV{KOHA_CGI_DEBUG} || 0;
+       unless ($cgi_debug or not $ENV{QUERY_STRING}) {
+               foreach (split /\&/,  $ENV{QUERY_STRING}) {
+                       /^debug\=(.+)$/ or next;
+                       $cgi_debug = $1;
+                       last;
+               }
+       }
+       unless ($debug =~ /^\d$/) {
                warn "Invalid \$debug value attempted: $debug";
                $debug=1;
        }
-       unless (0 <= $cgi_debug and $cgi_debug <= 9) {
-               $debug and 
+       unless ($cgi_debug =~ /^\d$/) {
+               $debug and
                warn "Invalid \$cgi_debug value attempted: $cgi_debug";
                $cgi_debug=1;
        }
@@ -60,8 +74,8 @@ BEGIN {
 __END__
 
 =head1 NAME 
-       
-       C4::Debug - Standardized, centralized, exported debug switches.
+
+C4::Debug - Standardized, centralized, exported debug switches.
 
 =head1 SYNOPSIS
 
@@ -102,7 +116,7 @@ The general purpose debug switch.
 =over
 
 =item environmental variable DEBUG or KOHA_DEBUG.  In bash, you might do:
-       
+
        export KOHA_DEBUG=1;
        perl t/Auth.t;
 
@@ -125,7 +139,7 @@ command with ERROR_LOG enabled for your VirtualHost.  Not intended for productio
 
 =over
 
-=item From a web browser, for example by supplying a non-zero debug parameter:
+=item From a web browser, for example by supplying a non-zero debug parameter (1 to 9):
 
        http://www.mylibrary.org/cgi-bin/koha/opac-search.pl?q=history&debug=1
 
@@ -138,12 +152,15 @@ command with ERROR_LOG enabled for your VirtualHost.  Not intended for productio
 =back 
 
 The former methods mean $cgi_debug is exposed.  Do NOT use it to trigger any actions that you would
-not allow a (potentially anonymous) end user to perform.  
+not allow a (potentially anonymous) end user to perform.  Dumping sensitive data, directory listings, or 
+emailing yourself a test message would all be bad actions to tie to $cgi_debug.
 
 =head1 OTHER SOURCES of Debug Switches
 
 =head2 System Preferences
 
+=cut
+
 =head2 Database Debug
 
 Debugging at the database level might be useful.  Koha does not currently integrate any such