From b2945bf61775161f9ce9be9bdbd106ad44247a14 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Tue, 20 Jul 2010 10:23:46 +0200 Subject: [PATCH] Aufrufe von 'exit' durch eigene Funktion '::end_of_request()' ersetzt. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Außerdem dafür gesorgt, dass Meldungen, die per $form->show_generic_(error|information) ausgegeben werden, nicht doppelt angezeigt werden. Conflicts: bin/mozilla/io.pl bin/mozilla/oe.pl --- SL/DATEV.pm | 2 +- SL/Dispatcher.pm | 20 +++++++++++++++++--- SL/Form.pm | 16 +++++++++------- SL/USTVA.pm | 2 +- SL/User.pm | 8 ++++---- bin/mozilla/admin.pl | 6 +++--- bin/mozilla/am.pl | 2 +- bin/mozilla/ap.pl | 2 +- bin/mozilla/ar.pl | 2 +- bin/mozilla/arap.pl | 4 ++-- bin/mozilla/bp.pl | 2 +- bin/mozilla/cp.pl | 2 +- bin/mozilla/ct.pl | 3 ++- bin/mozilla/do.pl | 12 ++++++------ bin/mozilla/fu.pl | 6 +++--- bin/mozilla/ic.pl | 2 +- bin/mozilla/installationcheck.pl | 3 ++- bin/mozilla/invoice_io.pl | 4 ++-- bin/mozilla/io.pl | 10 +++++----- bin/mozilla/ir.pl | 4 ++-- bin/mozilla/is.pl | 4 ++-- bin/mozilla/licenses.pl | 2 +- bin/mozilla/login.pl | 10 +++++----- bin/mozilla/oe.pl | 16 ++++++++-------- bin/mozilla/ustva.pl | 6 +++--- bin/mozilla/wh.pl | 4 ++-- doc/INSTALL.fcgi | 3 --- 27 files changed, 86 insertions(+), 71 deletions(-) diff --git a/SL/DATEV.pm b/SL/DATEV.pm index 49e824b50..eacda097d 100644 --- a/SL/DATEV.pm +++ b/SL/DATEV.pm @@ -405,7 +405,7 @@ sub _get_transactions { if ($ref2->{trans_id} != $trans->[0]->{trans_id}) { $form->error("Unbalanced ledger! old trans_id " . $trans->[0]->{trans_id} . " new trans_id " . $ref2->{trans_id} . " count $count"); - exit 1; + ::end_of_request(); } push @{ $trans }, $ref2; diff --git a/SL/Dispatcher.pm b/SL/Dispatcher.pm index 9d968ad0e..532592e66 100644 --- a/SL/Dispatcher.pm +++ b/SL/Dispatcher.pm @@ -14,6 +14,10 @@ use Rose::DB; use Rose::DB::Object; use File::Basename; +# Trailing new line is added so that Perl will not add the line +# number 'die' was called in. +use constant END_OF_REQUEST => "END-OF-REQUEST\n"; + sub pre_request_checks { show_error('login/auth_db_unreachable') unless $::auth->session_tables_present; $::auth->expire_sessions; @@ -33,7 +37,7 @@ sub show_error { print $::form->parse_html_template($template); $::lxdebug->leave_sub; - exit; + ::end_of_request(); } sub pre_startup_setup { @@ -159,8 +163,10 @@ sub handle_request { 1; } or do { - $::form->{label_error} = $::cgi->pre($EVAL_ERROR); - show_error('generic/error'); + if ($EVAL_ERROR ne END_OF_REQUEST) { + $::form->{label_error} = $::cgi->pre($EVAL_ERROR); + eval { show_error('generic/error') }; + } }; # cleanup @@ -181,4 +187,12 @@ sub unrequire_bin_mozilla { } } +package main; + +use strict; + +sub end_of_request { + die SL::Dispatcher->END_OF_REQUEST; +} + 1; diff --git a/SL/Form.pm b/SL/Form.pm index c75249bac..130a337ba 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -455,8 +455,8 @@ sub error { $self->show_generic_error($msg); } else { - - die "Error: $msg\n"; + print STDERR "Error: $msg\n"; + ::end_of_request(); } $main::lxdebug->leave_sub(); @@ -772,7 +772,7 @@ sub _prepare_html_template { my $info = "Developer information: templates/webpages/${file}.html is newer than the translation file locale/${language}/all.\n" . "Please re-run 'locales.pl' in 'locale/${language}'."; print(qq|
$info
|); - die($info); + ::end_of_request(); } $file = "templates/webpages/${file}.html"; @@ -781,7 +781,7 @@ sub _prepare_html_template { my $info = "Web page template '${file}' not found.\n" . "Please re-run 'locales.pl' in 'locale/${language}'."; print(qq|
$info
|); - die($info); + ::end_of_request(); } if ($self->{"DEBUG"}) { @@ -895,9 +895,11 @@ sub show_generic_error { $self->header(); print $self->parse_html_template("generic/error", $add_params); + print STDERR "Error: $error\n"; + $main::lxdebug->leave_sub(); - die("Error: $error\n"); + ::end_of_request(); } sub show_generic_information { @@ -917,7 +919,7 @@ sub show_generic_information { $main::lxdebug->leave_sub(); - die("Information: $text\n"); + ::end_of_request(); } # write Trigger JavaScript-Code ($qty = quantity of Triggers) @@ -975,7 +977,7 @@ sub redirect { if (!$self->{callback}) { $self->info($msg); - exit; + ::end_of_request(); } # my ($script, $argv) = split(/\?/, $self->{callback}, 2); diff --git a/SL/USTVA.pm b/SL/USTVA.pm index bfda202db..84a8a96e0 100644 --- a/SL/USTVA.pm +++ b/SL/USTVA.pm @@ -412,7 +412,7 @@ sub info { |; - exit; + ::end_of_request(); } else { diff --git a/SL/User.pm b/SL/User.pm index 16ad74ea3..88ea5b3f5 100644 --- a/SL/User.pm +++ b/SL/User.pm @@ -144,7 +144,7 @@ sub login { if ($form->{"show_dbupdate_warning"}) { print $form->parse_html_template("dbupgrade/warning"); - exit(0); + ::end_of_request(); } # update the tables @@ -412,7 +412,7 @@ sub dbcreate { # Process a Perl script which updates the database. # If the script returns 1 then the update was successful. # Return code "2" means "needs more interaction; remove -# users/nologin and exit". +# users/nologin and end current request". # All other return codes are fatal errors. sub process_perl_script { $main::lxdebug->enter_sub(); @@ -466,10 +466,10 @@ sub process_perl_script { print $form->parse_html_template("dbupgrade/error", { "file" => $filename, "error" => $@ }); - exit(0); + ::end_of_request(); } elsif (1 != $result) { unlink("users/nologin") if (2 == $result); - exit(0); + ::end_of_request(); } if (ref($version_or_control) eq "HASH") { diff --git a/bin/mozilla/admin.pl b/bin/mozilla/admin.pl index 8bd621c80..5962e5404 100755 --- a/bin/mozilla/admin.pl +++ b/bin/mozilla/admin.pl @@ -132,7 +132,7 @@ sub check_auth_db_and_tables { $form->header(); print $form->parse_html_template('admin/check_auth_database', \%params); - exit 0; + ::end_of_request(); } if (!$main::auth->check_tables()) { @@ -140,7 +140,7 @@ sub check_auth_db_and_tables { $form->header(); print $form->parse_html_template('admin/check_auth_tables', \%params); - exit 0; + ::end_of_request(); } if (-f $main::memberfile) { @@ -157,7 +157,7 @@ sub check_auth_db_and_tables { print $form->parse_html_template('admin/user_migration', { 'memberfile' => $main::memberfile, 'backupdir' => $backupdir }); - exit 0 + ::end_of_request(); } } diff --git a/bin/mozilla/am.pl b/bin/mozilla/am.pl index a1e227fa8..4a7840281 100644 --- a/bin/mozilla/am.pl +++ b/bin/mozilla/am.pl @@ -3545,7 +3545,7 @@ sub delete_warehouse { $form->header(); print $form->parse_html_template('am/confirm_delete_warehouse'); - exit 0; + ::end_of_request(); } if (AM->delete_warehouse(\%myconfig, $form)) { diff --git a/bin/mozilla/ap.pl b/bin/mozilla/ap.pl index 91836ebb7..1262b49f7 100644 --- a/bin/mozilla/ap.pl +++ b/bin/mozilla/ap.pl @@ -1064,7 +1064,7 @@ sub post { my ($vendor) = split /--/, $form->{vendor}; if ($form->{oldvendor} ne "$vendor--$form->{vendor_id}") { &update; - exit; + ::end_of_request(); } my ($debitaccno, $debittaxkey) = split /--/, $form->{AP_amountselected}; my ($taxkey, $NULL) = split /--/, $form->{taxchartselected}; diff --git a/bin/mozilla/ar.pl b/bin/mozilla/ar.pl index b5bd9be6c..9fdf2bc8c 100644 --- a/bin/mozilla/ar.pl +++ b/bin/mozilla/ar.pl @@ -1127,7 +1127,7 @@ sub post { my ($customer) = split /--/, $form->{customer}; if ($form->{oldcustomer} ne "$customer--$form->{customer_id}") { update(); - exit; + ::end_of_request(); } $form->{AR}{receivables} = $form->{ARselected}; diff --git a/bin/mozilla/arap.pl b/bin/mozilla/arap.pl index 8c49dc23d..03dd6e895 100644 --- a/bin/mozilla/arap.pl +++ b/bin/mozilla/arap.pl @@ -108,7 +108,7 @@ sub check_name { $form->error($locale->text("More than one #1 found matching, please be more specific.", $locale->text(ucfirst $name))); } else { &select_name($name); - exit; + ::end_of_request(); } } @@ -318,7 +318,7 @@ sub check_project { # check form->{project_list} how many there are $form->{rownumber} = $i; &select_project($i ? undef : 1, $nextsub); - exit; + ::end_of_request(); } if ($rows == 1) { diff --git a/bin/mozilla/bp.pl b/bin/mozilla/bp.pl index 1445eba05..1196763fa 100644 --- a/bin/mozilla/bp.pl +++ b/bin/mozilla/bp.pl @@ -390,7 +390,7 @@ sub print { print $locale->text('done'); $form->redirect($locale->text('Marked entries printed!')); } - exit; + ::end_of_request(); } } diff --git a/bin/mozilla/cp.pl b/bin/mozilla/cp.pl index f4a9efb20..a62a9ebff 100644 --- a/bin/mozilla/cp.pl +++ b/bin/mozilla/cp.pl @@ -771,7 +771,7 @@ sub check_form { if ($form->{currency} ne $form->{oldcurrency}) { &update; - exit; + ::end_of_request(); } $form->error($locale->text('Zero amount posting!')) if !$form->parse_amount(\%myconfig, $form->{amount}); diff --git a/bin/mozilla/ct.pl b/bin/mozilla/ct.pl index 9488ec847..10b138e62 100644 --- a/bin/mozilla/ct.pl +++ b/bin/mozilla/ct.pl @@ -574,8 +574,9 @@ sub save { } # /saving the history &edit; - exit; + $main::lxdebug->leave_sub(); + ::end_of_request(); } sub delete { diff --git a/bin/mozilla/do.pl b/bin/mozilla/do.pl index f7e859e5b..e350cb342 100644 --- a/bin/mozilla/do.pl +++ b/bin/mozilla/do.pl @@ -367,7 +367,7 @@ sub update_delivery_order { if ($rows > 1) { select_item(); - exit; + ::end_of_request(); } else { @@ -619,7 +619,7 @@ sub save { # if the name changed get new values if (check_name($form->{vc})) { update(); - exit; + ::end_of_request(); } $form->{id} = 0 if $form->{saveasnew}; @@ -647,7 +647,7 @@ sub save { if(!$form->{print_and_save}) { set_headings("edit"); update(); - exit; + ::end_of_request(); } $main::lxdebug->leave_sub(); } @@ -690,7 +690,7 @@ sub delete_delivery_order { # /saving the history $form->info($locale->text('Delivery Order deleted!')); - exit(); + ::end_of_request(); } $form->error($locale->text('Cannot delete delivery order!')); @@ -1232,7 +1232,7 @@ sub transfer_in { update(); $main::lxdebug->leave_sub(); - exit 0; + ::end_of_request(); } } @@ -1346,7 +1346,7 @@ sub transfer_out { update(); $main::lxdebug->leave_sub(); - exit 0; + ::end_of_request(); } } diff --git a/bin/mozilla/fu.pl b/bin/mozilla/fu.pl index 1879be0ee..ac9e81f2e 100644 --- a/bin/mozilla/fu.pl +++ b/bin/mozilla/fu.pl @@ -118,7 +118,7 @@ sub save_follow_up { if ($form->{POPUP_MODE}) { $form->header(); print $form->parse_html_template('fu/close_window'); - exit 0; + ::end_of_request(); } $form->{SAVED_MESSAGE} = $locale->text('Follow-Up saved.'); @@ -162,7 +162,7 @@ sub finish { if ($form->{POPUP_MODE}) { $form->header(); print $form->parse_html_template('fu/close_window'); - exit 0; + ::end_of_request(); } $form->redirect() if ($form->{callback}); @@ -198,7 +198,7 @@ sub delete { if ($form->{POPUP_MODE}) { $form->header(); print $form->parse_html_template('fu/close_window'); - exit 0; + ::end_of_request(); } $form->redirect() if ($form->{callback}); diff --git a/bin/mozilla/ic.pl b/bin/mozilla/ic.pl index ec287aa61..95d72ec07 100644 --- a/bin/mozilla/ic.pl +++ b/bin/mozilla/ic.pl @@ -1723,7 +1723,7 @@ sub update { if ($rows > 1) { $form->{makemodel_rows}--; &select_item; - exit; + ::end_of_request(); } else { map { $form->{item_list}[$i]{$_} =~ s/\"/"/g } qw(partnumber description unit partsgroup); diff --git a/bin/mozilla/installationcheck.pl b/bin/mozilla/installationcheck.pl index 54a9211a5..ce6022b1d 100644 --- a/bin/mozilla/installationcheck.pl +++ b/bin/mozilla/installationcheck.pl @@ -85,7 +85,8 @@ sub verify_installation { |); - exit(0); + + ::end_of_request(); } 1; diff --git a/bin/mozilla/invoice_io.pl b/bin/mozilla/invoice_io.pl index 97d30fec6..7203f928e 100644 --- a/bin/mozilla/invoice_io.pl +++ b/bin/mozilla/invoice_io.pl @@ -159,7 +159,7 @@ sub display_form { # if we have a display_form if ($form->{display_form}) { call_sub($form->{"display_form"}); - exit; + ::end_of_request(); } Common::webdav_folder($form) if ($main::webdav); @@ -176,7 +176,7 @@ sub display_form { # $form->{print_and_post} = 0; # # &print_form($old_form); - # exit; + # ::end_of_request(); # } # # $form->{action} = ""; diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index 46b7c28c0..cd019264c 100644 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -882,7 +882,7 @@ sub validate_items { # check if items are valid if ($form->{rowcount} == 1) { &update; - exit; + ::end_of_request(); } for my $i (1 .. $form->{rowcount} - 1) { @@ -1265,7 +1265,7 @@ sub print { &save(); $form->{formname} = $formname; &edit(); - exit; + ::end_of_request(); } &print_form($old_form); @@ -1432,7 +1432,7 @@ sub print_form { $form->save_history($form->dbconnect(\%myconfig)); } # /saving the history - exit; + ::end_of_request(); } } @@ -1705,7 +1705,7 @@ sub print_form { } call_sub($display_form); - exit; + ::end_of_request(); } my $msg = @@ -1716,7 +1716,7 @@ sub print_form { } if ($form->{printing}) { call_sub($display_form); - exit; + ::end_of_request(); } $main::lxdebug->leave_sub(); diff --git a/bin/mozilla/ir.pl b/bin/mozilla/ir.pl index 06f6d059b..1119ad426 100644 --- a/bin/mozilla/ir.pl +++ b/bin/mozilla/ir.pl @@ -468,7 +468,7 @@ sub update { if ($rows > 1) { &select_item; - exit; + ::end_of_request(); } else { @@ -664,7 +664,7 @@ sub post { # if the vendor changed get new values if (&check_name('vendor')) { &update; - exit; + ::end_of_request(); } if ($myconfig{mandatory_departments} && !$form->{department_id}) { diff --git a/bin/mozilla/is.pl b/bin/mozilla/is.pl index 3c5282cbe..7084d0a01 100644 --- a/bin/mozilla/is.pl +++ b/bin/mozilla/is.pl @@ -512,7 +512,7 @@ sub update { if ($rows > 1) { &select_item; - exit; + ::end_of_request(); } else { @@ -652,7 +652,7 @@ sub post { # if oldcustomer ne customer redo form if (&check_name('customer')) { &update; - exit; + ::end_of_request(); } if ($myconfig{mandatory_departments} && !$form->{department_id}) { diff --git a/bin/mozilla/licenses.pl b/bin/mozilla/licenses.pl index 6fe4f764e..49022059f 100644 --- a/bin/mozilla/licenses.pl +++ b/bin/mozilla/licenses.pl @@ -611,7 +611,7 @@ sub do_search { . $locale->text( "No licenses were found that match the search criteria.") . qq||); - exit(0); + ::end_of_request(); } print( diff --git a/bin/mozilla/login.pl b/bin/mozilla/login.pl index 5a5aa42b7..622db697d 100644 --- a/bin/mozilla/login.pl +++ b/bin/mozilla/login.pl @@ -57,7 +57,7 @@ sub run { if (SL::Auth::SESSION_EXPIRED == $session_result) { $form->{error_message} = $locale->text('The session is invalid or has expired.'); login_screen(); - exit; + ::end_of_request(); } my $action = $form->{action}; if (!$action && $auth->{SESSION}->{login}) { @@ -104,7 +104,7 @@ sub login { unless ($form->{login}) { login_screen($locale->text('You did not enter a name!')); - exit; + ::end_of_request(); } my $user = new User $form->{login}; @@ -112,9 +112,9 @@ sub login { # if we get an error back, bale out my $result; if (($result = $user->login($form)) <= -1) { - exit if $result == -2; + ::end_of_request() if $result == -2; login_screen($locale->text('Incorrect username or password!')); - exit; + ::end_of_request(); } my %style_to_script_map = ( 'v3' => 'v3', @@ -188,7 +188,7 @@ sub show_error { # $form->parse_html_template('login/auth_db_unreachable'); # $form->parse_html_template('login/authentication_pl_missing'); - exit; + ::end_of_request(); } 1; diff --git a/bin/mozilla/oe.pl b/bin/mozilla/oe.pl index f40e918f9..cd04c6b27 100644 --- a/bin/mozilla/oe.pl +++ b/bin/mozilla/oe.pl @@ -563,7 +563,7 @@ sub update { if ($rows > 1) { &select_item; - exit; + ::end_of_request(); } else { @@ -1010,7 +1010,7 @@ sub save_and_close { $form->{payment_id} = $payment_id; } &update; - exit; + ::end_of_request(); } $form->{id} = 0 if $form->{saveasnew}; @@ -1119,7 +1119,7 @@ sub save { $form->{payment_id} = $payment_id; } &update; - exit; + ::end_of_request(); } $form->{id} = 0 if $form->{saveasnew}; @@ -1180,7 +1180,7 @@ sub save { if(!$form->{print_and_save}) { delete @{$form}{ary_diff([keys %{ $form }], [qw(login stylesheet id script type cursor_fokus)])}; edit(); - exit; + ::end_of_request(); } $main::lxdebug->leave_sub(); } @@ -1264,7 +1264,7 @@ sub delete_order_quotation { } # /saving the history $form->info($msg); - exit(); + ::end_of_request(); } $form->error($err); @@ -1310,7 +1310,7 @@ sub invoice { if (&check_name($form->{vc})) { $form->{payment_id} = $payment_id if $form->{payment_id} eq ""; &update; - exit; + ::end_of_request(); } $form->{cp_id} *= 1; @@ -1333,7 +1333,7 @@ sub invoice { if (!$exchangerate) { &backorder_exchangerate($orddate, $buysell); - exit; + ::end_of_request(); } } @@ -1681,7 +1681,7 @@ sub check_for_direct_delivery { $main::lxdebug->leave_sub(); - exit 0; + ::end_of_request(); } sub purchase_order { diff --git a/bin/mozilla/ustva.pl b/bin/mozilla/ustva.pl index cfd78bf7c..945de31a1 100644 --- a/bin/mozilla/ustva.pl +++ b/bin/mozilla/ustva.pl @@ -915,7 +915,7 @@ sub generate_ustva { } else { $form->header; USTVA::error( $locale->text('Wrong Period' )); - exit(0); + ::end_of_request(); } my $tax_office = first { $_->{name} eq $form->{elsterland} } @{ $ustva->{tax_office_information} }; @@ -983,12 +983,12 @@ sub generate_ustva { } elsif ( $form->{format} eq '' ){ # No format error. $form->header; USTVA::error( $locale->text('Application Error. No Format given' ) . "!"); - exit(0); + ::end_of_request(); } else { # All other Formats are wrong $form->header; USTVA::error( $locale->text('Application Error. Wrong Format') . ": " . $form->{format} ); - exit(0); + ::end_of_request(); } diff --git a/bin/mozilla/wh.pl b/bin/mozilla/wh.pl index 89975cc2a..26f22cef6 100644 --- a/bin/mozilla/wh.pl +++ b/bin/mozilla/wh.pl @@ -277,7 +277,7 @@ sub transfer_parts { if (!scalar @transfers) { $form->show_generic_information($locale->text('Nothing has been selected for transfer.')); - exit 0; + ::end_of_request(); } WH->transfer(@transfers); @@ -611,7 +611,7 @@ sub remove_parts { if (!scalar @transfers) { $form->show_generic_information($locale->text('Nothing has been selected for removal.')); - exit 0; + ::end_of_request(); } WH->transfer(@transfers); diff --git a/doc/INSTALL.fcgi b/doc/INSTALL.fcgi index 5eb3a4067..6ec640d1a 100644 --- a/doc/INSTALL.fcgi +++ b/doc/INSTALL.fcgi @@ -49,6 +49,3 @@ Variante 2 startet nur einen zentralen Dispatcher und lenkt alle Scripte auf die 4. TODO -4.1. Fehlermeldungen, die per $form->error() ausgegeben werden, werden momentan doppelt angezeigt. - -4.2. "exit" sollte unter FastCGI nicht verwendet werden, startet ja den Prozess neu. Nur die Abhandlung des Requests sollte beendet werden. -- 2.20.1