mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-23 19:37:23 +08:00
prepare for v1.6.0-beta
This commit is contained in:
@@ -8,8 +8,6 @@ class DB
|
||||
|
||||
private static $instance;
|
||||
|
||||
private static $queries = [];
|
||||
|
||||
private $isConnected = false;
|
||||
|
||||
private function __construct()
|
||||
@@ -55,8 +53,6 @@ class DB
|
||||
$this->driver->query("SET collation_connection = 'utf8_general_ci'");
|
||||
$this->driver->query("SET sql_mode=''");
|
||||
$this->isConnected = true;
|
||||
$log = json_encode(func_get_args());
|
||||
do_log($log);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -66,7 +62,6 @@ class DB
|
||||
return null;
|
||||
}
|
||||
$config = config('database.mysql');
|
||||
do_log(json_encode($config));
|
||||
return $this->connect($config['host'], $config['username'], $config['password'], $config['database'], $config['port']);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ class Install
|
||||
|
||||
private $minimumPhpVersion = '7.2.0';
|
||||
|
||||
private $progressKeyPrefix = '__step';
|
||||
|
||||
protected $steps = ['环境检测', '添加 .env 文件', '创建数据表', '导入数据', '创建管理员账号'];
|
||||
|
||||
protected $initializeTables = [
|
||||
@@ -18,9 +20,15 @@ class Install
|
||||
'searchbox', 'secondicons', 'sources', 'standards', 'stylesheets', 'sysoppanel', 'teams', 'torrents_state', 'uploadspeed', 'agent_allowed_family',
|
||||
];
|
||||
|
||||
protected $envNames = ['MYSQL_HOST', 'MYSQL_PORT', 'MYSQL_USERNAME', 'MYSQL_PASSWORD', 'MYSQL_DATABASE', 'REDIS_HOST', 'REDIS_PORT', 'REDIS_DATABASE'];
|
||||
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
if (!session_id()) {
|
||||
session_start();
|
||||
}
|
||||
$this->currentStep = min(intval($_REQUEST['step'] ?? 1) ?: 1, count($this->steps) + 1);
|
||||
}
|
||||
|
||||
@@ -29,6 +37,31 @@ class Install
|
||||
return $this->currentStep;
|
||||
}
|
||||
|
||||
public function canAccessStep($step)
|
||||
{
|
||||
for ($i = 1; $i < $step; $i++) {
|
||||
$progressKey = $this->getProgressKey($i);
|
||||
if (!isset($_SESSION[$progressKey])) {
|
||||
do_log("check step: $i, session doesn't have, session: " . json_encode($_SESSION));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
do_log("check step: $step, can access, session: " . json_encode($_SESSION));
|
||||
return true;
|
||||
}
|
||||
|
||||
public function doneStep($step)
|
||||
{
|
||||
$progressKey = $this->getProgressKey($step);
|
||||
do_log("doneStep: $step, $progressKey = 1");
|
||||
$_SESSION[$progressKey] = 1;
|
||||
}
|
||||
|
||||
private function getProgressKey($step)
|
||||
{
|
||||
return $this->progressKeyPrefix . $step;
|
||||
}
|
||||
|
||||
public function getLogFile()
|
||||
{
|
||||
return sprintf('%s/nexus_install_%s.log', sys_get_temp_dir(), date('Ymd'));
|
||||
@@ -221,6 +254,7 @@ class Install
|
||||
|
||||
public function nextStep()
|
||||
{
|
||||
$this->doneStep($this->currentStep);
|
||||
$this->gotoStep($this->currentStep + 1);
|
||||
}
|
||||
|
||||
@@ -308,13 +342,14 @@ class Install
|
||||
}
|
||||
$mergeData = array_merge($envExampleData, $envData);
|
||||
$formControls = [];
|
||||
foreach ($mergeData as $key => $value) {
|
||||
if (isset($_POST[$key])) {
|
||||
$value = $_POST[$key];
|
||||
foreach ($this->envNames as $name) {
|
||||
$value = $mergeData[$name];
|
||||
if (isset($_POST[$name])) {
|
||||
$value = $_POST[$name];
|
||||
}
|
||||
$formControls[] = [
|
||||
'label' => $key,
|
||||
'name' => $key,
|
||||
'label' => $name,
|
||||
'name' => $name,
|
||||
'value' => $value,
|
||||
];
|
||||
}
|
||||
@@ -324,6 +359,10 @@ class Install
|
||||
|
||||
public function createAdministrator($username, $email, $password, $confirmPassword)
|
||||
{
|
||||
$count = get_row_count('users', 'where class = 16');
|
||||
if ($count > 0) {
|
||||
throw new \InvalidArgumentException("Administrator already exists");
|
||||
}
|
||||
if (!validusername($username)) {
|
||||
throw new \InvalidArgumentException("Innvalid username: $username");
|
||||
}
|
||||
@@ -398,7 +437,7 @@ class Install
|
||||
}
|
||||
fwrite($fp, $content);
|
||||
fclose($fp);
|
||||
$this->doLog("[CREATE ENV] $envFile with content: \n $content");
|
||||
$this->doLog("[CREATE ENV] $envFile with content: $content");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -464,6 +503,12 @@ class Install
|
||||
if (!in_array($table, $this->initializeTables)) {
|
||||
continue;
|
||||
}
|
||||
//if table not empty, skip
|
||||
$count = get_row_count($table);
|
||||
if ($count > 0) {
|
||||
$this->doLog("[IMPORT DATA] $table, not empty, skip");
|
||||
continue;
|
||||
}
|
||||
$this->doLog("[IMPORT DATA] $table, $sql");
|
||||
sql_query("truncate table $table");
|
||||
sql_query($sql);
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
<?php
|
||||
ini_set('error_reporting', E_ALL);
|
||||
ini_set('display_errors', 0);
|
||||
if (!session_id()) {
|
||||
session_start();
|
||||
}
|
||||
$rootpath = dirname(dirname(__DIR__)) . '/';
|
||||
define('ROOT_PATH', $rootpath);
|
||||
$isPost = $_SERVER['REQUEST_METHOD'] == 'POST';
|
||||
@@ -15,6 +12,10 @@ require $rootpath . 'nexus/Database/helpers.php';
|
||||
$install = new \Nexus\Install\Install();
|
||||
$currentStep = $install->currentStep();
|
||||
$maxStep = $install->maxStep();
|
||||
if (!$install->canAccessStep($currentStep)) {
|
||||
$install->gotoStep(1);
|
||||
}
|
||||
$error = $copy = '';
|
||||
|
||||
//step 1
|
||||
if ($currentStep == 1) {
|
||||
@@ -35,7 +36,7 @@ if ($currentStep == 2) {
|
||||
$install->createEnvFile($_POST);
|
||||
$install->nextStep();
|
||||
} catch (\Exception $exception) {
|
||||
$_SESSION['error'] = $exception->getMessage();
|
||||
$error = $exception->getMessage();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@@ -60,7 +61,7 @@ if ($currentStep == 3) {
|
||||
$install->createTable($shouldCreateTable);
|
||||
$install->nextStep();
|
||||
} catch (\Exception $exception) {
|
||||
$_SESSION['error'] = $exception->getMessage();
|
||||
$error = $exception->getMessage();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@@ -90,7 +91,7 @@ if ($currentStep == 3) {
|
||||
// sql_query($sqlAlter);
|
||||
// }
|
||||
// } catch (\Exception $e) {
|
||||
// $_SESSION['error'] = $e->getMessage();
|
||||
// $error = $e->getMessage();
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
@@ -113,7 +114,7 @@ if ($currentStep == 4) {
|
||||
$install->importInitialData();
|
||||
$install->nextStep();
|
||||
} catch (\Exception $e) {
|
||||
$_SESSION['error'] = $e->getMessage();
|
||||
$error = $e->getMessage();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
@@ -126,7 +127,7 @@ if ($currentStep == 5) {
|
||||
$install->createAdministrator($_POST['username'], $_POST['email'], $_POST['password'], $_POST['confirm_password']);
|
||||
$install->nextStep();
|
||||
} catch (\Exception $exception) {
|
||||
$_SESSION['error'] = $exception->getMessage();
|
||||
$error = $exception->getMessage();
|
||||
}
|
||||
}
|
||||
$pass = true;
|
||||
@@ -134,7 +135,7 @@ if ($currentStep == 5) {
|
||||
['label' => '用户名', 'name' => 'username', 'value' => $_POST['username'] ?? ''],
|
||||
['label' => '邮箱', 'name' => 'email', 'value' => $_POST['email'] ?? ''],
|
||||
['label' => '密码', 'name' => 'password', 'value' => $_POST['password'] ?? ''],
|
||||
['label' => '重复密码', 'name' => 'confirm_password', 'value' => $_POST['confirm_password'] ?? ''],
|
||||
['label' => '确认密码', 'name' => 'confirm_password', 'value' => $_POST['confirm_password'] ?? ''],
|
||||
];
|
||||
}
|
||||
?>
|
||||
@@ -186,13 +187,13 @@ if ($currentStep == 5) {
|
||||
}
|
||||
echo'</div>';
|
||||
|
||||
if (!empty($_SESSION['error'])) {
|
||||
echo sprintf('<div class="text-center text-red-500 p-4">Error: %s</div>', nl2br($_SESSION['error']));
|
||||
unset($_SESSION['error']);
|
||||
if (!empty($error)) {
|
||||
echo sprintf('<div class="text-center text-red-500 p-4">Error: %s</div>', nl2br($error));
|
||||
unset($error);
|
||||
}
|
||||
if (!empty($_SESSION['copy'])) {
|
||||
echo sprintf('<div class="text-center"><textarea class="w-1/2 h-40 border">%s</textarea></div>', $_SESSION['copy']);
|
||||
unset($_SESSION['copy']);
|
||||
if (!empty($copy)) {
|
||||
echo sprintf('<div class="text-center"><textarea class="w-1/2 h-40 border">%s</textarea></div>', $copy);
|
||||
unset($copy);
|
||||
}
|
||||
?>
|
||||
<div class="mt-10 text-center">
|
||||
@@ -207,7 +208,7 @@ if ($currentStep == 5) {
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-10 text-center">
|
||||
欢迎使用 NexusPHP 安装程序,如有疑问,点击<a href="http://nexusphp.org/" target="_blank" class="text-blue-500 p-1">这里</a>获取参考。
|
||||
欢迎使用 NexusPHP 安装程序,如有疑问,点击<a href="http://nexusphp.org/" target="_blank" class="text-blue-500 p-1">这里</a>获取帮助。
|
||||
</div>
|
||||
</body>
|
||||
<script>
|
||||
|
||||
Reference in New Issue
Block a user