Exemple #1
0
 /**
  * @param string $key
  * @throws Exception
  */
 static function save_md_data($key)
 {
     if (!isset(self::$_action_list[$key])) {
         self::_error_and_redirect('不存在此页', '/');
     }
     $actions = self::$_action_list[$key];
     $content = Lib_Request::post_var('content');
     if (trim($content) == '') {
         Lib_Request::flash('error', '提交内容为空');
         Module_HttpRequest_Router::redirect_to($actions[self::URL]);
     }
     $keyword = $actions[self::KEYWORD];
     $model_option = new Model_Option();
     $content = str_replace("\r", '', $content);
     $content = str_replace("\n", '\\n', $content);
     //$content = htmlentities($content);
     $result = $model_option->update_option_by_keyword($keyword, $content);
     if ($result['errno'] != Const_Err_Base::ERR_OK) {
         self::_error_and_redirect(Lib_Helper::format_err_struct($result), $actions[self::URL]);
     } else {
         $help2opcode = ['help_index' => Module_OperationRecord_Main::OPCODE_HELP_INFO, 'help_dev' => Module_OperationRecord_Main::OPCODE_HELP_DEVELOP, 'help_todo' => Module_OperationRecord_Main::OPCODE_HELP_TODO, 'internal_api' => Module_OperationRecord_Main::OPCODE_HELP_INTERNAL, 'open_api' => Module_OperationRecord_Main::OPCODE_HELP_OPEN];
         $opcode = isset($help2opcode[$keyword]) ? $help2opcode[$keyword] : Module_OperationRecord_Main::OPCODE_HELP_INFO;
         Module_OperationRecord_Main::add_record($opcode);
         Lib_Request::flash('保存成功');
         Module_HttpRequest_Router::redirect_to($actions[self::URL]);
     }
 }
Exemple #2
0
 /**
  * 文件任务入口
  * @param int $ap_id
  * @param array $data
  * @param array $options
  * @param int $task_id
  * @return array
  */
 static function run_task_by_ap_id_and_record($ap_id, $data = [], $options = [], $task_id = null)
 {
     // get ap info
     $ap_manager = Module_ControlCentre_ApManager::get_instance()->set_current_ap($ap_id);
     if (empty($ap_manager)) {
         return Lib_Helper::get_err_struct(Const_Err_DataAccess::ERR_GET_ACCESS_POINT_FAILD, 'Get ap failed! Result:' . Lib_Helper::format_err_struct($ap_id));
     }
     $task_model = new Model_Task();
     $nearest_task = $task_model->get_nearest_task_by_ap_id($ap_id, null, ['status', 'create_time']);
     if ($nearest_task[Const_DataAccess::MREK_ERRNO] != Const_Err_Base::ERR_OK) {
         return $nearest_task;
     }
     $nearest_task = $nearest_task[Const_DataAccess::MREK_DATA];
     $ap_info = $ap_manager->get_current_ap();
     if (!empty($nearest_task)) {
         if (isset($nearest_task['status']) && $nearest_task['status'] == self::TASK_STATUS_RUNNING) {
             $msg = self::_pre_task_running_mail_msg($ap_info, $nearest_task);
             $people = Module_ControlCentre_ApManager::interface_people(false);
             empty($people) || Da\Sys_App::run_in_mode(['Module_Notification_Mail', 'send_mail'], [implode(';', $people), '接入点[' . $ap_id . ']任务运行失败', $msg]);
             return Lib_Helper::get_err_struct(Const_Err_DataAccess::ERR_TASK_STATUS, 'pre-task is running!');
         }
     }
     // get flow info
     $flow_id = $ap_info[Module_FlowManager_Main::KEY_FLOW_ID];
     $flow_manager = Module_ControlCentre_FlowManager::get_instance()->set_current_flow($flow_id);
     if (empty($flow_manager)) {
         return Lib_Helper::get_err_struct(Const_Err_DataAccess::ERR_FLOW_NOT_EXISTS, '流程[' . $flow_id . ']不存在');
     }
     $flow_options = [];
     if (isset($options[Const_DataAccess::RUN_OPTION_FLOW_INFO])) {
         $flow_options = $options[Const_DataAccess::RUN_OPTION_FLOW_INFO];
         if (isset($flow_options[Module_FlowManager_Main::RUN_MODE])) {
             $run_mode = $flow_options[Module_FlowManager_Main::RUN_MODE];
             $flow_manager->set_run_mode($run_mode);
         }
         if (isset($flow_options[Module_FlowManager_Main::RUN_OPTION_CUSTOM_FLOW])) {
             $custom_flow = $flow_options[Module_FlowManager_Main::RUN_OPTION_CUSTOM_FLOW];
             $flow_manager->custom_flow($custom_flow);
         }
     }
     empty($flow_options) || $flow_manager->custom_options($flow_options);
     // end process current flow
     $options[Const_DataAccess::RUN_OPTION_FLOW_ID] = intval($flow_id);
     //$options[Const_DataAccess::RUN_OPTION_ACCESS_POINT_INFO] = $ap_info;
     isset($ap_info[Module_AccessPoint_Main::FIELD_SOURCE_ID]) && ($options[Const_DataAccess::RUN_OPTION_SRC_ID] = $ap_info[Module_AccessPoint_Main::FIELD_SOURCE_ID]);
     self::get_instance()->create_task($task_id);
     Module_ControlCentre_Counter::enable();
     self::_add_task_record_hook($options);
     self::_add_module_prepare_to_run_hook();
     self::_add_module_record_hook();
     self::_add_flow_stat_hook();
     self::_add_module_ratio_hook();
     Da\Sys_App::run_in_mode(function () {
         self::_add_failed_mail_hook();
     });
     return self::get_instance()->run_current_task($data, $options);
 }
Exemple #3
0
 /**
  * @return array
  * @throws Exception
  */
 function get_nav()
 {
     if ($this->_nav === null) {
         $mo = new Model_Option();
         $nav = $mo->get_one_by_keyword(Module_Page_Manager::SAVE_KEY_NAV);
         if ($nav[Const_DataAccess::MREK_ERRNO] != Const_Err_Base::ERR_OK) {
             throw new Exception(Lib_Helper::format_err_struct($nav), $nav[Const_DataAccess::MREK_ERRNO]);
         }
         $this->_nav = $nav[Const_DataAccess::MREK_DATA]['value'];
     }
     return $this->_nav;
 }
Exemple #4
0
 /**
  * @param int $id
  * @return $this|null
  */
 function set_current_ap($id)
 {
     if (isset($this->_ap_list[$id])) {
         $this->_current_ap_id = $id;
         $this->_current_ap = $this->_ap_list[$id];
     } else {
         $ap_info = Module_AccessPoint_Ap::get_ap($id);
         if ($ap_info['errno'] !== Const_Err_Base::ERR_OK) {
             Lib_Log::notice('Get ap faild! Result: %s', Lib_Helper::format_err_struct($ap_info));
             $this->_current_ap_id = null;
             $this->_current_ap = null;
             return null;
         }
         $ap_info = $ap_info['data'];
         $this->set_current_ap_info($id, $ap_info);
     }
     return $this;
 }
