Exemplo n.º 1
0
 public function restartTask()
 {
     $this->data['output'] = array();
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $task_id = (int) $this->request->get_or_post('task_id');
     $etas = array();
     if ($task_id) {
         $tm = new ATaskManager();
         $steps = $tm->getTaskSteps($task_id);
         foreach ($steps as $step) {
             if (!$step['settings']['to']) {
                 $tm->deleteStep($step['step_id']);
             } else {
                 $tm->updateStep($step['step_id'], array('status' => 1));
                 $etas[$step['step_id']] = $step['max_execution_time'];
             }
         }
         $task_details = $tm->getTaskById($task_id);
         if (!$task_details || !$task_details['steps']) {
             //remove task when it does not contain steps
             if (!$task_details['steps']) {
                 $tm->deleteTask($task_id);
             }
             $error_text = "Mail/Notification Sending Error: Cannot to restart task #" . $task_id . '. Task removed.';
             $error = new AError($error_text);
             return $error->toJSONResponse('APP_ERROR_402', array('error_text' => $error_text, 'reset_value' => true));
         }
         foreach ($etas as $step_id => $eta) {
             $task_details['steps'][$step_id]['eta'] = $eta;
         }
         $this->data['output']['task_details'] = $task_details;
     } else {
         $error = new AError(implode('<br>', $this->errors));
         return $error->toJSONResponse('VALIDATION_ERROR_406', array('error_text' => 'Unknown task ID.', 'reset_value' => true));
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->load->library('json');
     $this->response->addJSONHeader();
     $this->response->setOutput(AJson::encode($this->data['output']));
 }