Ejemplo n.º 1
0
 /**
  * @param int $task_id
  * @throws Exception
  */
 public function __construct($task_id = null)
 {
     if ($task_id) {
         $this->id = $task_id;
     } else {
         $id_gen = new Model_IdGen();
         $_id = $id_gen->gen_inc_id_by_key(Const_DataAccess::ID_TASK);
         if ($_id['errno'] != Const_Err_Base::ERR_OK) {
             throw new Exception('Get task id failed!!!! ' . json_encode($_id));
         }
         $this->id = $_id['data'];
         unset($id_gen);
     }
     $this->create_time = time();
 }
Ejemplo n.º 2
0
 /**
  * @return array
  */
 public function save()
 {
     if (empty($this->id)) {
         $id_gen = new Model_IdGen();
         $id = $id_gen->gen_inc_id_by_key(Const_DataAccess::ID_FLOW);
         if ($id['errno'] != Const_Err_Base::ERR_OK) {
             return $id;
         }
         $id = $id['data'];
         if (empty($id)) {
             return Lib_Helper::get_err_struct(Const_Err_DataAccess::ERR_GET_ID_FAILD, '获取ID失败', __FILE__, __LINE__);
         }
         $this->id = $id;
     }
     if (empty($this->flow) || empty($this->id)) {
         return Lib_Helper::get_err_struct(Const_Err_DataAccess::ERR_FLOW_EMPTY_FLOW, '[空流程] 未设置流程', __FILE__, __LINE__);
     }
     $data = [Model_FlowInfo::FIELD_FLOW_ID => $this->id, Model_FlowInfo::FIELD_FLOW_NAME => $this->name, Model_FlowInfo::FIELD_FLOW_FLOW => $this->flow, Model_FlowInfo::FIELD_FLOW_OPTIONS => $this->options];
     $flow_model = new Model_FlowInfo();
     $save = $flow_model->save($data);
     if ($save['errno'] !== Const_Err_Base::ERR_OK) {
         Lib_Log::error(__METHOD__ . ' faild! cause: ' . json_encode($save['data']));
         return Lib_Helper::get_err_struct(Const_Err_Db::ERR_SAVE_DATA_FAIL, __METHOD__ . '数据保存失败', __FILE__, __LINE__);
     }
     return Lib_Helper::get_return_struct($this->id);
 }
Ejemplo n.º 3
0
 /**
  * @return bool
  */
 function register_modules()
 {
     $all_modules = $this->_get_all_modules_from_path();
     $registered_modules = $this->get_registered_modules();
     foreach ($registered_modules as $_k => $_m) {
         $registered_modules[$_m['indentify']] = $_m;
         unset($registered_modules[$_k]);
     }
     $new_modules = [];
     $id_gen = new Model_IdGen();
     foreach ($all_modules as $_i => $_m) {
         if (isset($registered_modules[$_i])) {
             $_r_module = $registered_modules[$_i];
             if (Lib_Helper::str_equal($_r_module[Const_Module::META_VERSION], $_m[Const_Module::META_VERSION]) === false) {
                 $_m[Model_ModulesInfo::FIELD_MODULE_ID] = $_r_module[Model_ModulesInfo::FIELD_MODULE_ID];
                 $_m[Model_ModulesInfo::FIELD_MODULE_REG_TIME] = time();
                 $new_modules[] = $_m;
             }
             unset($registered_modules[$_i]);
         } else {
             $_id = $id_gen->gen_inc_id_by_key(Const_DataAccess::ID_MODULE);
             if ($_id['errno'] != Const_Err_Base::ERR_OK) {
                 Lib_Log::error("get moduel id failed, result: %s", json_encode($_id));
                 return false;
             }
             $_id = $_id['data'];
             if (empty($_id)) {
                 Lib_Log::error('module id gen failed!');
                 continue;
             }
             $_m[Model_ModulesInfo::FIELD_MODULE_ID] = $_id;
             $_m[Model_ModulesInfo::FIELD_MODULE_REG_TIME] = time();
             $new_modules[] = $_m;
         }
     }
     $insert = false;
     if (!empty($new_modules)) {
         $modules_info = new Model_ModulesInfo();
         foreach ($new_modules as $_m) {
             $modules_info->save($_m);
         }
         $insert = true;
     }
     return $insert;
 }