示例#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']));
 }
示例#2
0
 private function _send()
 {
     $this->loadLanguage('sale/contact');
     $task_id = (int) $this->request->get['task_id'];
     $step_id = (int) $this->request->get['step_id'];
     if (!$task_id || !$step_id) {
         $error_text = 'Cannot run task step. Task_id (or step_id) has not been set.';
         $this->_return_error($error_text);
     }
     $tm = new ATaskManager();
     $task_info = $tm->getTaskById($task_id);
     $sent = (int) $task_info['settings']['sent'];
     $task_steps = $tm->getTaskSteps($task_id);
     $step_info = array();
     foreach ($task_steps as $task_step) {
         if ($task_step['step_id'] == $step_id) {
             $step_info = $task_step;
             if ($task_step['sort_order'] == 1) {
                 $tm->updateTask($task_id, array('last_time_run' => date('Y-m-d H:i:s')));
             }
             break;
         }
     }
     if (!$step_info) {
         $error_text = 'Cannot run task step. Looks like task #' . $task_id . ' does not contain step #' . $step_id;
         $this->_return_error($error_text);
     }
     $tm->updateStep($step_id, array('last_time_run' => date('Y-m-d H:i:s')));
     if (!$step_info['settings'] || !$step_info['settings']['to']) {
         $error_text = 'Cannot run task step #' . $step_id . '. Unknown settings for it.';
         $this->_return_error($error_text);
     }
     $this->loadModel('sale/customer');
     $this->loadModel('setting/store');
     $store_info = $this->model_setting_store->getStore((int) $this->session->data['current_store_id']);
     $from = '';
     if ($store_info) {
         $from = $store_info['store_main_email'];
     }
     if (!$from) {
         $from = $this->config->get('store_main_email');
     }
     $send_data = array('subject' => $step_info['settings']['subject'], 'message' => $step_info['settings']['message'], 'sender' => $step_info['settings']['store_name'], 'from' => $from);
     //send emails in loop and update task's step info for restarting if step or task failed
     $step_settings = $step_info['settings'];
     $cnt = 0;
     $step_result = true;
     foreach ($step_info['settings']['to'] as $to) {
         $send_data['subscriber'] = in_array($to, $step_info['settings']['subscribers']) ? true : false;
         if ($this->protocol == 'email') {
             $result = $this->_send_email($to, $send_data);
         } elseif ($this->protocol == 'sms') {
             $result = $this->_send_sms($to, $send_data);
         } else {
             $result = false;
         }
         if ($result) {
             //remove sent address from step
             $k = array_search($to, $step_settings['to']);
             unset($step_settings['to'][$k]);
             $tm->updateStep($step_id, array('settings' => serialize($step_settings)));
             //update task details to show them at the end
             $sent++;
             $tm->updateTaskDetails($task_id, array('created_by' => $this->user->getId(), 'settings' => array('recipients_count' => $task_info['settings']['recipients_count'], 'sent' => $sent)));
         } else {
             $step_result = false;
         }
         $cnt++;
     }
     $tm->updateStep($step_id, array('last_result' => $step_result));
     if (!$step_result) {
         $this->_return_error('Some errors during step run. See log for details.');
     }
     return $step_result;
 }
示例#3
0
 public function restart()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->load->library('json');
     $this->response->addJSONHeader();
     if (has_value($this->request->post_or_get('task_id'))) {
         $tm = new ATaskManager();
         $task = $tm->getTaskById($this->request->post_or_get('task_id'));
         //check
         if ($task && $task['status'] == 2 && time() - dateISO2Int($task['start_time']) > 1800) {
             foreach ($task['steps'] as $step) {
                 $tm->updateStep($step['step_id'], array('status' => 1));
             }
             $tm->updateTask($task['task_id'], array('status' => 1, 'start_time' => date('Y-m-d H:i:s'), 'last_result' => 2));
         }
         $this->_run_task();
     } else {
         $this->response->setOutput(AJson::encode(array('result' => false)));
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }