Jelajahi Sumber

优化安装脚本

萤火科技 1 tahun lalu
induk
melakukan
0bed29154c

+ 24 - 7
public/install/index.php

@@ -155,7 +155,6 @@ if ($s === 'importDb') {
     $dbuser = $_POST['dbuser'] ?? '';
     $dbuser = $_POST['dbuser'] ?? '';
     $dbpwd = $_POST['dbpwd'] ?? '';
     $dbpwd = $_POST['dbpwd'] ?? '';
     $dbport = $_POST['dbport'] ?? 3306;
     $dbport = $_POST['dbport'] ?? 3306;
-
     $testdata = $_POST['testdata'] ?? '';
     $testdata = $_POST['testdata'] ?? '';
 
 
     // 执行的索引 (某条数据)
     // 执行的索引 (某条数据)
@@ -167,14 +166,14 @@ if ($s === 'importDb') {
         $pdo = new PDO($dsn, $dbuser, $dbpwd);
         $pdo = new PDO($dsn, $dbuser, $dbpwd);
         $pdo->query("SET NAMES utf8"); // 设置数据库编码
         $pdo->query("SET NAMES utf8"); // 设置数据库编码
     } catch (Exception $e) {
     } catch (Exception $e) {
-        insError('数据库连接错误,请检查!');
+        insError2('数据库连接错误,请检查!');
     }
     }
 
 
     // 验证数据库版本号
     // 验证数据库版本号
     // $version = $pdo->query('select version()')->fetchColumn();
     // $version = $pdo->query('select version()')->fetchColumn();
     $version = $pdo->getAttribute(PDO::ATTR_SERVER_VERSION);
     $version = $pdo->getAttribute(PDO::ATTR_SERVER_VERSION);
     if (version_compare($version, '5.7.0') == -1) {
     if (version_compare($version, '5.7.0') == -1) {
-        insError("很抱歉,数据库版本号不能低于5.7.0,请检查!您当前是 {$version}");
+        insError2("很抱歉,数据库版本号不能低于5.7.0,请检查!您当前是 {$version}");
     }
     }
 
 
     // 数据库创建完成,开始连接
     // 数据库创建完成,开始连接
@@ -184,13 +183,13 @@ if ($s === 'importDb') {
     $content = readDataFile('install.sql');
     $content = readDataFile('install.sql');
     $data = preg_split('/DROP TABLE IF EXISTS `.*?`;/', $content);
     $data = preg_split('/DROP TABLE IF EXISTS `.*?`;/', $content);
     if (!isset($data[$index])) {
     if (!isset($data[$index])) {
-        insError('数据库索引不正确');
+        insError2('数据库索引不正确');
     }
     }
 
 
     // 获取表名
     // 获取表名
     $tableName = parseTableName($data[$index]);
     $tableName = parseTableName($data[$index]);
     if (empty($tableName)) {
     if (empty($tableName)) {
-        insError('数据库执行脚本不正确');
+        insError2('数据库执行脚本不正确');
     }
     }
 
 
     // 生成sql语句
     // 生成sql语句
@@ -217,6 +216,7 @@ if ($s === 'importDb') {
     // 返回结果
     // 返回结果
     exit(jsonEncode(compact('index', 'message', 'status', 'isNext')));
     exit(jsonEncode(compact('index', 'message', 'status', 'isNext')));
 }
 }
+
 // 安装完成
 // 安装完成
 if ($s === md5('done')) {
 if ($s === md5('done')) {
     require_once(INSTALL_PATH . '/templates/step_4.php');
     require_once(INSTALL_PATH . '/templates/step_4.php');
@@ -290,6 +290,17 @@ function getPHPVersion()
     }
     }
 }
 }
 
 
