Add command to execute all of the normal upgrade commands for the application
This commit is contained in:
		
							parent
							
								
									fa9431c54d
								
							
						
					
					
						commit
						6f3ea462a7
					
				| @ -13,12 +13,14 @@ class SeedCommand extends BaseSeedCommand | |||||||
|      * Block someone from running this seed command if they have not completed |      * Block someone from running this seed command if they have not completed | ||||||
|      * the migration process. |      * the migration process. | ||||||
|      */ |      */ | ||||||
|     public function handle(): int |     public function handle() | ||||||
|     { |     { | ||||||
|         if (!$this->hasCompletedMigrations()) { |         if (!$this->hasCompletedMigrations()) { | ||||||
|             return $this->showMigrationWarning(); |             $this->showMigrationWarning(); | ||||||
|  | 
 | ||||||
|  |             return; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         return parent::handle(); |         parent::handle(); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -13,12 +13,14 @@ class UpCommand extends BaseUpCommand | |||||||
|      * Block someone from running this up command if they have not completed |      * Block someone from running this up command if they have not completed | ||||||
|      * the migration process. |      * the migration process. | ||||||
|      */ |      */ | ||||||
|     public function handle(): int |     public function handle() | ||||||
|     { |     { | ||||||
|         if (!$this->hasCompletedMigrations()) { |         if (!$this->hasCompletedMigrations()) { | ||||||
|             return $this->showMigrationWarning(); |             $this->showMigrationWarning(); | ||||||
|  | 
 | ||||||
|  |             return; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         return parent::handle(); |         parent::handle(); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										111
									
								
								app/Console/Commands/UpgradeCommand.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										111
									
								
								app/Console/Commands/UpgradeCommand.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,111 @@ | |||||||
|  | <?php | ||||||
|  | 
 | ||||||
|  | namespace Pterodactyl\Console\Commands; | ||||||
|  | 
 | ||||||
|  | use Closure; | ||||||
|  | use Illuminate\Console\Command; | ||||||
|  | use Pterodactyl\Console\Kernel; | ||||||
|  | use Symfony\Component\Process\Process; | ||||||
|  | use Symfony\Component\Console\Helper\ProgressBar; | ||||||
|  | 
 | ||||||
|  | class UpgradeCommand extends Command | ||||||
|  | { | ||||||
|  |     /** @var string */ | ||||||
|  |     protected $signature = 'p:upgrade {--force}'; | ||||||
|  | 
 | ||||||
|  |     /** @var string */ | ||||||
|  |     protected $description = 'Executes the commands necessary for getting Pterodactyl operational after installing new files.'; | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Executes an upgrade command which will run through all of our standard | ||||||
|  |      * commands for Pterodactyl and enable users to basically just download | ||||||
|  |      * the archive and execute this and be done. | ||||||
|  |      * | ||||||
|  |      * This places the application in maintenance mode as well while the commands | ||||||
|  |      * are being executed. | ||||||
|  |      * | ||||||
|  |      * @throws \Exception | ||||||
|  |      */ | ||||||
|  |     public function handle() | ||||||
|  |     { | ||||||
|  |         if ($this->input->isInteractive()) { | ||||||
|  |             if (!$this->confirm('Are you sure you want to run the upgrade process for your Panel?')) { | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         ini_set('output_buffering', 0); | ||||||
|  |         $bar = $this->output->createProgressBar(8); | ||||||
|  |         $bar->start(); | ||||||
|  | 
 | ||||||
|  |         $this->withProgress($bar, function () { | ||||||
|  |             $this->line('$upgrader> php artisan down'); | ||||||
|  |             $this->call('down'); | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|  |         $this->withProgress($bar, function () { | ||||||
|  |             $this->line('$upgrader> chmod -R 755 storage bootstrap/cache'); | ||||||
|  |             $process = new Process(['chmod', '-R', '755', 'storage', 'bootstrap/cache']); | ||||||
|  |             $process->run(function ($type, $buffer) { | ||||||
|  |                 $this->{$type === Process::ERR ? 'error' : 'line'}($buffer); | ||||||
|  |             }); | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|  |         $this->withProgress($bar, function () { | ||||||
|  |             $command = ['composer', 'install', '--no-ansi']; | ||||||
|  |             if (config('app.env') === 'production' && !config('app.debug')) { | ||||||
|  |                 $command[] = '--optimize-autoloader'; | ||||||
|  |                 $command[] = '--no-dev'; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             $this->line('$upgrader> ' . implode(' ', $command)); | ||||||
|  |             $process = new Process($command); | ||||||
|  |             $process->run(function ($type, $buffer) { | ||||||
|  |                 $this->line($buffer); | ||||||
|  |             }); | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|  |         /** @var \Illuminate\Foundation\Application $app */ | ||||||
|  |         $app = require __DIR__ . '/../../../bootstrap/app.php'; | ||||||
|  |         /** @var \Pterodactyl\Console\Kernel $kernel */ | ||||||
|  |         $kernel = $app->make(Kernel::class); | ||||||
|  |         $kernel->bootstrap(); | ||||||
|  |         $this->setLaravel($app); | ||||||
|  | 
 | ||||||
|  |         $this->withProgress($bar, function () { | ||||||
|  |             $this->line('$upgrader> php artisan view:clear'); | ||||||
|  |             $this->call('view:clear'); | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|  |         $this->withProgress($bar, function () { | ||||||
|  |             $this->line('$upgrader> php artisan config:clear'); | ||||||
|  |             $this->call('config:clear'); | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|  |         $this->withProgress($bar, function () { | ||||||
|  |             $this->line('$upgrader> php artisan migrate --seed --force'); | ||||||
|  |             $this->call('migrate', ['--seed' => '', '--force' => '']); | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|  |         $this->withProgress($bar, function () { | ||||||
|  |             $this->line('$upgrader> php artisan queue:restart'); | ||||||
|  |             $this->call('queue:restart'); | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|  |         $this->withProgress($bar, function () { | ||||||
|  |             $this->line('$upgrader> php artisan up'); | ||||||
|  |             $this->call('up'); | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|  |         $this->newLine(); | ||||||
|  |         $this->info('Finished running upgrade.'); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     protected function withProgress(ProgressBar $bar, Closure $callback) | ||||||
|  |     { | ||||||
|  |         $bar->clear(); | ||||||
|  |         $callback(); | ||||||
|  |         $bar->advance(); | ||||||
|  |         $bar->display(); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -33,7 +33,7 @@ trait RequiresDatabaseMigrations | |||||||
|      * them to properly run the migrations rather than ignoring all of the other previous |      * them to properly run the migrations rather than ignoring all of the other previous | ||||||
|      * errors... |      * errors... | ||||||
|      */ |      */ | ||||||
|     protected function showMigrationWarning(): int |     protected function showMigrationWarning() | ||||||
|     { |     { | ||||||
|         $this->getOutput()->writeln('<options=bold> |         $this->getOutput()->writeln('<options=bold> | ||||||
| | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | | | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ | | ||||||
| @ -51,7 +51,5 @@ database state by running the command above. | |||||||
| '); | '); | ||||||
| 
 | 
 | ||||||
|         $this->getOutput()->error('You must correct the error above before continuing.'); |         $this->getOutput()->error('You must correct the error above before continuing.'); | ||||||
| 
 |  | ||||||
|         return 1; |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Dane Everitt
						Dane Everitt