|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Pterodactyl\Console\Commands; |
| 4 | + |
| 5 | +use Closure; |
| 6 | +use Illuminate\Console\Command; |
| 7 | +use Pterodactyl\Console\Kernel; |
| 8 | +use Symfony\Component\Process\Process; |
| 9 | +use Symfony\Component\Console\Helper\ProgressBar; |
| 10 | + |
| 11 | +class UpgradeCommand extends Command |
| 12 | +{ |
| 13 | + /** @var string */ |
| 14 | + protected $signature = 'p:upgrade {--force}'; |
| 15 | + |
| 16 | + /** @var string */ |
| 17 | + protected $description = 'Executes the commands necessary for getting Pterodactyl operational after installing new files.'; |
| 18 | + |
| 19 | + /** |
| 20 | + * Executes an upgrade command which will run through all of our standard |
| 21 | + * commands for Pterodactyl and enable users to basically just download |
| 22 | + * the archive and execute this and be done. |
| 23 | + * |
| 24 | + * This places the application in maintenance mode as well while the commands |
| 25 | + * are being executed. |
| 26 | + * |
| 27 | + * @throws \Exception |
| 28 | + */ |
| 29 | + public function handle() |
| 30 | + { |
| 31 | + if ($this->input->isInteractive()) { |
| 32 | + if (!$this->confirm('Are you sure you want to run the upgrade process for your Panel?')) { |
| 33 | + return; |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + ini_set('output_buffering', 0); |
| 38 | + $bar = $this->output->createProgressBar(8); |
| 39 | + $bar->start(); |
| 40 | + |
| 41 | + $this->withProgress($bar, function () { |
| 42 | + $this->line('$upgrader> php artisan down'); |
| 43 | + $this->call('down'); |
| 44 | + }); |
| 45 | + |
| 46 | + $this->withProgress($bar, function () { |
| 47 | + $this->line('$upgrader> chmod -R 755 storage bootstrap/cache'); |
| 48 | + $process = new Process(['chmod', '-R', '755', 'storage', 'bootstrap/cache']); |
| 49 | + $process->run(function ($type, $buffer) { |
| 50 | + $this->{$type === Process::ERR ? 'error' : 'line'}($buffer); |
| 51 | + }); |
| 52 | + }); |
| 53 | + |
| 54 | + $this->withProgress($bar, function () { |
| 55 | + $command = ['composer', 'install', '--no-ansi']; |
| 56 | + if (config('app.env') === 'production' && !config('app.debug')) { |
| 57 | + $command[] = '--optimize-autoloader'; |
| 58 | + $command[] = '--no-dev'; |
| 59 | + } |
| 60 | + |
| 61 | + $this->line('$upgrader> ' . implode(' ', $command)); |
| 62 | + $process = new Process($command); |
| 63 | + $process->run(function ($type, $buffer) { |
| 64 | + $this->line($buffer); |
| 65 | + }); |
| 66 | + }); |
| 67 | + |
| 68 | + /** @var \Illuminate\Foundation\Application $app */ |
| 69 | + $app = require __DIR__ . '/../../../bootstrap/app.php'; |
| 70 | + /** @var \Pterodactyl\Console\Kernel $kernel */ |
| 71 | + $kernel = $app->make(Kernel::class); |
| 72 | + $kernel->bootstrap(); |
| 73 | + $this->setLaravel($app); |
| 74 | + |
| 75 | + $this->withProgress($bar, function () { |
| 76 | + $this->line('$upgrader> php artisan view:clear'); |
| 77 | + $this->call('view:clear'); |
| 78 | + }); |
| 79 | + |
| 80 | + $this->withProgress($bar, function () { |
| 81 | + $this->line('$upgrader> php artisan config:clear'); |
| 82 | + $this->call('config:clear'); |
| 83 | + }); |
| 84 | + |
| 85 | + $this->withProgress($bar, function () { |
| 86 | + $this->line('$upgrader> php artisan migrate --seed --force'); |
| 87 | + $this->call('migrate', ['--seed' => '', '--force' => '']); |
| 88 | + }); |
| 89 | + |
| 90 | + $this->withProgress($bar, function () { |
| 91 | + $this->line('$upgrader> php artisan queue:restart'); |
| 92 | + $this->call('queue:restart'); |
| 93 | + }); |
| 94 | + |
| 95 | + $this->withProgress($bar, function () { |
| 96 | + $this->line('$upgrader> php artisan up'); |
| 97 | + $this->call('up'); |
| 98 | + }); |
| 99 | + |
| 100 | + $this->newLine(); |
| 101 | + $this->info('Finished running upgrade.'); |
| 102 | + } |
| 103 | + |
| 104 | + protected function withProgress(ProgressBar $bar, Closure $callback) |
| 105 | + { |
| 106 | + $bar->clear(); |
| 107 | + $callback(); |
| 108 | + $bar->advance(); |
| 109 | + $bar->display(); |
| 110 | + } |
| 111 | +} |
0 commit comments