File tree Expand file tree Collapse file tree 3 files changed +110
-0
lines changed
Expand file tree Collapse file tree 3 files changed +110
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Pterodactyl \Console \Commands \Overrides ;
4+
5+ use Pterodactyl \Console \RequiresDatabaseMigrations ;
6+ use Illuminate \Database \Console \Seeds \SeedCommand as BaseSeedCommand ;
7+
8+ class SeedCommand extends BaseSeedCommand
9+ {
10+ use RequiresDatabaseMigrations;
11+
12+ /**
13+ * Block someone from running this seed command if they have not completed the migration
14+ * process.
15+ *
16+ * @return int
17+ */
18+ public function handle ()
19+ {
20+ if (!$ this ->hasCompletedMigrations ()) {
21+ return $ this ->showMigrationWarning ();
22+ }
23+
24+ return parent ::handle ();
25+ }
26+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Pterodactyl \Console \Commands \Overrides ;
4+
5+ use Pterodactyl \Console \RequiresDatabaseMigrations ;
6+ use Illuminate \Foundation \Console \UpCommand as BaseUpCommand ;
7+
8+ class UpCommand extends BaseUpCommand
9+ {
10+ use RequiresDatabaseMigrations;
11+
12+ /**
13+ * @return bool|int
14+ */
15+ public function handle ()
16+ {
17+ if (!$ this ->hasCompletedMigrations ()) {
18+ return $ this ->showMigrationWarning ();
19+ }
20+
21+ return parent ::handle ();
22+ }
23+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Pterodactyl \Console ;
4+
5+ /**
6+ * @mixin \Illuminate\Console\Command
7+ */
8+ trait RequiresDatabaseMigrations
9+ {
10+ /**
11+ * Checks if the migrations have finished running by comparing the last migration file.
12+ *
13+ * @return bool
14+ */
15+ protected function hasCompletedMigrations (): bool
16+ {
17+ /** @var \Illuminate\Database\Migrations\Migrator $migrator */
18+ $ migrator = $ this ->getLaravel ()->make ('migrator ' );
19+
20+ $ files = $ migrator ->getMigrationFiles (database_path ('migrations ' ));
21+
22+ if (! $ migrator ->repositoryExists ()) {
23+ return false ;
24+ }
25+
26+ if (array_diff (array_keys ($ files ), $ migrator ->getRepository ()->getRan ())) {
27+ return false ;
28+ }
29+
30+ return true ;
31+ }
32+
33+ /**
34+ * Throw a massive error into the console to hopefully catch the users attention and get
35+ * them to properly run the migrations rather than ignoring all of the other previous
36+ * errors...
37+ *
38+ * @return int
39+ */
40+ protected function showMigrationWarning (): int
41+ {
42+ $ this ->getOutput ()->writeln ("<options=bold>
43+ | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |
44+ | |
45+ | Your database has not been properly migrated! |
46+ | |
47+ | @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |</>
48+
49+ You must run the following command to finish migrating your database:
50+
51+ <fg=green;options=bold>php artisan migrate --step --force</>
52+
53+ You will not be able to use Pterodactyl Panel as expected without fixing your
54+ database state by running the command above.
55+ " );
56+
57+ $ this ->getOutput ()->error ("You must correct the error above before continuing. " );
58+
59+ return 1 ;
60+ }
61+ }
You can’t perform that action at this time.
0 commit comments