From f08994907db78caa12981bfd285a57231b52a773 Mon Sep 17 00:00:00 2001 From: Davo Hynds Date: Mon, 8 Jan 2024 14:27:37 -0600 Subject: [PATCH 1/4] Add an option to specify the default path to the models directory --- src/Illuminate/Database/Console/PruneCommand.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Database/Console/PruneCommand.php b/src/Illuminate/Database/Console/PruneCommand.php index aeb10e2df6c..255e5e26e7b 100644 --- a/src/Illuminate/Database/Console/PruneCommand.php +++ b/src/Illuminate/Database/Console/PruneCommand.php @@ -23,7 +23,8 @@ class PruneCommand extends Command {--model=* : Class names of the models to be pruned} {--except=* : Class names of the models to be excluded from pruning} {--chunk=1000 : The number of models to retrieve per chunk of models to be deleted} - {--pretend : Display the number of prunable records found instead of deleting them}'; + {--pretend : Display the number of prunable records found instead of deleting them} + {--default-path=Models : The default path where models are located}'; /** * The console command description. @@ -121,7 +122,7 @@ protected function models() */ protected function getDefaultPath() { - return app_path('Models'); + return app_path($this->option('default-path')); } /** From e51f1460084c0efe5a8eca451e79bc87eeee706c Mon Sep 17 00:00:00 2001 From: Davo Hynds Date: Tue, 9 Jan 2024 09:23:02 -0600 Subject: [PATCH 2/4] Change the argument to path --- src/Illuminate/Database/Console/PruneCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Database/Console/PruneCommand.php b/src/Illuminate/Database/Console/PruneCommand.php index 255e5e26e7b..003bc6044a9 100644 --- a/src/Illuminate/Database/Console/PruneCommand.php +++ b/src/Illuminate/Database/Console/PruneCommand.php @@ -24,7 +24,7 @@ class PruneCommand extends Command {--except=* : Class names of the models to be excluded from pruning} {--chunk=1000 : The number of models to retrieve per chunk of models to be deleted} {--pretend : Display the number of prunable records found instead of deleting them} - {--default-path=Models : The default path where models are located}'; + {--path=Models : The default path where models are located}'; /** * The console command description. @@ -122,7 +122,7 @@ protected function models() */ protected function getDefaultPath() { - return app_path($this->option('default-path')); + return app_path($this->option('path')); } /** From 94550906944507d496d0e3735eea48efe69f799f Mon Sep 17 00:00:00 2001 From: Davo Hynds Date: Tue, 9 Jan 2024 11:35:23 -0600 Subject: [PATCH 3/4] Allow an array, but fall back to app/Models --- src/Illuminate/Database/Console/PruneCommand.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Database/Console/PruneCommand.php b/src/Illuminate/Database/Console/PruneCommand.php index 003bc6044a9..a2026a3f45c 100644 --- a/src/Illuminate/Database/Console/PruneCommand.php +++ b/src/Illuminate/Database/Console/PruneCommand.php @@ -24,7 +24,7 @@ class PruneCommand extends Command {--except=* : Class names of the models to be excluded from pruning} {--chunk=1000 : The number of models to retrieve per chunk of models to be deleted} {--pretend : Display the number of prunable records found instead of deleting them} - {--path=Models : The default path where models are located}'; + {--path=* : Absolute path(s) to directories where models are located}'; /** * The console command description. @@ -97,7 +97,7 @@ protected function models() throw new InvalidArgumentException('The --models and --except options cannot be combined.'); } - return collect((new Finder)->in($this->getDefaultPath())->files()->name('*.php')) + return collect((new Finder)->in($this->getPath())->files()->name('*.php')) ->map(function ($model) { $namespace = $this->laravel->getNamespace(); @@ -120,9 +120,14 @@ protected function models() * * @return string */ - protected function getDefaultPath() + protected function getPath() { - return app_path($this->option('path')); + + if (! empty($path = $this->option('path'))) { + return $path; + } + + return app_path('Models'); } /** From 9d687c93033608adfb89cf64efe53ea4ec945c25 Mon Sep 17 00:00:00 2001 From: Davo Hynds Date: Tue, 9 Jan 2024 13:00:30 -0600 Subject: [PATCH 4/4] Fix styling and doc block --- src/Illuminate/Database/Console/PruneCommand.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Illuminate/Database/Console/PruneCommand.php b/src/Illuminate/Database/Console/PruneCommand.php index a2026a3f45c..39481536a8d 100644 --- a/src/Illuminate/Database/Console/PruneCommand.php +++ b/src/Illuminate/Database/Console/PruneCommand.php @@ -116,13 +116,12 @@ protected function models() } /** - * Get the default path where models are located. + * Get the path where models are located. * * @return string */ protected function getPath() { - if (! empty($path = $this->option('path'))) { return $path; }