laravel / pennant

A simple, lightweight library for managing feature flags.
https://laravel.com/docs/pennant
MIT License
479 stars 49 forks source link

Calling pennant:purge command via Artisan::call() keeps failing #76

Closed stephenjude closed 11 months ago

stephenjude commented 11 months ago

Pennant Version

1.5

Laravel Version

10.31.0

PHP Version

8.1.15

Database Driver & Version

MySQL 8.0.32

Description

Calling pennant:purge command via Artisan::call() keeps failing when done outside the terminal.

Like calling it inside a queue job class.

I believe this is because the console commands are registered to only run when the application is running in console.

if ($this->app->runningInConsole()) {
    $this->offerPublishing();

    $this->commands([
        \Laravel\Pennant\Commands\FeatureMakeCommand::class,
        \Laravel\Pennant\Commands\PurgeCommand::class,
    ]);
}

Can we have this check removed so the command can be run from anywhere in the application?

Steps To Reproduce

Create a job class and call the the pennant:purge command inside the handle() method like this:

public function handle(): void
{
    Artisan::call('pennant:purge');
}

Screenshot:

image
crynobone commented 11 months ago

You should be able to just do the following:

use Laravel\Pennant\FeatureManager;

app(FeatureManager::class)->store()->purge();
stephenjude commented 11 months ago

Thank you @crynobone