提交 add781ff 编写于 作者: D devil_gong

安装程序

上级 68a2360e
...@@ -26,6 +26,23 @@ class Index extends Common ...@@ -26,6 +26,23 @@ class Index extends Common
parent::__construct(); parent::__construct();
} }
/**
* 是否已安装
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-12-28
* @desc description
*/
private function IsInstall()
{
// 是否已安装
if(file_exists(ROOT.'public/install/install.lock'))
{
exit('你已经安装过该系统,重新安装需要先删除 ./public/install/install.lock 文件');
}
}
/** /**
* 协议 * 协议
* @author Devil * @author Devil
...@@ -36,6 +53,7 @@ class Index extends Common ...@@ -36,6 +53,7 @@ class Index extends Common
*/ */
public function Index() public function Index()
{ {
$this->IsInstall();
return $this->fetch(); return $this->fetch();
} }
...@@ -49,6 +67,7 @@ class Index extends Common ...@@ -49,6 +67,7 @@ class Index extends Common
*/ */
public function Check() public function Check()
{ {
$this->IsInstall();
return $this->fetch(); return $this->fetch();
} }
...@@ -62,6 +81,7 @@ class Index extends Common ...@@ -62,6 +81,7 @@ class Index extends Common
*/ */
public function Create() public function Create()
{ {
$this->IsInstall();
return $this->fetch(); return $this->fetch();
} }
...@@ -137,7 +157,7 @@ class Index extends Common ...@@ -137,7 +157,7 @@ class Index extends Common
} }
// 创建数据表 // 创建数据表
$ret = $this->CreateTable($db); $ret = $this->CreateTable($db, $params);
if($ret['code'] != 0) if($ret['code'] != 0)
{ {
return $ret; return $ret;
...@@ -229,7 +249,7 @@ php; ...@@ -229,7 +249,7 @@ php;
{ {
return DataReturn('配置文件创建失败', -1); return DataReturn('配置文件创建失败', -1);
} }
return DataReturn('success', 0); return DataReturn('安装成功', 0);
} }
/** /**
...@@ -239,28 +259,41 @@ php; ...@@ -239,28 +259,41 @@ php;
* @date 2018-12-28 * @date 2018-12-28
* @desc description * @desc description
* @param [object] $db [db对象] * @param [object] $db [db对象]
* @param [array] $params [输入参数]
*/ */
private function CreateTable($db) private function CreateTable($db, $params)
{ {
if(!file_exists(ROOT.'public/install/shopxo.sql')) if(!file_exists(ROOT.'public/install/shopxo.sql'))
{ {
return DataReturn('数据库sql文件不存在', -1); return DataReturn('数据库sql文件不存在', -1);
} }
// 导入sql数据并创建表 // sql文件
$sql_array = preg_split("/;[\r\n]+/", str_replace('`s_', '`'.$params['DB_PREFIX'], file_get_contents(ROOT.'public/install/shopxo.sql'))); $sql = file_get_contents(ROOT.'public/install/shopxo.sql');
//替换表前缀
$sql = str_replace("`s_", " `{$params['DB_PREFIX']}", $sql);
// 转为数组
$sql_all = preg_split("/;[\r\n]+/", $sql);
$success = 0; $success = 0;
$failure = 0; $failure = 0;
foreach($sql_array as $v) foreach($sql_all as $v)
{ {
if (!empty($v)) if (!empty($v))
{ {
if($db->query($v)) if (substr($v, 0, 12) == 'CREATE TABLE')
{ {
$success++; if($db->execute($v) !== false)
{
$success++;
} else {
$failure++;
}
} else { } else {
$failure++; $db->execute($v);
} }
} }
} }
...@@ -274,7 +307,7 @@ php; ...@@ -274,7 +307,7 @@ php;
} }
// 创建成功标记文件 // 创建成功标记文件
@file_put_contents(ROOT.'public/install/install.lock'); @touch(ROOT.'public/install/install.lock');
return DataReturn('success', 0, $result); return DataReturn('success', 0, $result);
} }
...@@ -366,9 +399,12 @@ php; ...@@ -366,9 +399,12 @@ php;
// 数据库连接端口 // 数据库连接端口
'hostport' => $params['DB_PORT'], 'hostport' => $params['DB_PORT'],
// 数据库连接参数 // 数据库连接参数
'params' => [], 'params' => [
\PDO::ATTR_CASE => \PDO::CASE_LOWER,
\PDO::ATTR_EMULATE_PREPARES => true,
],
// 数据库编码默认采用utf8 // 数据库编码默认采用utf8
'charset' => 'utf8', 'charset' => 'utf8mb4',
// 数据库表前缀 // 数据库表前缀
'prefix' => $params['DB_PREFIX'], 'prefix' => $params['DB_PREFIX'],
]); ]);
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<!-- conntent start --> <!-- conntent start -->
<div class="am-g inside create"> <div class="am-g inside create">
<h2>数据库信息</h2> <h2>数据库信息</h2>
<form class="am-form am-form-horizontal form-validation" method="post" action="{{:MyUrl('install/index/add')}}" request-type="ajax-url" request-value="{{:MyUrl('install/index/success')}}"> <form class="am-form am-form-horizontal form-validation" method="post" action="{{:MyUrl('install/index/add')}}" request-type="ajax-url" request-value="{{:MyUrl('install/index/successful')}}" timeout="60000">
<div class="am-form-group"> <div class="am-form-group">
<label class="am-u-sm-2 am-form-label">数据库类型</label> <label class="am-u-sm-2 am-form-label">数据库类型</label>
<div class="am-u-sm-10"> <div class="am-u-sm-10">
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
<!-- conntent start --> <!-- conntent start -->
<div class="am-g inside success"> <div class="am-g inside success">
<a href="javascript:;" class="am-icon-btn am-success am-icon-sm am-icon-check"></a> <i class="am-icon-btn am-success am-icon-sm am-icon-check"></i>
<h2>恭喜您安装成功</h2> <h2>恭喜您安装成功</h2>
<div class="box"> <div class="box">
<a href="{{$Think.__MY_URL__}}index.php?s=/admin/index/index" target="_blank">后台管理</a><br /> <a href="{{$Think.__MY_URL__}}index.php?s=/admin/index/index" target="_blank">后台管理</a><br />
......
...@@ -379,7 +379,7 @@ function FromInit(form_name) ...@@ -379,7 +379,7 @@ function FromInit(form_name)
url:action, url:action,
type:method, type:method,
dataType:"json", dataType:"json",
timeout:10000, timeout:$form.attr('timeout') || 10000,
data:GetFormVal(form_name), data:GetFormVal(form_name),
processData:false, processData:false,
contentType:false, contentType:false,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册