From 5494f687372570c9d1c5eb5c6aad73767e50820a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Fri, 14 Oct 2011 13:53:35 +0200 Subject: [PATCH] $::cgi entfernt. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Verfahren: - Für alle Vorkommen von "my $cgi = $::cgi;": ersetzt durch my $cgi = $::request->{cgi}->new({}) ersetzt - Wenn in einer Datei alle my $cgi rausgefallen sind auch use CGI entfernt. - Initialisierung von $::cgi in scripts und Dispatcher entfernt und in dei Initialisierung von $::request eingebaut. - cgi aus der Liste der kanonischen globals genommen. Zu CGI: - CGI::func und CGI->func sind beides valide Werte, sind aber intern buggy wie Hölle. CGI:: erzeugt ein Dummyobjekt mit CGI->new, und klobbert damit cookies. CGI-> ist noch schlimmer und ruft ${CGI}->{.cookies} auf. - CGI->new({}) ist schneller als CGI->new(''), deshalb habe ich diese version genommen. Auf meinem Rechner schafft die erste Version etwa 32k/s, die zweite 28k/s. - CGI kompiliert benötigte Funktionen beim ersten Aufruf über AUTOLOAD. - cookie benötigen ein $cgi Objekt. --- SL/Auth.pm | 5 +---- SL/Controller/Base.pm | 2 +- SL/Controller/DebugMenu.pm | 4 ++-- SL/Dispatcher.pm | 9 ++++----- SL/Form.pm | 13 +++++-------- bin/mozilla/admin.pl | 2 -- bin/mozilla/ap.pl | 4 ++-- bin/mozilla/ar.pl | 6 +++--- bin/mozilla/dn.pl | 2 +- bin/mozilla/do.pl | 2 +- bin/mozilla/fu.pl | 2 +- bin/mozilla/gl.pl | 8 ++++---- bin/mozilla/io.pl | 4 ++-- bin/mozilla/ir.pl | 2 +- bin/mozilla/is.pl | 4 ++-- bin/mozilla/login.pl | 1 - bin/mozilla/oe.pl | 4 ++-- bin/mozilla/rp.pl | 4 ++-- bin/mozilla/sepa.pl | 4 ++-- bin/mozilla/vk.pl | 5 ++--- scripts/console | 3 +-- scripts/rose_auto_create_model.pl | 4 +--- scripts/task_server.pl | 3 +-- t/structure/globals.t | 2 +- 24 files changed, 42 insertions(+), 57 deletions(-) diff --git a/SL/Auth.pm b/SL/Auth.pm index e2b54906c..7ca8d0bfd 100644 --- a/SL/Auth.pm +++ b/SL/Auth.pm @@ -511,10 +511,7 @@ sub restore_session { my $self = shift; - my $cgi = $main::cgi; - $cgi ||= CGI->new(''); - - $session_id = $cgi->cookie($self->get_session_cookie_name()); + $session_id = $::request->{cgi}->cookie($self->get_session_cookie_name()); $session_id =~ s|[^0-9a-f]||g; $self->{SESSION} = { }; diff --git a/SL/Controller/Base.pm b/SL/Controller/Base.pm index 198f16e0f..6d9434742 100644 --- a/SL/Controller/Base.pm +++ b/SL/Controller/Base.pm @@ -30,7 +30,7 @@ sub redirect_to { my $self = shift; my $url = $self->url_for(@_); - print $::cgi->redirect($url); + print $::request->{cgi}->redirect($url); } sub render { diff --git a/SL/Controller/DebugMenu.pm b/SL/Controller/DebugMenu.pm index 0e536760a..79b3cd5d7 100644 --- a/SL/Controller/DebugMenu.pm +++ b/SL/Controller/DebugMenu.pm @@ -9,7 +9,7 @@ __PACKAGE__->run_before(sub { die 'not allowed in config' unless $::lx_office_co sub action_reload { my ($self, %params) = @_; - print $::cgi->redirect('controller.pl?action=FrameHeader/header'); + print $::request->{cgi}->redirect('controller.pl?action=FrameHeader/header'); exit; } @@ -17,7 +17,7 @@ sub action_toggle { my ($self, %params) = @_; $::lxdebug->level_by_name($::form->{level}, !$::lxdebug->level_by_name($::form->{level})); - print $::cgi->redirect('controller.pl?action=FrameHeader/header'); + print $::request->{cgi}->redirect('controller.pl?action=FrameHeader/header'); return; } diff --git a/SL/Dispatcher.pm b/SL/Dispatcher.pm index cfb4fb834..e9f7dac09 100644 --- a/SL/Dispatcher.pm +++ b/SL/Dispatcher.pm @@ -168,11 +168,10 @@ sub handle_request { $self->unrequire_bin_mozilla; - $::cgi = CGI->new(''); $::locale = Locale->new($::lx_office_conf{system}->{language}); $::form = Form->new; $::instance_conf = SL::InstanceConfiguration->new; - $::request = { }; + $::request = { cgi => CGI->new({}) }; my $session_result = $::auth->restore_session; $::auth->create_or_refresh_session; @@ -240,7 +239,7 @@ sub handle_request { } or do { if ($EVAL_ERROR ne END_OF_REQUEST) { print STDERR $EVAL_ERROR; - $::form->{label_error} = $::cgi->pre($EVAL_ERROR); + $::form->{label_error} = $::request->{cgi}->pre($EVAL_ERROR); eval { show_error('generic/error') }; } }; @@ -311,7 +310,7 @@ sub _route_dispatcher_request { 1; } or do { - $::form->{label_error} = $::cgi->pre($EVAL_ERROR); + $::form->{label_error} = $::request->{cgi}->pre($EVAL_ERROR); show_error('generic/error'); }; @@ -328,7 +327,7 @@ sub _route_controller_request { 1; } or do { - $::form->{label_error} = $::cgi->pre($EVAL_ERROR); + $::form->{label_error} = $::request->{cgi}->pre($EVAL_ERROR); show_error('generic/error'); }; diff --git a/SL/Form.pm b/SL/Form.pm index b9ba6942f..c7539354c 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -464,11 +464,11 @@ sub hide_form { my $self = shift; if (@_) { - map({ print($main::cgi->hidden("-name" => $_, "-default" => $self->{$_}) . "\n"); } @_); + map({ print($::request->{cgi}->hidden("-name" => $_, "-default" => $self->{$_}) . "\n"); } @_); } else { for (sort keys %$self) { next if (($_ eq "header") || (ref($self->{$_}) ne "")); - print($main::cgi->hidden("-name" => $_, "-default" => $self->{$_}) . "\n"); + print($::request->{cgi}->hidden("-name" => $_, "-default" => $self->{$_}) . "\n"); } } $main::lxdebug->leave_sub(); @@ -624,8 +624,7 @@ sub create_http_response { my $self = shift; my %params = @_; - my $cgi = $main::cgi; - $cgi ||= CGI->new(''); + my $cgi = $::request->{cgi}; my $session_cookie; if (defined $main::auth) { @@ -762,8 +761,7 @@ sub ajax_response_header { my ($self) = @_; my $db_charset = $::lx_office_conf{system}->{dbcharset} || Common::DEFAULT_CHARSET; - my $cgi = $main::cgi || CGI->new(''); - my $output = $cgi->header('-charset' => $db_charset); + my $output = $::request->{cgi}->header('-charset' => $db_charset); $main::lxdebug->leave_sub(); @@ -780,8 +778,7 @@ sub redirect_header { die "Headers already sent" if $self->{header}; $self->{header} = 1; - my $cgi = $main::cgi || CGI->new(''); - return $cgi->redirect($new_uri); + return $::request->{cgi}->redirect($new_uri); } sub set_standard_title { diff --git a/bin/mozilla/admin.pl b/bin/mozilla/admin.pl index e78842751..2472f6c6c 100755 --- a/bin/mozilla/admin.pl +++ b/bin/mozilla/admin.pl @@ -33,7 +33,6 @@ #====================================================================== use DBI; -use CGI; use Encode; use English qw(-no_match_vars); use Fcntl; @@ -68,7 +67,6 @@ sub run { $::lxdebug->enter_sub; my $session_result = shift; - $cgi = $::cgi; $form = $::form; $locale = $::locale; $auth = $::auth; diff --git a/bin/mozilla/ap.pl b/bin/mozilla/ap.pl index 361d43272..6d24657f3 100644 --- a/bin/mozilla/ap.pl +++ b/bin/mozilla/ap.pl @@ -195,7 +195,7 @@ sub form_header { my $form = $main::form; my %myconfig = %main::myconfig; my $locale = $main::locale; - my $cgi = $main::cgi; + my $cgi = $::request->{cgi}; $main::auth->assert('general_ledger'); @@ -836,7 +836,7 @@ sub form_footer { my $form = $main::form; my %myconfig = %main::myconfig; my $locale = $main::locale; - my $cgi = $main::cgi; + my $cgi = $::request->{cgi}; $main::auth->assert('general_ledger'); diff --git a/bin/mozilla/ar.pl b/bin/mozilla/ar.pl index 2f2f55e56..1522339b8 100644 --- a/bin/mozilla/ar.pl +++ b/bin/mozilla/ar.pl @@ -215,7 +215,7 @@ sub form_header { my $form = $main::form; my %myconfig = %main::myconfig; my $locale = $main::locale; - my $cgi = $main::cgi; + my $cgi = $::request->{cgi}; my ($title, $readonly, $exchangerate, $rows); my ($taxincluded, $notes, $department, $customer, $employee, $amount, $project); @@ -879,7 +879,7 @@ sub form_footer { my $form = $main::form; my %myconfig = %main::myconfig; my $locale = $main::locale; - my $cgi = $main::cgi; + my $cgi = $::request->{cgi}; my ($transdate, $closedto); @@ -1332,7 +1332,7 @@ sub search { my $form = $main::form; my %myconfig = %main::myconfig; my $locale = $main::locale; - my $cgi = $main::cgi; + my $cgi = $::request->{cgi}; my ($customer, $department); my ($jsscript, $button1, $button2, $onload); diff --git a/bin/mozilla/dn.pl b/bin/mozilla/dn.pl index 063f9da4f..132286fbd 100644 --- a/bin/mozilla/dn.pl +++ b/bin/mozilla/dn.pl @@ -316,7 +316,7 @@ sub show_dunning { my $form = $main::form; my %myconfig = %main::myconfig; my $locale = $main::locale; - my $cgi = $main::cgi; + my $cgi = $::request->{cgi}; $main::auth->assert('dunning_edit'); diff --git a/bin/mozilla/do.pl b/bin/mozilla/do.pl index 54c650c31..7924b05a2 100644 --- a/bin/mozilla/do.pl +++ b/bin/mozilla/do.pl @@ -454,7 +454,7 @@ sub orders { my $form = $main::form; my %myconfig = %main::myconfig; my $locale = $main::locale; - my $cgi = $main::cgi; + my $cgi = $::request->{cgi}; ($form->{ $form->{vc} }, $form->{"$form->{vc}_id"}) = split(/--/, $form->{ $form->{vc} }); diff --git a/bin/mozilla/fu.pl b/bin/mozilla/fu.pl index ec322413f..8870c2b60 100644 --- a/bin/mozilla/fu.pl +++ b/bin/mozilla/fu.pl @@ -231,7 +231,7 @@ sub report { my $form = $main::form; my %myconfig = %main::myconfig; my $locale = $main::locale; - my $cgi = $main::cgi; + my $cgi = $::request->{cgi}; my @report_params = qw(created_for subject body reference follow_up_date_from follow_up_date_to itime_from itime_to due_only all_users done not_done); diff --git a/bin/mozilla/gl.pl b/bin/mozilla/gl.pl index 189d1c481..6ef1ca3e3 100644 --- a/bin/mozilla/gl.pl +++ b/bin/mozilla/gl.pl @@ -218,7 +218,7 @@ sub search { my $form = $main::form; my %myconfig = %main::myconfig; my $locale = $main::locale; - my $cgi = $main::cgi; + my $cgi = $::request->{cgi}; $form->{title} = $locale->text('Journal'); @@ -507,7 +507,7 @@ sub generate_report { my @columns = qw( gldate transdate id reference description - notes source debit debit_accno + notes source debit debit_accno credit credit_accno debit_tax debit_tax_accno credit_tax credit_tax_accno projectnumbers balance employee ); @@ -861,7 +861,7 @@ sub display_rows { my $form = $main::form; my %myconfig = %main::myconfig; - my $cgi = $main::cgi; + my $cgi = $::request->{cgi}; $form->{debit_1} = 0 if !$form->{"debit_1"}; $form->{totaldebit} = 0; @@ -1347,7 +1347,7 @@ sub form_footer { my $form = $main::form; my %myconfig = %main::myconfig; my $locale = $main::locale; - my $cgi = $main::cgi; + my $cgi = $::request->{cgi}; my $follow_ups_block; if ($form->{id}) { diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index e647db693..a4e027d6c 100644 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -113,7 +113,7 @@ sub display_row { my $form = $main::form; my %myconfig = %main::myconfig; my $locale = $main::locale; - my $cgi = $main::cgi; + my $cgi = $::request->{cgi}; my $numrows = shift; @@ -415,7 +415,7 @@ sub set_pricegroup { my $form = $main::form; my $locale = $main::locale; - my $cgi = $main::cgi; + my $cgi = $::request->{cgi}; _check_io_auth(); diff --git a/bin/mozilla/ir.pl b/bin/mozilla/ir.pl index 780b8eac3..353b44453 100644 --- a/bin/mozilla/ir.pl +++ b/bin/mozilla/ir.pl @@ -262,7 +262,7 @@ sub form_header { my $form = $main::form; my %myconfig = %main::myconfig; my $locale = $main::locale; - my $cgi = $main::cgi; + my $cgi = $::request->{cgi}; $main::auth->assert('vendor_invoice_edit'); diff --git a/bin/mozilla/is.pl b/bin/mozilla/is.pl index 9ca19d839..19f546db3 100644 --- a/bin/mozilla/is.pl +++ b/bin/mozilla/is.pl @@ -285,7 +285,7 @@ sub form_header { my $form = $main::form; my %myconfig = %main::myconfig; my $locale = $main::locale; - my $cgi = $main::cgi; + my $cgi = $::request->{cgi}; $main::auth->assert('invoice_edit'); @@ -335,7 +335,7 @@ sub form_header { my %labels = map { $_ => $_ } @{ $form->{ALL_CURRENCIES} }; $form->{currency} = $form->{defaultcurrency} unless $form->{currency}; $form->{show_exchangerate} = $form->{currency} ne $form->{defaultcurrency}; - $TMPL_VAR{currencies} = NTI($::cgi->popup_menu('-name' => 'currency', '-default' => $form->{"currency"}, + $TMPL_VAR{currencies} = NTI($::request->{cgi}->popup_menu('-name' => 'currency', '-default' => $form->{"currency"}, '-values' => \@values, '-labels' => \%labels)) if scalar @values; push @custom_hiddens, "forex"; push @custom_hiddens, "exchangerate" if $form->{forex}; diff --git a/bin/mozilla/login.pl b/bin/mozilla/login.pl index 94905e4ed..d52a69b49 100644 --- a/bin/mozilla/login.pl +++ b/bin/mozilla/login.pl @@ -45,7 +45,6 @@ sub run { $::lxdebug->enter_sub; my $session_result = shift; - $cgi = $::cgi; $form = $::form; $auth = $::auth; diff --git a/bin/mozilla/oe.pl b/bin/mozilla/oe.pl index 6b8d30bb0..90efb0e64 100644 --- a/bin/mozilla/oe.pl +++ b/bin/mozilla/oe.pl @@ -298,7 +298,7 @@ sub form_header { my $form = $main::form; my %myconfig = %main::myconfig; my $locale = $main::locale; - my $cgi = $main::cgi; + my $cgi = $::request->{cgi}; check_oe_access(); @@ -744,7 +744,7 @@ sub orders { my $form = $main::form; my %myconfig = %main::myconfig; my $locale = $main::locale; - my $cgi = $main::cgi; + my $cgi = $::request->{cgi}; check_oe_access(); diff --git a/bin/mozilla/rp.pl b/bin/mozilla/rp.pl index 125d0b916..062c44f4e 100644 --- a/bin/mozilla/rp.pl +++ b/bin/mozilla/rp.pl @@ -176,7 +176,7 @@ sub report { } my $projectnumber = - NTI($main::cgi->popup_menu('-name' => "project_id", + NTI($::request->{cgi}->popup_menu('-name' => "project_id", '-values' => \@project_values, '-labels' => \%project_labels)); @@ -1663,7 +1663,7 @@ sub aging { my $form = $main::form; my %myconfig = %main::myconfig; my $locale = $main::locale; - my $cgi = $main::cgi; + my $cgi = $::request->{cgi}; my $report = SL::ReportGenerator->new(\%myconfig, $form); diff --git a/bin/mozilla/sepa.pl b/bin/mozilla/sepa.pl index f559c604b..ce334b28a 100755 --- a/bin/mozilla/sepa.pl +++ b/bin/mozilla/sepa.pl @@ -176,7 +176,7 @@ sub bank_transfer_list { my $form = $main::form; my $locale = $main::locale; - my $cgi = $main::cgi; + my $cgi = $::request->{cgi}; my $vc = $form->{vc} eq 'customer' ? 'customer' : 'vendor'; $form->{title} = $vc eq 'customer' ? $::locale->text('List of bank collections') : $locale->text('List of bank transfers'); @@ -443,7 +443,7 @@ sub bank_transfer_download_sepa_xml { my $form = $main::form; my $myconfig = \%main::myconfig; my $locale = $main::locale; - my $cgi = $main::cgi; + my $cgi = $::request->{cgi}; my $vc = $form->{vc} eq 'customer' ? 'customer' : 'vendor'; if (!$myconfig->{company}) { diff --git a/bin/mozilla/vk.pl b/bin/mozilla/vk.pl index 1327b2161..e871053a3 100644 --- a/bin/mozilla/vk.pl +++ b/bin/mozilla/vk.pl @@ -54,7 +54,6 @@ sub search_invoice { my $form = $main::form; my %myconfig = %main::myconfig; my $locale = $main::locale; - my $cgi = $main::cgi; my ($customer, $department); @@ -100,7 +99,7 @@ sub invoice_transactions { # Nichts führt, daher diese Zwischenlösung &check_name('customer', no_select => 1); - + # $form->{customer_id} wurde schon von check_name gesetzt $form->{customername} = $form->{customer}; }; @@ -312,7 +311,7 @@ sub invoice_transactions { if ( $subtotals2{qty} != 0 ) { $subtotals2{sellprice} = $subtotals2{sellprice_total} / $subtotals2{qty}; - $subtotals2{lastcost} = $subtotals2{lastcost_total} / $subtotals2{qty}; + $subtotals2{lastcost} = $subtotals2{lastcost_total} / $subtotals2{qty}; } else { $subtotals2{sellprice} = 0; $subtotals2{lastcost} = 0; diff --git a/scripts/console b/scripts/console index df9f6bf9d..50febadb6 100755 --- a/scripts/console +++ b/scripts/console @@ -62,11 +62,10 @@ sub lxinit { $::lxdebug = LXDebug->new(file => $debug_file); $::locale = Locale->new($::lx_office_conf{system}->{language}); - $::cgi = CGI->new qw(); $::form = Form->new; $::auth = SL::Auth->new; $::instance_conf = SL::InstanceConfiguration->new; - $::request = { }; + $::request = { cgi => CGI->new({}) }; die 'cannot reach auth db' unless $::auth->session_tables_present; diff --git a/scripts/rose_auto_create_model.pl b/scripts/rose_auto_create_model.pl index 5a7a12262..12ac0bdaf 100755 --- a/scripts/rose_auto_create_model.pl +++ b/scripts/rose_auto_create_model.pl @@ -31,7 +31,6 @@ my %blacklist = SL::DB::Helper::Mappings->get_blacklist; my %package_names = SL::DB::Helper::Mappings->get_package_names; our $form; -our $cgi; our $auth; our %lx_office_conf; @@ -59,11 +58,10 @@ sub setup { $::lxdebug = LXDebug->new(); $::locale = Locale->new("de"); $::form = new Form; - $::cgi = new CGI(''); $::auth = SL::Auth->new(); $::user = User->new($login); %::myconfig = $auth->read_user($login); - $::request = { }; + $::request = { cgi => CGI->new({}) }; $form->{script} = 'rose_meta_data.pl'; $form->{login} = $login; diff --git a/scripts/task_server.pl b/scripts/task_server.pl index 66e81e7c8..9bf2cb384 100755 --- a/scripts/task_server.pl +++ b/scripts/task_server.pl @@ -40,10 +40,9 @@ sub lxinit { $::lxdebug = LXDebug->new; $::locale = Locale->new($::lx_office_conf{system}->{language}); - $::cgi = CGI->new qw(); $::form = Form->new; $::auth = SL::Auth->new; - $::request = { }; + $::request = { cgi => CGI->new({}) }; die 'cannot reach auth db' unless $::auth->session_tables_present; diff --git a/t/structure/globals.t b/t/structure/globals.t index 14e0445d2..0a04c6f6f 100644 --- a/t/structure/globals.t +++ b/t/structure/globals.t @@ -7,7 +7,7 @@ use Support::Files; my (@globals, $testcount); BEGIN { - @globals = qw(lxdebug auth myconfig form cgi lx_office_conf locale dispatcher instance_conf request); + @globals = qw(lxdebug auth myconfig form lx_office_conf locale dispatcher instance_conf request); $testcount = scalar(@Support::Files::testitems); } -- 2.20.1