Index.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // |
  4. // +----------------------------------------------------------------------
  5. // |
  6. // +----------------------------------------------------------------------
  7. // |
  8. // +----------------------------------------------------------------------
  9. // |
  10. // +----------------------------------------------------------------------
  11. // +----------------------------------------------------------------------
  12. // | 安装控制模块
  13. // +----------------------------------------------------------------------
  14. namespace app\install\controller;
  15. use app\admin\library\Install;
  16. use app\common\controller\BaseController;
  17. class Index extends BaseController
  18. {
  19. public function index()
  20. {
  21. define('INSTALL_PATH', app()->getBasePath() . 'admin' . DS . 'command' . DS . 'Install' . DS);
  22. $installLockFile = INSTALL_PATH . "install.lock";
  23. if (is_file($installLockFile)) {
  24. echo '当前已经安装成功,如果需要重新安装,请手动移除install.lock文件';
  25. exit;
  26. }
  27. if ($this->request->isPost()) {
  28. $mysqlHostname = $this->request->post('mysqlHostname', '127.0.0.1');
  29. $mysqlHostport = $this->request->post('mysqlHostport', '3306');
  30. $hostArr = explode(':', $mysqlHostname);
  31. if (count($hostArr) > 1) {
  32. $mysqlHostname = $hostArr[0];
  33. $mysqlHostport = $hostArr[1];
  34. }
  35. $mysqlUsername = $this->request->post('mysqlUsername', 'root');
  36. $mysqlPassword = $this->request->post('mysqlPassword', '');
  37. $mysqlDatabase = $this->request->post('mysqlDatabase', '');
  38. $mysqlPrefix = $this->request->post('mysqlPrefix', 'yzn_');
  39. $adminUsername = $this->request->post('adminUsername', 'admin');
  40. $adminPassword = $this->request->post('adminPassword', '');
  41. $adminPasswordConfirmation = $this->request->post('adminPasswordConfirmation', '');
  42. $adminEmail = $this->request->post('adminEmail', 'admin@admin.com');
  43. if ($adminPassword !== $adminPasswordConfirmation) {
  44. $this->error('两次输入的密码不一致');
  45. }
  46. try {
  47. $adminName = Install::installation($mysqlHostname, $mysqlHostport, $mysqlDatabase, $mysqlUsername, $mysqlPassword, $mysqlPrefix, $adminUsername, $adminPassword, $adminEmail);
  48. } catch (\PDOException $e) {
  49. throw new Exception($e->getMessage());
  50. } catch (\Exception $e) {
  51. $this->error($e->getMessage());
  52. }
  53. $this->success('安装成功!', null, ['adminName' => $adminName]);
  54. }
  55. $errInfo = '';
  56. try {
  57. Install::checkenv();
  58. } catch (\Exception $e) {
  59. $errInfo = $e->getMessage();
  60. }
  61. return $this->fetch("/install", ['errInfo' => $errInfo]);
  62. }
  63. }