Install.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace app\admin\command;
  3. use think\console\Command;
  4. use think\console\Input;
  5. use think\console\input\Option;
  6. use think\console\Output;
  7. use think\Db;
  8. use think\Exception;
  9. class Install extends Command
  10. {
  11. protected $model = null;
  12. protected function configure()
  13. {
  14. $this
  15. ->setName('install')
  16. ->addOption('force', 'f', Option::VALUE_OPTIONAL, 'force override', FALSE)
  17. ->setDescription('New installation of FastAdmin');
  18. }
  19. protected function execute(Input $input, Output $output)
  20. {
  21. //覆盖安装
  22. $force = $input->getOption('force');
  23. $installLockFile = __DIR__ . "/Install/install.lock";
  24. if (is_file($installLockFile) && !$force)
  25. {
  26. throw new Exception("\nFastAdmin already installed!\nIf you need to reinstall again, use the parameter --force=true ");
  27. }
  28. $sql = file_get_contents(__DIR__ . '/Install/fastadmin.sql');
  29. // 查询一次SQL,判断连接是否正常
  30. Db::execute("SELECT 1");
  31. // 调用原生PDO对象进行批量查询
  32. Db::getPdo()->exec($sql);
  33. file_put_contents($installLockFile, 1);
  34. $output->info("Install Successed!");
  35. }
  36. }