dep: package update
This commit is contained in:
+33
-2
@@ -19,7 +19,8 @@ class PruneCommand extends Command
|
||||
*/
|
||||
protected $signature = 'model:prune
|
||||
{--model=* : Class names of the models to be pruned}
|
||||
{--chunk=1000 : The number of models to retrieve per chunk of models to be deleted}';
|
||||
{--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}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
@@ -44,6 +45,14 @@ class PruneCommand extends Command
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->option('pretend')) {
|
||||
$models->each(function ($model) {
|
||||
$this->pretendToPrune($model);
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$events->listen(ModelsPruned::class, function ($event) {
|
||||
$this->info("{$event->count} [{$event->model}] records have been pruned.");
|
||||
});
|
||||
@@ -78,7 +87,7 @@ class PruneCommand extends Command
|
||||
return collect($models);
|
||||
}
|
||||
|
||||
return collect((new Finder)->in(app_path('Models'))->files())
|
||||
return collect((new Finder)->in(app_path('Models'))->files()->name('*.php'))
|
||||
->map(function ($model) {
|
||||
$namespace = $this->laravel->getNamespace();
|
||||
|
||||
@@ -104,4 +113,26 @@ class PruneCommand extends Command
|
||||
|
||||
return in_array(Prunable::class, $uses) || in_array(MassPrunable::class, $uses);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display how many models will be pruned.
|
||||
*
|
||||
* @param string $model
|
||||
* @return void
|
||||
*/
|
||||
protected function pretendToPrune($model)
|
||||
{
|
||||
$instance = new $model;
|
||||
|
||||
$count = $instance->prunable()
|
||||
->when(in_array(SoftDeletes::class, class_uses_recursive(get_class($instance))), function ($query) {
|
||||
$query->withTrashed();
|
||||
})->count();
|
||||
|
||||
if ($count === 0) {
|
||||
$this->info("No prunable [$model] records found.");
|
||||
} else {
|
||||
$this->info("{$count} [{$model}] records will be pruned.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user