Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add model:prune console command #196

Closed
wants to merge 8 commits into from
Closed

Add model:prune console command #196

wants to merge 8 commits into from

Conversation

mjauvin
Copy link
Member

@mjauvin mjauvin commented Dec 3, 2024

To show only active plugins, we need to add an event listener in Winter core as shown below:

Event::listen('system.console.model.prune.findModels', function () {
    $models = [];
    $pm = \System\Classes\PluginManager::instance();
 
    $modulesModels = File::findModels([base_path() . '/modules' => '/*/models']);
    $models[] = $modulesModels->all();
 
    $pluginsPaths = collect($pm->getPlugins())->map(function ($plugin) use ($pm) { 
        return $pm->getPluginPath($plugin);
    })->filter(function ($path) {
        return File::exists($path . '/models');
    })->each(function ($path) use (&$models) {
        $modelPaths = Finder::create()->in($path . '/models')->files()->name('/^[A-Z]{1}.+\.php$/');
        $models[] = collect($modelPaths)->map(function ($model) {
            $modelPath = str_replace(['/', '.php'], ['\\', ''], Str::after($model->getRealPath(), plugins_path().DIRECTORY_SEPARATOR));
            return ucwords($modelPath, '\\');
        })->all();
    });
 
    return collect($models)->flatten();
});

@mjauvin mjauvin added this to the 1.2.7 milestone Dec 3, 2024
@mjauvin mjauvin requested a review from LukeTowers December 3, 2024 18:24
@mjauvin mjauvin self-assigned this Dec 3, 2024
@mjauvin mjauvin marked this pull request as draft December 3, 2024 18:26
@mjauvin mjauvin marked this pull request as ready for review December 3, 2024 22:34

return in_array(Prunable::class, $uses) || in_array(MassPrunable::class, $uses);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mjauvin let's just include this in the System module directly. it's pretty dependent on that layer of Winter rather than being able to standalone in Storm.

@mjauvin
Copy link
Member Author

mjauvin commented Dec 4, 2024

moved to a different PR in winter core

@mjauvin mjauvin closed this Dec 4, 2024
@mjauvin mjauvin deleted the model-prune-cmd branch December 4, 2024 17:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants