Code

periodic value within db should be 'none' or /d*_$periodic/
[gosa.git] / gosa-si / gosa-si-server
index be587d2700a65f0d7216157a71defd54aa17daa4..1d59cd75ef7a83776f0ee1e0e48e4aed731be3cf 100755 (executable)
@@ -151,6 +151,7 @@ my @job_queue_col_names = ("id INTEGER PRIMARY KEY",
        "plainname VARCHAR(255) DEFAULT 'none'",
        "siserver VARCHAR(255) DEFAULT 'none'",
        "modified INTEGER DEFAULT '0'",
+       "periodic VARCHAR(6) DEFAULT 'none'",
 );
 
 # holds all other gosa-si-server
@@ -225,6 +226,10 @@ our $logged_in_user_date_of_expiry = 600;
 # List of month names, used in function daemon_log
 my @monthnames = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
 
+# List of accepted periodical xml tags related to cpan modul DateTime
+our $check_periodic = {"months"=>'', "weeks"=>'', "days"=>'', "hours"=>'', "minutes"=>''};
+
+
 %cfg_defaults = (
 "general" => {
     "log-file" => [\$log_file, "/var/run/".$prg.".log"],
@@ -1135,7 +1140,15 @@ sub msg_to_decrypt {
        }
        # msg is from a gosa-si-client
        if(( !$msg ) || ( !$msg_hash ) || ( !$module )){
-               ($msg, $msg_hash, $module) = &input_from_known_client($next_msg, $msg_source, $session_id);
+               if (not defined $msg_source) 
+               {
+                       # Only needed, to be compatible with older gosa-si-server versions
+                       ($msg, $msg_hash, $module) = &input_from_known_client($next_msg, $heap->{'remote_ip'}, $session_id);
+               }
+               else
+               {
+                       ($msg, $msg_hash, $module) = &input_from_known_client($next_msg, $msg_source, $session_id);
+               }
        }
        # an error occurred
        if(( !$msg ) || ( !$msg_hash ) || ( !$module )){
@@ -1327,7 +1340,7 @@ sub msg_to_decrypt {
                                $msg =~ s/<header>gosa_/<header>/;
                                my $error= &send_msg_to_target($msg, $hostname, $hostkey, $header, $session_id);
                                if ($error) {
-                                       &daemon_log("$session_id ERROR: Some problems occurred while trying to send msg to client '$hostkey': $msg", 1);
+                                       &daemon_log("$session_id ERROR: Some problems occurred while trying to send msg to client '$hostname': $msg", 1);
                                }
                        } 
                        else 
@@ -1700,16 +1713,35 @@ sub session_start {
 
 
 sub watch_for_done_jobs {
-       #CHECK: $heap for what?
-       my ($kernel,$heap) = @_[KERNEL, HEAP];
+       my $kernel = $_[KERNEL];
 
        my $sql_statement = "SELECT * FROM ".$job_queue_tn." WHERE ((status='done') AND (modified='0'))";
        my $res = $job_db->select_dbentry( $sql_statement );
 
-       while( my ($id, $hit) = each %{$res} ) {
-               my $jobdb_id = $hit->{id};
-               my $sql_statement = "DELETE FROM $job_queue_tn WHERE id=$jobdb_id"; 
-               my $res = $job_db->del_dbentry($sql_statement); 
+       while( my ($number, $hit) = each %{$res} ) 
+       {
+               # Non periodical jobs can be deleted.
+               if ($hit->{periodic} eq "none")
+               {
+                       my $jobdb_id = $hit->{id};
+                       my $sql_statement = "DELETE FROM $job_queue_tn WHERE id=$jobdb_id"; 
+                       my $res = $job_db->del_dbentry($sql_statement); 
+               }
+
+               # Periodical jobs should not be deleted but reactivated with new timestamp instead.
+               else
+               {
+                       my ($p_time, $periodic) = split("_", $hit->{periodic});
+                       my $reactivated_ts = $hit->{timestamp};
+                       my $act_ts = int(&get_time());
+                       while ($act_ts > int($reactivated_ts))   # Redo calculation to avoid multiple jobs in the past
+                       {
+                               $reactivated_ts = &calc_timestamp($reactivated_ts, "plus", $p_time, $periodic);
+                       }
+                       my $sql = "UPDATE $job_queue_tn SET status='waiting', timestamp='$reactivated_ts' WHERE id='".$hit->{id}."'"; 
+                       my $res = $job_db->exec_statement($sql);
+                       &daemon_log("J INFO: Update periodical job '".$hit->{headertag}."' for client '".$hit->{targettag}."'. New execution time '$reactivated_ts'.", 5);
+               }
        }
 
        $kernel->delay_set('watch_for_done_jobs',$job_queue_loop_delay);
@@ -1936,7 +1968,7 @@ sub watch_for_new_jobs {
                                        my $func_error = &send_msg_to_target($job_msg, $server_address, $GosaPackages_key, $header, "J");                    
 
                                        # update status in job queue to ...
-                    # ... 'processing', for jobs: 'reinstall', 'update'
+                    # ... 'processing', for jobs: 'reinstall', 'update', activate_new
                     if (($header =~ /gosa_trigger_action_reinstall/) 
                             || ($header =~ /gosa_trigger_activate_new/)
                             || ($header =~ /gosa_trigger_action_update/)) {
@@ -1947,7 +1979,7 @@ sub watch_for_new_jobs {
                     # ... 'done', for all other jobs, they are no longer needed in the jobqueue
                     else {
                         my $sql_statement = "UPDATE $job_queue_tn SET status='done' WHERE id=$jobdb_id";
-                        my $dbres = $job_db->update_dbentry($sql_statement);
+                        my $dbres = $job_db->exec_statement($sql_statement);
                     }