Exemplo n.º 1
0
 /**
  * post-trigger of task
  */
 public function complete()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $task_id = (int) $this->request->post['task_id'];
     if ($task_id) {
         $tm = new ATaskManager();
         //get backup_name
         $steps = $tm->getTaskSteps($task_id);
         if ($steps) {
             $step_info = current($steps);
             $backup_name = $step_info['settings']['backup_name'];
             $backup_name = !$backup_name ? 'manual_backup' : $backup_name;
         }
         $tm->deleteTask($task_id);
         $install_upgrade_history = new ADataset('install_upgrade_history', 'admin');
         $display_name = '';
         if (is_file(DIR_BACKUP . $backup_name . '.tar.gz')) {
             $display_name = $backup_name . '.tar.gz';
             $result_text = $this->html->convertLinks($this->language->get('backup_complete_text_file'));
         } elseif (is_dir(DIR_BACKUP . $backup_name)) {
             $display_name = $backup_name . '/...';
             $result_text = sprintf($this->language->get('backup_complete_text_dir'), DIR_BACKUP . $backup_name);
         }
         $install_upgrade_history->addRows(array('date_added' => date("Y-m-d H:i:s", time()), 'name' => 'Manual Backup', 'version' => VERSION, 'backup_file' => $display_name, 'backup_date' => date("Y-m-d H:i:s", time()), 'type' => 'backup', 'user' => $this->user->getUsername()));
     }
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
     $this->load->library('json');
     $this->response->addJSONHeader();
     $this->response->setOutput(AJson::encode(array('result' => true, 'result_text' => $result_text)));
 }
Exemplo n.º 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;
 }
Exemplo n.º 3
0
 public function incompleted()
 {
     //init controller data
     $this->extensions->hk_InitData($this, __FUNCTION__);
     $this->loadModel('user/user');
     $this->data = $this->language->getASet('sale/contact');
     $tm = new ATaskManager();
     $incompleted = $tm->getTasks(array('filter' => array('name' => 'send_now')));
     $k = 0;
     foreach ($incompleted as $incm_task) {
         //show all incompleted tasks for Top Administrator user group
         if ($this->user->getUserGroupId() != 1) {
             if ($incm_task['starter'] != $this->user->getId()) {
                 continue;
             }
         }
         //define incompleted tasks by last time run
         $max_exec_time = (int) $incm_task['max_execution_time'];
         if (!$max_exec_time) {
             //if no limitations for execution time for task - think it's 2 hours
             //$max_exec_time = 7200;
             $max_exec_time = 7200;
         }
         if (time() - dateISO2Int($incm_task['last_time_run']) > $max_exec_time) {
             //get some info about task, for ex message-text and subject
             $steps = $tm->getTaskSteps($incm_task['task_id']);
             if (!$steps) {
                 $tm->deleteTask($incm_task['task_id']);
             }
             $user_info = $this->model_user_user->getUser($incm_task['starter']);
             $incm_task['starter_name'] = $user_info['username'] . ' ' . $user_info['firstname'] . ' ' . $user_info['lastname'];
             $step = current($steps);
             $step_settings = $step['settings'];
             if ($step_settings['subject']) {
                 $incm_task['subject'] = $step_settings['subject'];
             }
             $incm_task['message'] = mb_substr($step_settings['message'], 0, 300);
             $incm_task['date_added'] = dateISO2Display($incm_task['date_added'], $this->language->get('date_format_short') . ' ' . $this->language->get('time_format'));
             $incm_task['last_time_run'] = dateISO2Display($incm_task['last_time_run'], $this->language->get('date_format_short') . ' ' . $this->language->get('time_format'));
             $incm_task['was_sent'] = sprintf($this->language->get('text_was_sent'), $incm_task['settings']['sent'], $incm_task['settings']['recipients_count']);
             $this->data['tasks'][$k] = $incm_task;
         }
         $k++;
     }
     $this->data['restart_task_url'] = $this->html->getSecureURL('r/sale/contact/restartTask');
     $this->data['complete_task_url'] = $this->html->getSecureURL('r/sale/contact/complete');
     $this->data['abort_task_url'] = $this->html->getSecureURL('r/sale/contact/abort');
     $this->view->batchAssign($this->data);
     $this->processTemplate('responses/sale/contact_incompleted.tpl');
     //update controller data
     $this->extensions->hk_UpdateData($this, __FUNCTION__);
 }