예제 #1
0
 /**
  * 删除模型
  */
 public function action()
 {
     $modelId = $this->isG('id', '请选择要删除的数据!');
     $model = \Model\ModelManage::findModel($modelId);
     if (empty($model)) {
         $this->error('模型不存在');
     }
     $this->db()->transaction();
     $deleteModelResult = \Model\ModelManage::deleteModel($modelId);
     if (empty($deleteModelResult)) {
         $this->db()->rollBack();
         $this->error('删除模型失败');
     }
     $deleteModelField = \Model\Field::deleteModelField($modelId);
     if (empty($deleteModelField)) {
         $this->db()->rollBack();
         $this->error('移除模型字段记录失败');
     }
     $this->db('menu')->where('menu_name = :name')->delete(['name' => $model['model_title']]);
     $this->db()->commit();
     $alterTableResult = \Model\ModelManage::alterTable(strtolower($model['model_name']));
     if (empty($alterTableResult)) {
         $log = new \Expand\Log();
         $failLog = "Alter Model Table Field: {$this->prefix}{$model['model_name']}" . date("Y-m-d H:i:s");
         $log->creatLog('modelError', $failLog);
         $this->error('删除数据库表失败,具体信息请查阅程序日志');
     }
     $this->success('删除成功');
 }
예제 #2
0
 /**
  * 初始化模型表
  * 基础字段:模型_id,模型_listsort,模型_lang,模型_url,模型_status,模型_createtime
  */
 public static function initModelTable($model)
 {
     $model = strtolower($model);
     $table = self::$modelPrefix . $model;
     $initResult = self::db()->alter("CREATE TABLE IF NOT EXISTS `{$table}` (`{$model}_id` int(11) NOT NULL AUTO_INCREMENT, `{$model}_listsort` int(11) NOT NULL,`{$model}_status` tinyint(4) NOT NULL, `{$model}_url` VARCHAR( 255 ) NOT NULL, `{$model}_createtime` int(11) NOT NULL, PRIMARY KEY (`{$model}_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;");
     if ($initResult == false) {
         $log = new \Expand\Log();
         $failLog = "Create Model Table : {$table}" . date("Y-m-d H:i:s");
         $log->creatLog('modelError', $failLog);
         self::error("创建{$table}表失败");
     }
 }
예제 #3
0
 /**
  * 删除字段
  */
 public function fieldAction()
 {
     $id = $this->isG('id', $GLOBALS['_LANG']['COMMON']['DELETE_ID']);
     $field = \Model\Field::findField($id);
     if (empty($field)) {
         $this->error($GLOBALS['_LANG']['MODEL']['NOT_EXIST_FIELD']);
     }
     $removeFieldResult = \Model\Field::removeField($id);
     if (empty($removeFieldResult)) {
         $this->error($GLOBALS['_LANG']['COMMON']['DELETE_ERROR']);
     }
     $model = \Model\Model::findModel($field['model_id']);
     $alertTableFieldResult = \Model\Field::alertTableField($model['model_name'], $field['field_name']);
     if (empty($alertTableFieldResult)) {
         $log = new \Expand\Log();
         $failLog = "Delete Field: " . strtolower($model['model_name']) . "_{$field['field_name']}, Model:{$model['model_name']}  " . date("Y-m-d H:i:s");
         $log->creatLog('fieldError', $failLog);
         $this->error($GLOBALS['_LANG']['MODEL']['ALERT_TABLE_FIELD_ERROR']);
     }
     $this->success($GLOBALS['_LANG']['COMMON']['DELETE_SUCCESS']);
 }
예제 #4
0
 public function action()
 {
     $id = $this->isG('id', '请选择要删除的数据!');
     $field = \Model\Field::findField($id);
     if (empty($field)) {
         $this->error('不存在的字段');
     }
     $removeFieldResult = \Model\Field::removeField($id);
     if (empty($removeFieldResult)) {
         $this->error('删除失败');
     }
     $model = \Model\ModelManage::findModel($field['field_model_id']);
     $alertTableFieldResult = \Model\Field::alertTableField($model['model_name'], $field['field_name']);
     if (empty($alertTableFieldResult)) {
         $log = new \Expand\Log();
         $failLog = "Delete Field: " . strtolower($model['model_name']) . "_{$field['field_name']}, Model:{$model['model_name']}  " . date("Y-m-d H:i:s");
         $log->creatLog('fieldError', $failLog);
         $this->error('移除数据库表字段失败,具体信息请查阅程序日志');
     }
     $this->success('删除成功');
 }
예제 #5
0
 /**
  * 添加模型
  */
 public function action()
 {
     $this->db()->transaction();
     /**
      * 插入模型信息
      */
     $addModelresult = \Model\Model::addModel();
     if ($addModelresult['status'] == false) {
         $this->db()->rollBack();
         $this->error($addModelresult['mes']);
     }
     /**
      * 插入模型菜单
      */
     $addMenuResult = \Model\Menu::insertModelMenu($addModelresult['mes']['lang_key'], '9', "Team-{$addModelresult['mes']['model_name']}-index");
     if ($addMenuResult == false) {
         $this->db()->rollBack();
         $this->error($GLOBALS['_LANG']['MENU']['ADD_MENU_FAIL']);
     }
     /**
      * 插入初始化的字段
      */
     $setFieldResult = \Model\Model::setInitField($addModelresult['mes']['model_id']);
     if ($setFieldResult['status'] == false) {
         $this->db()->rollBack();
         $this->error($setFieldResult['mes']);
     }
     $this->db()->commit();
     $initResult = \Model\Model::initModelTable($addModelresult['mes']['model_name']);
     if ($setFieldResult['status'] == false) {
         $log = new \Expand\Log();
         $failLog = "Create Model Table Field: {$setFieldResult['mes']}" . date("Y-m-d H:i:s");
         $log->creatLog('modelError', $failLog);
         $this->error($GLOBALS['_LANG']['MODEL']['CREATE_TABLE_ERROR']);
     }
     $this->success($GLOBALS['_LANG']['MODEL']['ADD_MODEL_SUCCESS'], $this->url('Team-Model-index'));
 }
예제 #6
0
 /**
  * 记录错误日志
  * @param type $error 错误信息
  */
 private static function recordLog($error, $extract = true)
 {
     $fileName = 'error_' . md5(self::loadConfig('PRIVATE_KEY') . date("Ymd"));
     $msg = 'Date:' . date('Y-m-d H:i:s') . "\rTimestamp:" . time() . "\r";
     if ($extract == true) {
         $msg .= "Rank[{$error['type']}] PHP error: {$error['message']}\rFile:{$error['file']};Line:{$error['line']}\r\r";
     } else {
         $msg .= "{$error}\r";
     }
     $msg .= "\r\r";
     $log = new \Expand\Log();
     $log->creatLog($fileName, $msg);
 }