install.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. // error_reporting(0);
  3. include "model.php";
  4. include "YxEnv.php";
  5. define('install', true);
  6. define('INSTALL_ROOT', __DIR__);
  7. define('TESTING_TABLE', 'config');
  8. $step = $_GET['step'] ?? 1;
  9. $installDir = "install";
  10. $modelInstall = new installModel();
  11. // Env设置
  12. $yxEnv = new YxEnv();
  13. // 检查是否有安装过
  14. $envFilePath = $modelInstall->getAppRoot() . '/.env';
  15. if ($modelInstall->appIsInstalled() && in_array($step, [1, 2, 3, 4])) {
  16. die('可能已经安装过本系统了,请删除配置目录下面的install.lock文件再尝试');
  17. }
  18. // 加载Example文件
  19. $yxEnv->load($modelInstall->getAppRoot() . '/.example.env');
  20. //尝试生成.env
  21. $yxEnv->makeEnv($modelInstall->getAppRoot() . '/.env');
  22. $post = [
  23. 'host' => $_POST['host'] ?? '127.0.0.1',
  24. 'port' => $_POST['port'] ?? '3306',
  25. 'user' => $_POST['user'] ?? 'root',
  26. 'password' => $_POST['password'] ?? '',
  27. 'name' => $_POST['name'] ?? 'likeadmin',
  28. 'admin_user' => $_POST['admin_user'] ?? '',
  29. 'admin_password' => $_POST['admin_password'] ?? '',
  30. 'admin_confirm_password' => $_POST['admin_confirm_password'] ?? '',
  31. 'prefix' => $_POST['prefix'] ?? 'la_',
  32. 'import_test_data' => $_POST['import_test_data'] ?? 'off',
  33. 'clear_db' => $_POST['clear_db'] ?? 'off',
  34. ];
  35. $message = '';
  36. // 检查数据库正确性
  37. if ($step == 4) {
  38. $canNext = true;
  39. if (empty($post['prefix'])) {
  40. $canNext = false;
  41. $message = '数据表前缀不能为空';
  42. } elseif ($post['admin_user'] == '') {
  43. $canNext = false;
  44. $message = '请填写管理员用户名';
  45. } elseif (empty(trim($post['admin_password']))) {
  46. $canNext = false;
  47. $message = '管理员密码不能为空';
  48. } elseif ($post['admin_password'] != $post['admin_confirm_password']) {
  49. $canNext = false;
  50. $message = '两次密码不一致';
  51. } else {
  52. // 检查 数据库信息
  53. $result = $modelInstall->checkConfig($post['name'], $post);
  54. if ($result->result == 'fail') {
  55. $canNext = false;
  56. $message = $result->error;
  57. }
  58. // 导入测试数据
  59. if ($canNext == true && $post['import_test_data'] == 'on') {
  60. if (!$modelInstall->importDemoData()) {
  61. $canNext = false;
  62. $message = '导入测试数据错误';
  63. }
  64. }
  65. // 写配置文件
  66. if ($canNext) {
  67. $yxEnv->putEnv($envFilePath, $post);
  68. $modelInstall->mkLockFile();
  69. }
  70. // 恢复admin和index入口
  71. if ($canNext) {
  72. $modelInstall->restoreIndexLock();
  73. }
  74. }
  75. if (!$canNext)
  76. $step = 3;
  77. }
  78. // 取得安装成功的表
  79. $successTables = $modelInstall->getSuccessTable();
  80. $nextStep = $step + 1;
  81. include __DIR__ . "/template/main.php";