diff --git a/application/index/controller/Install.php b/application/index/controller/Install.php index c3d6970b..78a8492e 100644 --- a/application/index/controller/Install.php +++ b/application/index/controller/Install.php @@ -166,108 +166,4 @@ EOT; ]); return $this->fetch(); } - - public function update($start = 0) - { - try { - $user = false; - if (Session::has('uid')) { - $user = Users::get(Session::get('uid')); - if (!$user) { - Session::delete('uid'); - } - } - - if (!$user || !$user->is_admin) { - $this->redirect(url('/')); - } - - $path = Env::get('root_path') . 'update.sql'; - $file = @file_get_contents($path); - if (!$file) { - $this->redirect(url('/')); - } - - $code = 0; - $msg = null; - if ($start == 1) { - if ($file) { - $config = Config::pull('db'); - - // 替换sql关键字 - $file = str_replace([ - '{database}' - ], [ - $config['database'] - ], $file); - - $mysqli = new \mysqli( - $config['hostname'], - $config['username'], - $config['password'], - $config['database'], - $config['hostport'] - ); - if ($mysqli->connect_errno) { - $mysqli->close(); - throw new Exception($mysqli->connect_error); - } - - $mysqli->autocommit(false); - $mysqli->select_db($config['database']); - $mysqli->query("SET NAMES utf8"); - - // 新建表字段 - $tableFields = Config::pull('table'); - - foreach ($tableFields as $table => $fields) { - foreach ($fields as $field => $sql) { - $fetchFields = $mysqli->query("DESCRIBE `{$table}`;"); - // 判断字段是否已存在 - $flag = true; - foreach ($fetchFields as $fetchField) { - if ($field == $fetchField['Field']) { - $flag = false; - } - } - if ($flag) { - if (!$mysqli->query($sql)) { - throw new Exception($mysqli->error); - } - } - } - } - - foreach (explode(';', $file) as $value) { - if ($value && !ctype_space($value)) { - if (!$mysqli->query($value . ';')) { - throw new Exception('

数据导入失败!

错误信息:
' . $mysqli->error . '

sql语句:
' . $value . '

'); - } - } - } - - $mysqli->commit(); - $mysqli->autocommit(true); - $mysqli->close(); - } - $code = 1; - $msg = '更新成功,返回首页'; - // 删除sql文件 - @unlink($path); - if (file_exists(Env::get('root_path') . 'install.sql')) { - @unlink(Env::get('root_path') . 'install.sql'); - } - } - } catch (Exception $e) { - $mysqli->rollback(); - $mysqli->close(); - $code = 0; - $msg = $e->getMessage(); - } - $this->assign([ - 'code' => $code, - 'msg' => $msg - ]); - return $this->fetch(); - } } diff --git a/application/index/controller/admin/System.php b/application/index/controller/admin/System.php index a8d6adc5..368566d8 100644 --- a/application/index/controller/admin/System.php +++ b/application/index/controller/admin/System.php @@ -8,6 +8,7 @@ namespace app\index\controller\admin; +use app\common\model\Config; use think\Db; use app\common\model\Images; use think\Exception;