currentStep(); $maxStep = $install->maxStep(); //step 1 if ($currentStep == 1) { $requirements = $install->listRequirementTableRows(); $pass = $requirements['pass']; if ($isPost) { $install->nextStep(); } } if ($currentStep == 2) { $envExampleFile = "$rootpath.env.example"; $envExampleData = readEnvFile($envExampleFile); $envFormControls = $install->listEnvFormControls(); $newData = array_column($envFormControls, 'value', 'name'); while ($isPost) { // $envFile = "$rootpath.env." . time(); // $newData = $formData = []; // if (file_exists($envFile) && is_readable($envFile)) { // //already exists, read it ,and merge post data // $newData = readEnvFile($envFile); // } // foreach ($envExampleData as $key => $value) { // $postValue = trim($_POST[$key] ?? ''); // if ($postValue) { // $value = $postValue; // } // $newData[$key] = $value; // $envExampleData[] = [ // 'label' => $key, // 'name' => $key, // 'value' => $value, // ]; // } // unset($key); //check try { $connectMysql = mysql_connect($newData['MYSQL_HOST'], $newData['MYSQL_USERNAME'], $newData['MYSQL_PASSWORD'], $newData['MYSQL_DATABASE'], $newData['MYSQL_PORT']); } catch (\Exception $e) { $_SESSION['error'] = "Mysql: " . $e->getMessage(); break; } if (extension_loaded('redis') && !empty($newData['REDIS_HOST'])) { try { $redis = new Redis(); $redis->connect($newData['REDIS_HOST'], $newData['REDIS_PORT'] ?: 6379); } catch (\Exception $e) { $_SESSION['error'] = "Redis: " . $e->getMessage(); break; } if (!ctype_digit($newData['REDIS_DATABASE']) || $newData['REDIS_DATABASE'] < 0 || $newData['REDIS_DATABASE'] > 15) { $_SESSION['error'] = "invalid REDIS_DATABASE"; break; } } // $content = ""; // foreach ($newData as $key => $value) { // $content .= "{$key}={$value}\n"; // } // $fp = @fopen($envFile, 'w'); // if ($fp === false) { // $msg = "文件无法打开, 确保 PHP 有权限在根目录创建文件"; // $msg .= "\n也可以复制以下内容保存到 $envFile 中"; // $_SESSION['error'] = $msg; // $_SESSION['copy'] = $content; // } // fwrite($fp, $content); // fclose($fp); $install->nextStep(); break; } $tableRows = [ [ 'label' => '.env.example', 'required' => 'exists && readable', 'current' => $envExampleFile, 'result' => $install->yesOrNo(file_exists($envExampleFile) && is_readable($envExampleFile)), ], ]; $fails = array_filter($tableRows, function ($value) {return $value['result'] == 'NO';}); $pass = empty($fails); } if ($currentStep == 3) { $pass = true; $existsTable = $install->listExistsTable(); $tableCreate = $install->listAllTableCreate(); $shouldCreateTable = []; foreach ($tableCreate as $table => $sql) { if (in_array($table, $existsTable)) { continue; } $shouldCreateTable[$table] = $sql; } while (true) { // $sqlFile = $rootpath . '_db/dbstructure_v1.6.sql'; // try { // $tableCreate = listAllTableCreate($sqlFile); // } catch (\Exception $e) { // $_SESSION['error'] = $e->getMessage(); // break; // } // if (empty($tableCreate)) { // $_SESSION['error'] = "no table create, make sure sql file is correct"; // break; // } if ($isPost) { try { foreach ($shouldCreateTable as $table => $sql) { sql_query($sql); } } catch (\Exception $e) { $_SESSION['error'] = $e->getMessage(); break; } $install->nextStep(); } break; } } //if ($currentStep == 4) { // $pass = true; // while (true) { // $shouldAlterTable = listShouldAlterTable(); // if ($isPost) { // if (!empty($shouldAlterTable)) { // try { // sql_query('SET sql_mode=(SELECT REPLACE(@@sql_mode,"NO_ZERO_DATE", ""));'); // foreach ($shouldAlterTable as $table => $fields) { // $sqlAlter = "alter table $table"; // $sqlUpdate = "update $table"; // $updateWhere = []; // foreach ($fields as $field) { // $sqlAlter .= " modify $field datetime default null,"; // $sqlUpdate .= " set $field = null,"; // $updateWhere[] = "$field = '0000-00-00 00:00:00'"; // } // $sqlAlter = rtrim($sqlAlter, ','); // $sqlUpdate = rtrim($sqlUpdate, ',') . " where " . implode(' or ', $updateWhere); // sql_query($sqlUpdate); // sql_query($sqlAlter); // } // } catch (\Exception $e) { // $_SESSION['error'] = $e->getMessage(); // break; // } // } // goStep($currentStep + 1); // } // break; // } //} if ($currentStep == 4) { $settingTableRows = $install->listSettingTableRows(); $settings = $settingTableRows['settings']; $symbolicLinks = $settingTableRows['symbolic_links']; $tableRows = $settingTableRows['table_rows']; $pass = $settingTableRows['pass']; while (true) { try { foreach ($settings as $prefix => &$group) { if ($isPost) { $install->doLog("[SAVE] prefix: $prefix, nameAndValues: " . json_encode($group)); foreach ($symbolicLinks as $path) { $linkName = ROOT_PATH . 'public/' . basename($path); if (is_dir($linkName)) { $install->doLog("path: $linkName already exits, skip create symbolic link $linkName -> $path"); continue; } //@todo // $linkResult = symlink($path, $linkName); // if ($linkResult === false) { // throw new \Exception("can't not make symbolic link: $linkName -> $path"); // } } //@todo // saveSetting($prefix, $group); } } } catch (\Exception $e) { $_SESSION['error'] = $e->getMessage(); break; } $isPost && $install->nextStep(); break; } } if ($currentStep == 5) { if ($isPost) { try { $install->createAdministrator($_POST['username'], $_POST['email'], $_POST['password'], $_POST['confirm_password']); $install->nextStep(); } catch (\Exception $exception) { $_SESSION['error'] = $exception->getMessage(); } } $pass = true; $userFormControls = [ ['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'] ?? ''], ]; } ?> Update NexusPHP | step <?php echo $currentStep?>
renderSteps()?>
'; $header = ['项目', '要求', '当前', '结果']; if ($currentStep == 1) { echo $install->renderTable($header, $requirements['table_rows']); } elseif ($currentStep == 2) { echo $install->renderTable($header, $tableRows); echo '
若 Redis 不启用,相关项目留空
'; echo $install->renderForm($envFormControls); } elseif ($currentStep == 3) { echo '

需要新建以下数据表

'; if (empty($shouldCreateTable)) { echo '
恭喜,需要的表均已创建!
'; } else { echo sprintf('
%s
', implode(', ', array_keys($shouldCreateTable))); } } elseif ($currentStep == 4) { echo $install->renderTable($header, $tableRows); echo '
'; echo sprintf('这一步会把 %s 的数据合并到 %s, 然后插入数据库中。', $tableRows[1]['label'], $tableRows[0]['label']); echo '
'; } elseif ($currentStep == 5) { echo $install->renderForm($userFormControls, '1/3', '1/4', '3/4'); } elseif ($currentStep > $maxStep) { echo '
恭喜,一切就绪!
'; echo '
有问题可查阅安装日志:' . $install->getLogFile() . '
'; echo '
为安全起见,请删除以下目录
'; echo '
' . $install->getInsallDirectory() . '
'; } echo'
'; if (!empty($_SESSION['error'])) { echo sprintf('
Error: %s
', nl2br($_SESSION['error'])); unset($_SESSION['error']); } if (!empty($_SESSION['copy'])) { echo sprintf('
', $_SESSION['copy']); unset($_SESSION['copy']); } ?>
回首页