Exemple #5
0
 /**
  * @param int $task_id
  * @param int $mid
  * @param string $class
  * @return string
  */
 private function _loop_callback_hook($task_id, $mid, $class)
 {
     if (!isset($this->flow[Module_FlowManager_Main::FLOW_TYPE_MAIN]) || !isset($this->flow[Module_FlowManager_Main::FLOW_TYPE_STUFF])) {
         Lib_Log::info("empty task flow main or stuff, will not run callback hook, id: %d", $this->id);
         return null;
     }
     // 安全检查,只有主模块才能注册回调
     $main_mids = $this->flow[Module_FlowManager_Main::FLOW_TYPE_MAIN];
     if (!in_array($mid, $main_mids)) {
         Lib_Log::notice("mid [%d] not in flow, flow id: [%d]", [$mid, $this->id]);
         return null;
     }
     // 没有回调方案
     $callback_relation_mids = $this->flow[Module_FlowManager_Main::FLOW_TYPE_STUFF];
     if (!isset($callback_relation_mids[$mid])) {
         return null;
     }
     Lib_Log::debug(function () use($mid, $callback_relation_mids) {
         return vsprintf("FLOW_CALL: prepare to gen callback for mid [%d], mids [%s]", [$mid, json_encode($callback_relation_mids[$mid])]);
     });
     // 生成回调
     $callback = $this->gen_module_callback_in_loop($task_id, $mid);
     // 注册
     if ($callback['errno'] == Const_Err_Base::ERR_OK) {
         $callback = $callback['data'];
         Lib_Log::debug(function () use($task_id, $mid, $callback, $class) {
             return vsprintf("FLOW_CALL: register callback to class [%s], mid: %d", [get_class($class), $mid]);
         });
         $class->register_callback($callback);
     } else {
         Lib_Log::notice("FLOW_CALL: gen callback failed. return %s", Lib_Helper::format_err_struct($callback));
     }
 }
Exemple #6
0
 /**
  * @param int $module_id
  * @return array
  */
 function get_module_info_by_id($module_id)
 {
     if (isset($this->_reg_modules[$module_id])) {
         return $this->_reg_modules[$module_id];
     }
     $module_info_model = new Model_ModulesInfo();
     $module = $module_info_model->get_module_by_id($module_id);
     if ($module['errno'] !== Const_Err_Base::ERR_OK) {
         Lib_Log::error(__METHOD__ . ' faild! cause: ' . Lib_Helper::format_err_struct($module));
         return [];
     }
     $this->_reg_modules[$module_id] = $module['data'];
     return $this->_reg_modules[$module_id];
 }