+// 检测php位数
+function getPHPArchitecture()
+{
+    if (PHP_INT_SIZE < 8) {
+        echo "<span class=\"col-red\"><strong>32位</strong> (请使用64位的php)</span>";
+        setIsNext(false);
+    } else {
+        echo "<span>64位</span>";
+    }
+}
+
 // 匹配mysql表名
 // 匹配mysql表名
 function parseTableName(string $sql): ?string
 function parseTableName(string $sql): ?string
 {
 {
@@ -398,10 +409,16 @@ function insInfo($str)
     echo '<script>$("#install").append("' . $str . '<br>");</script>';
     echo '<script>$("#install").append("' . $str . '<br>");</script>';
 }
 }
 
 
-function insError($str, $isExit = false)
+function insError($str, $isExit = true)
 {
 {
     insInfo("<span class='col-red'>$str</span>");
     insInfo("<span class='col-red'>$str</span>");
-    exit();
+    $isExit && exit();
+}
+
+function insError2($message, $isExit = true)
+{
+    echo jsonEncode(['status' => false, 'message' => $message]);
+    $isExit && exit();
 }
 }
 
 
 /**
 /**

+ 8 - 1
public/install/templates/step_1.php

@@ -35,6 +35,12 @@
                 <td>7.4</td>
                 <td>7.4</td>
                 <td class="endCol"><?php echo getPHPVersion(); ?></td>
                 <td class="endCol"><?php echo getPHPVersion(); ?></td>
             </tr>
             </tr>
+            <tr>
+                <td height="26" class="firstCol">PHP 位数</td>
+                <td>64位</td>
+                <td>64位</td>
+                <td class="endCol"><?php echo getPHPArchitecture(); ?></td>
+            </tr>
             <tr>
             <tr>
                 <td height="26" class="firstCol">附件上传</td>
                 <td height="26" class="firstCol">附件上传</td>
                 <td>2M</td>
                 <td>2M</td>
@@ -80,7 +86,8 @@
                     <td height="26" class="firstCol"><?= $item['name'] ?></td>
                     <td height="26" class="firstCol"><?= $item['name'] ?></td>
                     <td><?= $item['status'] ? '支持' : '不支持' ?></td>
                     <td><?= $item['status'] ? '支持' : '不支持' ?></td>
                     <td class="endCol">
                     <td class="endCol">
-                        <span class="<?= $item['status'] ? '' : 'col-red' ?>"><?= $item['status'] ? '无' : '需安装' ?></span>
+                        <span
+                            class="<?= $item['status'] ? '' : 'col-red' ?>"><?= $item['status'] ? '无' : '需安装' ?></span>
                     </td>
                     </td>
                 </tr>
                 </tr>
             <?php endforeach ?>
             <?php endforeach ?>

+ 5 - 1
public/install/templates/step_3.php

@@ -14,7 +14,7 @@
     <div class="text">
     <div class="text">
         <h4>正在安装...</h4>
         <h4>正在安装...</h4>
         <div id="install">
         <div id="install">
-            <p>数据库连接文件创建完成!</p>
+            <p>数据库配置文件创建完成!</p>
         </div>
         </div>
     </div>
     </div>
 </div>
 </div>
@@ -30,12 +30,16 @@
                 dbname: '<?= $_POST['dbname'] ?? '' ?>',
                 dbname: '<?= $_POST['dbname'] ?? '' ?>',
                 dbuser: '<?= $_POST['dbuser'] ?? '' ?>',
                 dbuser: '<?= $_POST['dbuser'] ?? '' ?>',
                 dbpwd: '<?= $_POST['dbpwd'] ?? '' ?>',
                 dbpwd: '<?= $_POST['dbpwd'] ?? '' ?>',
+                dbport: '<?= $_POST['dbport'] ?? 3306 ?>',
                 index: index,
                 index: index,
             },
             },
             type: 'POST',
             type: 'POST',
             dataType: 'json',
             dataType: 'json',
             success: function (data) {
             success: function (data) {
                 appendMsg(data.message, data.status ? 10 : 30)
                 appendMsg(data.message, data.status ? 10 : 30)
+                if (!data.status) {
+                    return
+                }
                 if (data.isNext) {
                 if (data.isNext) {
                     setTimeout(() => importDb(index + 1), 50)
                     setTimeout(() => importDb(index + 1), 50)
                 } else {
                 } else {