Skip to content

Commit 6f3ea46

Browse files
committed
Add command to execute all of the normal upgrade commands for the application
1 parent fa9431c commit 6f3ea46

File tree

4 files changed

+122
-9
lines changed

4 files changed

+122
-9
lines changed

app/Console/Commands/Overrides/SeedCommand.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ class SeedCommand extends BaseSeedCommand
1313
* Block someone from running this seed command if they have not completed
1414
* the migration process.
1515
*/
16-
public function handle(): int
16+
public function handle()
1717
{
1818
if (!$this->hasCompletedMigrations()) {
19-
return $this->showMigrationWarning();
19+
$this->showMigrationWarning();
20+
21+
return;
2022
}
2123

22-
return parent::handle();
24+
parent::handle();
2325
}
2426
}

app/Console/Commands/Overrides/UpCommand.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ class UpCommand extends BaseUpCommand
1313
* Block someone from running this up command if they have not completed
1414
* the migration process.
1515
*/
16-
public function handle(): int
16+
public function handle()
1717
{
1818
if (!$this->hasCompletedMigrations()) {
19-
return $this->showMigrationWarning();
19+
$this->showMigrationWarning();
20+
21+
return;
2022
}
2123

22-
return parent::handle();
24+
parent::handle();
2325
}
2426
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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+
}

app/Console/RequiresDatabaseMigrations.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected function hasCompletedMigrations(): bool
3333
* them to properly run the migrations rather than ignoring all of the other previous
3434
* errors...
3535
*/
36-
protected function showMigrationWarning(): int
36+
protected function showMigrationWarning()
3737
{
3838
$this->getOutput()->writeln('<options=bold>
3939
| @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
@@ -51,7 +51,5 @@ protected function showMigrationWarning(): int
5151
');
5252

5353
$this->getOutput()->error('You must correct the error above before continuing.');
54-
55-
return 1;
5654
}
5755
}

0 commit comments

Comments
 (0)