From 7a28d36f516352678091062b7042f04026be1845 Mon Sep 17 00:00:00 2001 From: psc Date: Tue, 27 Apr 2010 13:53:30 +0000 Subject: [PATCH] Apply fix for #4271 - Move code for saving events to a static function in the DaemonEvent class so it can be called from different places in the code without making it redundant. Use this new function in gotomasses and the system plugin so that both places can benefit from the new time offset feature. git-svn-id: https://oss.gonicus.de/repositories/gosa/branches/2.6-lhm@17888 594d385d-05f5-0310-b6e9-bd551577e9d8 --- .../goto/addons/goto/class_gotomasses.inc | 46 +----------------- .../addons/goto/events/class_DaemonEvent.inc | 48 +++++++++++++++++++ .../admin/systems/class_systemManagement.inc | 8 +--- 3 files changed, 51 insertions(+), 51 deletions(-) diff --git a/trunk/gosa-plugins/goto/addons/goto/class_gotomasses.inc b/trunk/gosa-plugins/goto/addons/goto/class_gotomasses.inc index 033858270..b7200f344 100644 --- a/trunk/gosa-plugins/goto/addons/goto/class_gotomasses.inc +++ b/trunk/gosa-plugins/goto/addons/goto/class_gotomasses.inc @@ -322,51 +322,7 @@ class gotomasses extends plugin /* Close dialog */ if(isset($_POST['save_event_dialog'])){ - if(is_object($this->dialog)){ - $this->dialog->save_object(); - 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; - } - } - } + list($this->dialog, $this->current) = DaemonEvent::save_event_dialog($this->dialog, $this->current, $this->o_queue, $this->config); } diff --git a/trunk/gosa-plugins/goto/addons/goto/events/class_DaemonEvent.inc b/trunk/gosa-plugins/goto/addons/goto/events/class_DaemonEvent.inc index 6268d9c0e..e46fd57e5 100644 --- a/trunk/gosa-plugins/goto/addons/goto/events/class_DaemonEvent.inc +++ b/trunk/gosa-plugins/goto/addons/goto/events/class_DaemonEvent.inc @@ -409,6 +409,54 @@ class DaemonEvent } + /*! \brief Save an event dialog and check if multiple events needs to be created */ + static function save_event_dialog($dialog, $current, $o_queue, $config) + { + if(is_object($dialog)){ + $dialog->save_object(); + if($dialog->multiple_events) { + $event_type = get_class($dialog); + $targets = $dialog->get_targets(); + $timestamp = $dialog->timestamp; + + $i = 1; + $count = count($targets); + while($i <= $count) { + $operations = $dialog->concurrent_operations; + $event = new $event_type($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(!$o_queue->append($event)){ + msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG); + } + + # Calculate start time for the next run + $timestamp = $timestamp + ($dialog->time_offset*60); + } + + return(array(FALSE, -1)); + } else { + $dialog->save_object(); + if(!$o_queue->append($dialog)){ + msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG); + return(array($dialog, $current)); + }else{ + return(array(FALSE, -1)); + } + } + } +} + /*! \brief Returns a complete list of all available events. @return Array Containing $this->get_event_info() for all available events. */ diff --git a/trunk/gosa-plugins/systems/admin/systems/class_systemManagement.inc b/trunk/gosa-plugins/systems/admin/systems/class_systemManagement.inc index f07b78ae1..3d9fa94b5 100644 --- a/trunk/gosa-plugins/systems/admin/systems/class_systemManagement.inc +++ b/trunk/gosa-plugins/systems/admin/systems/class_systemManagement.inc @@ -848,12 +848,8 @@ class systems extends plugin */ if(isset($_POST['save_event_dialog']) || $this->systab->get_type() == TRIGGERED_EVENT){ $o_queue = new gosaSupportDaemon(); - $o_queue->append($this->systab); - if($o_queue->is_error()){ - msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG); - }else{ - $this->systab = FALSE; - } + $this->systab = DaemonEvent::save_event_dialog($this->systab, NULL, $o_queue, $this->config); + } if(isset($_POST['abort_event_dialog'])){ $this->systab = FALSE; -- 2.30.2