Exemple #7
0
 static function task_list_action()
 {
     $task_id = Lib_Request::get_int('task_id');
     $ap_name = Lib_Request::get_var('ap_name');
     $ap_name = trim($ap_name);
     $src_id = Lib_Request::get_var('sub_src');
     $src_id = trim($src_id);
     $status = Lib_Request::get_int('status');
     $time_begin = Lib_Request::get_var('time_begin');
     $time_begin = trim($time_begin);
     $time_end = Lib_Request::get_var('time_end');
     $time_end = trim($time_end);
     $cond = [];
     $search_vars = [];
     $ap_cond = [];
     if (!empty($task_id)) {
         $cond = ['_id' => $task_id];
         $search_vars = ['task_id' => $task_id];
     } else {
         if (strpos($src_id, ',')) {
             $src_ids = explode(',', $src_id);
             $int_src_ids = [];
             foreach ($src_ids as $k => $v) {
                 $int_src_ids[] = intval($v);
             }
             $cond['src_id'] = ['$in' => array_merge($src_ids, $int_src_ids)];
         } elseif (!empty($src_id)) {
             $cond['src_id'] = ['$in' => [$src_id, intval($src_id)]];
         }
         if (!empty($status)) {
             $cond['status'] = $status;
             $search_vars['status'] = $status;
         }
         if (!empty($time_begin) || !empty($time_end)) {
             $time_cond = [];
             if (!empty($time_begin)) {
                 $time_begin = strtotime($time_begin);
                 $time_cond['$gt'] = $time_begin;
             }
             if (!empty($time_end)) {
                 $time_end = strtotime($time_end);
                 $time_cond['$lte'] = $time_end;
             }
             if ($time_begin >= $time_end) {
                 unset($time_cond['$lte']);
             }
             if (!empty($time_cond)) {
                 $cond['create_time'] = $time_cond;
             }
         }
     }
     if (!Module_Account_User::has_perms([Module_Account_Perm::PERM_AP_ADMIN])) {
         $ap_cond['interface_people'] = new MongoRegex("/" . Module_Account_User::get_current_user() . "/");
     }
     if (!empty($ap_name)) {
         $ap_cond = ['ap_name' => new MongoRegex("/" . $ap_name . "/")];
     }
     if (!empty($ap_cond)) {
         $search_vars['ap_name'] = $ap_name;
         $ap_ids = [];
         $int_ap_ids = [];
         $model = new Model_AccessPoint();
         $ap_infos = $model->get_all($ap_cond);
         if ($ap_infos['errno'] == Const_Err_Base::ERR_OK) {
             foreach ($ap_infos['data'] as $k => $ap) {
                 $ap_ids[] = $ap['ap_id'];
                 $int_ap_ids[] = intval($ap['ap_id']);
             }
         }
         $cond['ap_id'] = ['$in' => array_merge($ap_ids, $int_ap_ids)];
     }
     $model_task = new Model_Task();
     $total_num = $model_task->get_tasks_count($cond);
     $current_page = Lib_Request::get_int('page');
     //当前页码,必须
     $total_size = isset($total_num['data']) ? intval($total_num['data']) : 0;
     //总记录数,必须
     $page_size = 15;
     //每页条数,必须
     $skip = ($current_page - 1) * $page_size;
     //跳过记录,必须
     $skip = $skip < 0 ? 0 : $skip;
     $mode = 2;
     //页码模式,决定页码个数,默认1
     $tasks = $model_task->get_all($cond, $page_size, $skip);
     if ($tasks['errno'] !== Const_Err_Base::ERR_OK) {
         Lib_Log::error(Lib_Helper::format_err_struct($tasks));
         $tasks = [];
         Lib_Request::flash('未获取到任务信息');
     }
     $tasks = $tasks['data'];
     $ap_infos = [];
     $ap_model = new Model_AccessPoint();
     foreach ($tasks as $_k => $_t) {
         $ap_info = $ap_model->get_ap_by_id($_t['ap_id']);
         $ap_info['ap_id'] = $_t['ap_id'];
         if ($ap_info['errno'] !== Const_Err_Base::ERR_OK) {
             Lib_Log::error(Lib_Helper::format_err_struct($ap_info));
             Lib_Request::flash('获取接入点信息失败');
             Module_HttpRequest_Router::redirect_to('/');
         }
         $ap_info = $ap_info[Const_DataAccess::MREK_DATA];
         $ap_infos[$_t['ap_id']] = $ap_info;
     }
     $source_model = new Model_Source();
     $all_sources = $source_model->get_all();
     $sources = $all_sources[Const_DataAccess::MREK_DATA];
     $all_src_type = [];
     foreach ($all_sources['data'] as $k => $v) {
         if (!in_array($v['src_type'], $all_src_type)) {
             $all_src_type[] = $v['src_type'];
         }
     }
     asort($all_src_type);
     $task_status_list = Module_ControlCentre_Main::$task_status_list;
     $pages = Module_View_Template::get_pages_html($current_page, $total_size, $page_size, $mode);
     Module_Page_Main::render('control_centre/task_list', ['ap_info' => $ap_infos, 'tasks' => $tasks, 'sources' => $sources, 'pages' => $pages, 'all_src_type' => $all_src_type, 'status_list' => $task_status_list, 'search_vars' => $search_vars]);
 }
