Code

Implement reinstall with offsets (#4271)
[gosa.git] / trunk / gosa-plugins / goto / addons / goto / class_gotomasses.inc
index ad278eaba61f3fdd86377e58ecb2e57f82980c2a..0338582703545101d99b2cf198b6e39cd3f34c94 100644 (file)
@@ -324,12 +324,48 @@ class gotomasses extends plugin
     if(isset($_POST['save_event_dialog'])){
       if(is_object($this->dialog)){
         $this->dialog->save_object();
-        if(!$this->o_queue->append($this->dialog)){
-          msg_dialog::display(_("Service infrastructure"),msgPool::siError($this->o_queue->get_error()),ERROR_DIALOG);
-        }else{
-          $this->dialog = FALSE; 
+        if($this->dialog->multiple_events) {
+          $event_type = get_class($this->dialog);
+          $targets = $this->dialog->get_targets();
+          $timestamp = $this->dialog->timestamp;
+
+          $i = 1;
+          $count = count($targets);
+          while($i <= $count) {
+            $operations = $this->dialog->concurrent_operations;
+            $event = new $event_type($this->config);
+            $event->set_timestamp($timestamp);
+            $event->set_type(SCHEDULED_EVENT);
+
+            while($operations > 0) {
+              $i++;
+              $target = array_shift($targets);
+              $event->add_targets(array($target));
+              $operations--;
+            }
+
+            $event->save_object();
+            $event->get_targets();
+            if(!$this->o_queue->append($event)){
+              msg_dialog::display(_("Service infrastructure"),msgPool::siError($this->o_queue->get_error()),ERROR_DIALOG);
+            }
+
+            # Calculate start time for the next run
+            $timestamp = $timestamp + ($this->dialog->time_offset*60);
+          }
+
+          $this->dialog = FALSE;
           $this->current = -1;
-        } 
+        }
+        else {
+          $this->dialog->save_object();
+          if(!$this->o_queue->append($this->dialog)){
+            msg_dialog::display(_("Service infrastructure"),msgPool::siError($this->o_queue->get_error()),ERROR_DIALOG);
+          }else{
+            $this->dialog = FALSE; 
+            $this->current = -1;
+          } 
+        }
       }
     }
 
@@ -807,7 +843,10 @@ class gotomasses extends plugin
         $sort.= " DESC";
       }
     }
-     
+
+    /* Sleep a second to avoid timing issues when adding new items */
+    sleep(1);
+
     /* Get entries. */ 
     $start  = $this->start; 
     $stop   = $this->range;