PanelUpdate.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Console\Commands;
  3. use Artisan;
  4. use Illuminate\Console\Command;
  5. class PanelUpdate extends Command
  6. {
  7. protected $signature = 'panel:update';
  8. protected $description = 'ProxyPanel Version Update (面板更新)';
  9. public function handle(): void
  10. {
  11. $bar = $this->output->createProgressBar(2);
  12. $bar->minSecondsBetweenRedraws(0);
  13. $this->displayBanner();
  14. $bar->start();
  15. $this->updateDatabase();
  16. $bar->advance();
  17. $this->updateCache();
  18. $bar->finish();
  19. $this->info(trans('setup.update_complete'));
  20. }
  21. private function displayBanner(): void
  22. {
  23. $banner = <<<BANNER
  24. ___ ___ _
  25. / _ \ _ __ ___ __ __ _ _ / _ \ __ _ _ __ ___ | |
  26. / /_)/| '__| / _ \ \ \/ /| | | | / /_)/ / _` || '_ \ / _ \| |
  27. / ___/ | | | (_) | > < | |_| |/ ___/ | (_| || | | || __/| |
  28. \/ |_| \___/ /_/\_\ \__, |\/ \__,_||_| |_| \___||_|
  29. |___/
  30. BANNER;
  31. $this->info($banner);
  32. }
  33. private function updateDatabase(): void
  34. {
  35. $this->line(trans('setup.update_db'));
  36. Artisan::call('migrate --force');
  37. if (config('app.env') === 'demo' && $this->confirm(trans('setup.demo_reset'))) {
  38. Artisan::call('migrate:fresh --seed --force');
  39. }
  40. }
  41. private function updateCache(): void
  42. {
  43. $this->line(trans('setup.update_cache'));
  44. Artisan::call('optimize');
  45. }
  46. }