GDPDU: Maps nicht innerhalb von AlphaNumeric, sondern danach.
[kivitendo-erp.git] / scripts / task_server.pl
index 1bcb719..f22ce13 100755 (executable)
@@ -32,6 +32,7 @@ use File::Spec;
 use List::Util qw(first);
 use POSIX qw(setuid setgid);
 use SL::Auth;
+use SL::DBUpgrade2;
 use SL::DB::AuthClient;
 use SL::DB::BackgroundJob;
 use SL::BackgroundJob::ALL;
@@ -63,7 +64,6 @@ sub initialize_kivitendo {
 
   package main;
 
-  Form::disconnect_standard_dbh;
   $::lxdebug       = LXDebug->new;
   $::locale        = Locale->new($::lx_office_conf{system}->{language});
   $::form          = Form->new;
@@ -93,8 +93,7 @@ sub initialize_kivitendo {
 }
 
 sub cleanup_kivitendo {
-  eval { SL::DB::Auth->new->db->dbh->rollback; };
-  eval { SL::DB::BackgroundJob->new->db->dbh->rollback; };
+  eval { SL::DB->client->dbh->rollback; };
 
   $::auth->save_session;
   $::auth->expire_sessions;
@@ -107,9 +106,10 @@ sub cleanup_kivitendo {
 }
 
 sub clean_before_sleeping {
-  Form::disconnect_standard_dbh;
   SL::DBConnect::Cache->disconnect_all_and_clear;
   SL::DB->db_cache->clear;
+
+  File::Temp::cleanup();
 }
 
 sub drop_privileges {
@@ -210,6 +210,18 @@ EOT
     exit 2;
   }
 
+  initialize_kivitendo();
+
+  my $dbupdater_auth = SL::DBUpgrade2->new(form => $::form, auth => 1)->parse_dbupdate_controls;
+  if ($dbupdater_auth->unapplied_upgrade_scripts($::auth->dbconnect)) {
+    print STDERR <<EOT;
+The authentication database requires an upgrade. Please login to
+kivitendo's administration interface in order to apply it. The task
+server cannot start until the upgrade has been applied.
+EOT
+    exit 2;
+  }
+
   drop_privileges();
 
   return ();
@@ -259,6 +271,8 @@ sub run_once_for_all_clients {
 
 sub gd_run {
   while (1) {
+    $SIG{'ALRM'} = 'IGNORE';
+
     run_once_for_all_clients();
 
     debug("Sleeping");
@@ -267,7 +281,8 @@ sub gd_run {
 
     my $seconds = 60 - (localtime)[0];
     if (!eval {
-      local $SIG{'ALRM'} = sub {
+      $SIG{'ALRM'} = sub {
+        $SIG{'ALRM'} = 'IGNORE';
         debug("Got woken up by SIGALRM");
         die "Alarm!\n"
       };
@@ -279,17 +294,6 @@ 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();