Controller-Base: _controller_name in controller_name umbenennen; action_name() ergänzt
[kivitendo-erp.git] / SL / Dispatcher.pm
index f6c9f60..43bf668 100644 (file)
@@ -2,9 +2,18 @@ package SL::Dispatcher;
 
 use strict;
 
+# Force scripts/locales.pl to parse these templates:
+#   parse_html_template('login_screen/auth_db_unreachable')
+#   parse_html_template('login_screen/user_login')
+#   parse_html_template('generic/error')
+
 BEGIN {
-  unshift @INC, "modules/override"; # Use our own versions of various modules (e.g. YAML).
-  push    @INC, "modules/fallback"; # Only use our own versions of modules if there's no system version.
+  use SL::System::Process;
+  my $exe_dir = SL::System::Process::exe_dir;
+
+  unshift @INC, "${exe_dir}/modules/override"; # Use our own versions of various modules (e.g. YAML).
+  push    @INC, "${exe_dir}/modules/fallback"; # Only use our own versions of modules if there's no system version.
+  unshift @INC, $exe_dir;
 }
 
 use CGI qw( -no_xhtml);
@@ -200,7 +209,13 @@ sub handle_request {
 
     $::form->error($::locale->text('System currently down for maintenance!')) if -e ($::lx_office_conf{paths}->{userspath} . "/nologin") && $script ne 'admin';
 
-    ($routing_type, $script, $script_name, $action) = qw(controller controller LoginScreen login) if ($script eq 'login') && ($action eq 'login');
+    # For compatibility with a lot of database upgrade scripts etc:
+    # Re-write request to old 'login.pl?action=login' to new
+    # 'LoginScreen' controller. Make sure to load its code!
+    if (($script eq 'login') && ($action eq 'login')) {
+      ($routing_type, $script, $script_name, $action) = qw(controller controller LoginScreen login);
+      _require_controller('LoginScreen');
+    }
 
     if (($script eq 'login') && !$action) {
       print $::request->{cgi}->redirect('controller.pl?action=LoginScreen/user_login');
@@ -243,6 +258,7 @@ sub handle_request {
     if ($EVAL_ERROR ne END_OF_REQUEST) {
       print STDERR $EVAL_ERROR;
       $::form->{label_error} = $::request->{cgi}->pre($EVAL_ERROR);
+      chdir SL::System::Process::exe_dir;
       eval { show_error('generic/error') };
     }
   };