Exemple #8
0
#!/usr/bin/env php
<?php 
require_once dirname(dirname(dirname(__FILE__))) . '/app/init.php';
$options = getopt('a:t:m:');
if (!isset($options['a']) || !isset($options['t']) || !isset($options['m'])) {
    p('use as xxx -a ap_id -t task_id -m module_id');
    exit;
}
$ap_id = $options['a'];
//'16723523721449231476';
$task_id = $options['t'];
// 123
$module_id = $options['m'];
//'9691047284819742687'
$control_options = [Const_DataAccess::RUN_OPTION_FLOW_INFO => [Module_FlowManager_Main::RUN_MODE => Module_FlowManager_Main::RUN_MODE_SINGLE_MODULE, Module_FlowManager_Main::RUN_OPTION_SINGLE_MODULE_ID => $module_id]];
$ap_info = Module_AccessPoint_Ap::get_ap($ap_id);
if ($ap_info['errno'] !== Const_Err_Base::ERR_OK) {
    p('Get ap faild! Result:' . Lib_Helper::format_err_struct($ap_info));
    exit;
}
$ap_info = $ap_info['data'];
$flow_id = $ap_info[Module_FlowManager_Main::KEY_FLOW_ID];
unset($ap_info[Module_FlowManager_Main::KEY_FLOW_ID]);
$control_options[Const_DataAccess::RUN_OPTION_ACCESS_POINT_INFO] = $ap_info;
$data = Module_ControlCentre_Main::run($flow_id, $control_options, $task_id);
p($data);
exit;
Exemple #9
0
 static function index_action()
 {
     $model_task = new Model_Task();
     $tasks = $model_task->get_all(['status' => 2], 10);
     if ($tasks['errno'] !== Const_Err_Base::ERR_OK) {
         Lib_Log::error(Lib_Helper::format_err_struct($tasks));
         $tasks = [];
     }
     $tasks = $tasks['data'];
     $ap_ids = [];
     $src_ids = [];
     foreach ($tasks as $_k => $_t) {
         $ap_ids[$_k] = isset($_t['ap_id']) ? $_t['ap_id'] : '';
         $src_ids[$_k] = isset($_t['src_id']) ? $_t['src_id'] : '';
     }
     $ap_model = new Model_AccessPoint();
     $aps = $ap_model->get_ap_by_ids($ap_ids);
     if ($aps['errno'] !== Const_Err_Base::ERR_OK) {
         Lib_Log::error(Lib_Helper::format_err_struct($aps));
         $aps = [];
     }
     $aps = $aps['data'];
     $source_model = new Model_Source();
     $sources = $source_model->get_sources_by_ids($src_ids);
     if ($sources['errno'] !== Const_Err_Base::ERR_OK) {
         Lib_Log::error(Lib_Helper::format_err_struct($sources));
         $sources = [];
     }
     $sources = $sources['data'];
     $gt_time = strtotime('-1 month');
     $source_model->set_table_name('t_src_statistics');
     $cond = ['update_time' => ['$gte' => $gt_time]];
     $source_statistics = $source_model->get_table()->get_all($cond, [], 0, 0, null, true);
     if ($source_statistics['errno'] !== Const_Err_Base::ERR_OK) {
         Lib_Log::error(Lib_Helper::format_err_struct($source_statistics));
         $source_statistics = [];
     }
     $source_statistics = $source_statistics['data'];
     $statistics = [];
     foreach ($source_statistics as $v) {
         $day = date('m-d', $v['update_time']);
         $statistics[$day] = isset($statistics[$day]) ? $statistics[$day] : [];
         $statistics[$day]['total'] = isset($statistics[$day]['total']) ? $statistics[$day]['total'] : 0;
         $statistics[$day]['status_1'] = isset($statistics[$day]['status_1']) ? $statistics[$day]['status_1'] : 0;
         $statistics[$day]['status_other'] = isset($statistics[$day]['status_other']) ? $statistics[$day]['status_other'] : 0;
         $statistics[$day]['total'] += intval($v['total']);
         $statistics[$day]['status_1'] += intval($v['status_1']);
         $statistics[$day]['status_other'] = $statistics[$day]['total'] - $statistics[$day]['status_1'];
     }
     foreach ($statistics as $day => $v) {
         $source_statistics_min = isset($source_statistics_min) && $source_statistics_min < $v['status_1'] ? $source_statistics_min : $v['status_1'];
     }
     $_access = Module_Statistics_Action::get_index_month_charts();
     $access_date = $_access['access_date'];
     $receive_data = $_access['receive_data'];
     $send_data = $_access['send_data'];
     self::render('common/index', ['tasks' => $tasks, 'aps' => $aps, 'sources' => $sources, 'source_statistics' => $statistics, 'source_statistics_min' => $source_statistics_min, 'access_date' => $access_date, 'send_data' => $send_data, 'receive_data' => $receive_data]);
 }