Auth.pm: Rechte nur dann laden, wenn User & Client gesetzt sind
[kivitendo-erp.git] / scripts / task_server.pl
index cb332ec..b1baef4 100755 (executable)
@@ -75,6 +75,23 @@ sub lxinit {
   die "cannot find locale for user $login" unless $::locale   = Locale->new('de');
 }
 
+sub per_job_initialization {
+  $::locale        = Locale->new($::myconfig{countrycode} || $::lx_office_conf{system}->{language});
+  $::form          = Form->new;
+  $::instance_conf = SL::InstanceConfiguration->new;
+  $::request       = SL::Request->new(
+    cgi            => CGI->new({}),
+    layout         => SL::Layout::None->new,
+  );
+
+  $::auth->restore_session;
+
+  $::form->{login} = $lx_office_conf{task_server}->{login};
+  $::instance_conf->init;
+
+  $::form->{__ERROR_HANDLER} = sub { die @_ };
+}
+
 sub drop_privileges {
   my $user = $lx_office_conf{task_server}->{run_as};
   return unless $user;
@@ -174,8 +191,7 @@ sub gd_run {
       foreach my $job (@{ $jobs }) {
         # Provide fresh global variables in case legacy code modifies
         # them somehow.
-        $::locale = Locale->new($::lx_office_conf{system}->{language});
-        $::form   = Form->new;
+        per_job_initialization();
 
         chdir $exe_dir;
 
@@ -209,6 +225,17 @@ sub gd_run {
   }
 }
 
+sub end_of_request {
+  $main::lxdebug->show_backtrace();
+  die <<EOF;
+Job called ::end_of_request()!
+
+This usually indicates success but should not be used by background jobs. A
+backtrace has been logged. Please tell the job author to have a look at it.
+EOF
+
+}
+
 chdir $exe_dir;
 
 mkdir SL::System::TaskServer::PID_BASE() if !-d SL::System::TaskServer::PID_BASE();