From 61ca9dcffcd9b732186625bc087440b61dd7d7fc Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Wed, 22 Feb 2023 11:24:40 +1100 Subject: [PATCH] wip --- .../Cache/Console/CacheTableCommand.php | 6 +++- .../Console/Migrations/MigrateMakeCommand.php | 28 ++++++++++++++----- .../Console/NotificationTableCommand.php | 6 +++- .../Queue/Console/BatchesTableCommand.php | 8 ++++-- .../Queue/Console/FailedTableCommand.php | 8 ++++-- src/Illuminate/Queue/Console/TableCommand.php | 8 ++++-- 6 files changed, 49 insertions(+), 15 deletions(-) diff --git a/src/Illuminate/Cache/Console/CacheTableCommand.php b/src/Illuminate/Cache/Console/CacheTableCommand.php index 3db70896cacc..bd822d01fac8 100644 --- a/src/Illuminate/Cache/Console/CacheTableCommand.php +++ b/src/Illuminate/Cache/Console/CacheTableCommand.php @@ -64,7 +64,11 @@ public function handle() $this->components->info('Migration created successfully.'); - $this->composer->dumpAutoloads(); + if (preg_match('/^return new class/', $this->files->get($fullPath)) === 0) { + $this->components->info('Regenerating the Composer autoloader files.'); + + $this->composer->dumpAutoloads(); + } } /** diff --git a/src/Illuminate/Database/Console/Migrations/MigrateMakeCommand.php b/src/Illuminate/Database/Console/Migrations/MigrateMakeCommand.php index 75c06345b1bd..4d68fefe95ed 100644 --- a/src/Illuminate/Database/Console/Migrations/MigrateMakeCommand.php +++ b/src/Illuminate/Database/Console/Migrations/MigrateMakeCommand.php @@ -4,6 +4,7 @@ use Illuminate\Contracts\Console\PromptsForMissingInput; use Illuminate\Database\Migrations\MigrationCreator; +use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Composer; use Illuminate\Support\Str; @@ -42,19 +43,28 @@ class MigrateMakeCommand extends BaseCommand implements PromptsForMissingInput */ protected $composer; + /** + * The filesystem instance. + * + * @var \Illuminate\Filesystem\Filesystem + */ + protected $files; + /** * Create a new migration install command instance. * * @param \Illuminate\Database\Migrations\MigrationCreator $creator * @param \Illuminate\Support\Composer $composer + * @param \Illuminate\Filesystem\Filesystem $files * @return void */ - public function __construct(MigrationCreator $creator, Composer $composer) + public function __construct(MigrationCreator $creator, Composer $composer, Filesystem $files = null) { parent::__construct(); $this->creator = $creator; $this->composer = $composer; + $this->files = $files ?? new Filesystem(); } /** @@ -92,9 +102,13 @@ public function handle() // Now we are ready to write the migration out to disk. Once we've written // the migration out, we will dump-autoload for the entire framework to // make sure that the migrations are registered by the class loaders. - $this->writeMigration($name, $table, $create); + $fullPath = $this->writeMigration($name, $table, $create); - $this->composer->dumpAutoloads(); + if (preg_match('/^return new class/', $this->files->get($fullPath)) === 0) { + $this->components->info('Regenerating the Composer autoloader files.'); + + $this->composer->dumpAutoloads(); + } } /** @@ -107,11 +121,11 @@ public function handle() */ protected function writeMigration($name, $table, $create) { - $file = $this->creator->create( + return tap($this->creator->create( $name, $this->getMigrationPath(), $table, $create - ); - - $this->components->info(sprintf('Migration [%s] created successfully.', $file)); + ), function ($file) { + $this->components->info(sprintf('Migration [%s] created successfully.', $file)); + }); } /** diff --git a/src/Illuminate/Notifications/Console/NotificationTableCommand.php b/src/Illuminate/Notifications/Console/NotificationTableCommand.php index dd70cdbfabb0..3c59f58c7921 100644 --- a/src/Illuminate/Notifications/Console/NotificationTableCommand.php +++ b/src/Illuminate/Notifications/Console/NotificationTableCommand.php @@ -64,7 +64,11 @@ public function handle() $this->components->info('Migration created successfully.'); - $this->composer->dumpAutoloads(); + if (preg_match('/^return new class/', $this->files->get($fullPath)) === 0) { + $this->components->info('Regenerating the Composer autoloader files.'); + + $this->composer->dumpAutoloads(); + } } /** diff --git a/src/Illuminate/Queue/Console/BatchesTableCommand.php b/src/Illuminate/Queue/Console/BatchesTableCommand.php index a11a32366192..07dc75ff4426 100644 --- a/src/Illuminate/Queue/Console/BatchesTableCommand.php +++ b/src/Illuminate/Queue/Console/BatchesTableCommand.php @@ -61,12 +61,16 @@ public function handle() $table = $this->laravel['config']['queue.batching.table'] ?? 'job_batches'; $this->replaceMigration( - $this->createBaseMigration($table), $table + $fullPath = $this->createBaseMigration($table), $table ); $this->components->info('Migration created successfully.'); - $this->composer->dumpAutoloads(); + if (preg_match('/^return new class/', $this->files->get($fullPath)) === 0) { + $this->components->info('Regenerating the Composer autoloader files.'); + + $this->composer->dumpAutoloads(); + } } /** diff --git a/src/Illuminate/Queue/Console/FailedTableCommand.php b/src/Illuminate/Queue/Console/FailedTableCommand.php index fbddbae71864..ce7a140dcfbd 100644 --- a/src/Illuminate/Queue/Console/FailedTableCommand.php +++ b/src/Illuminate/Queue/Console/FailedTableCommand.php @@ -61,12 +61,16 @@ public function handle() $table = $this->laravel['config']['queue.failed.table']; $this->replaceMigration( - $this->createBaseMigration($table), $table + $fullPath = $this->createBaseMigration($table), $table ); $this->components->info('Migration created successfully.'); - $this->composer->dumpAutoloads(); + if (preg_match('/^return new class/', $this->files->get($fullPath)) === 0) { + $this->components->info('Regenerating the Composer autoloader files.'); + + $this->composer->dumpAutoloads(); + } } /** diff --git a/src/Illuminate/Queue/Console/TableCommand.php b/src/Illuminate/Queue/Console/TableCommand.php index 1c28e7a56fbb..ffa7325d9a34 100644 --- a/src/Illuminate/Queue/Console/TableCommand.php +++ b/src/Illuminate/Queue/Console/TableCommand.php @@ -61,12 +61,16 @@ public function handle() $table = $this->laravel['config']['queue.connections.database.table']; $this->replaceMigration( - $this->createBaseMigration($table), $table + $fullPath = $this->createBaseMigration($table), $table ); $this->components->info('Migration created successfully.'); - $this->composer->dumpAutoloads(); + if (preg_match('/^return new class/', $this->files->get($fullPath)) === 0) { + $this->components->info('Regenerating the Composer autoloader files.'); + + $this->composer->dumpAutoloads(); + } } /**