Skip to content

Commit

Permalink
add event to fetch models
Browse files Browse the repository at this point in the history
  • Loading branch information
mjauvin committed Dec 3, 2024
1 parent 37b6a2c commit a32f79a
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions src/Database/Console/PruneCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@ protected function models()
throw new InvalidArgumentException('The --models and --except options cannot be combined.');

Check failure on line 28 in src/Database/Console/PruneCommand.php

View workflow job for this annotation

GitHub Actions / Code Analysis

Instantiated class Winter\Storm\Database\Console\InvalidArgumentException not found.

Check failure on line 28 in src/Database/Console/PruneCommand.php

View workflow job for this annotation

GitHub Actions / Code Analysis

Throwing object of an unknown class Winter\Storm\Database\Console\InvalidArgumentException.
}

$paths = [
base_path() . '/modules' => '/*/models',
plugins_path() => '/*/*/models',
];

return File::findModels($paths)
return $this->findModels()
->when(! empty($except), function ($models) use ($except) {
return $models->reject(function ($model) use ($except) {
return in_array($model, $except);
Expand All @@ -45,6 +40,31 @@ protected function models()
})->values();
}

protected function findModels()
{
/**
* @event system.console.model.prune.findModels
* Give the opportunity to return a collection of Models to prune.
*
* Example usage:
*
* Event::listen('system.console.model.prune.findModels', function () {
* return collect(['example model' => '\System\Models\File']);
* });
*
*/
$models = \Event::fire('system.console.model.prune.findModels', [$this], true);

Check failure on line 56 in src/Database/Console/PruneCommand.php

View workflow job for this annotation

GitHub Actions / Code Analysis

Call to an undefined static method Illuminate\Support\Facades\Event::fire().
if ($models instanceof \Illuminate\Support\Collection) {
return $models;
}

$paths = [
base_path() . '/modules' => '/*/models',
plugins_path() => '/*/*/models',
];
return File::findModels($paths);

Check failure on line 65 in src/Database/Console/PruneCommand.php

View workflow job for this annotation

GitHub Actions / Code Analysis

Call to an undefined static method Winter\Storm\Support\Facades\File::findModels().
}

/**
* Determine if the given model class is prunable.
*
Expand Down

0 comments on commit a32f79a

Please sign in to comment.