diff --git a/src/Commands/ClearCommand.php b/src/Commands/PurgeCommand.php similarity index 65% rename from src/Commands/ClearCommand.php rename to src/Commands/PurgeCommand.php index 9393c2a0..9be1ab29 100644 --- a/src/Commands/ClearCommand.php +++ b/src/Commands/PurgeCommand.php @@ -6,14 +6,15 @@ use Illuminate\Console\Command; use Illuminate\Console\ConfirmableTrait; use Illuminate\Database\DatabaseManager; +use Laravel\Pulse\Contracts\Storage; use Laravel\Pulse\Pulse; use Laravel\Pulse\Queries\Concerns\InteractsWithConnection; use Symfony\Component\Console\Attribute\AsCommand; -#[AsCommand(name: 'pulse:clear')] -class ClearCommand extends Command +#[AsCommand(name: 'pulse:purge')] +class PurgeCommand extends Command { - use ConfirmableTrait, InteractsWithConnection; + use ConfirmableTrait; /** * The database mananger. @@ -34,35 +35,29 @@ class ClearCommand extends Command * * @var string */ - public $signature = 'pulse:clear {--force : Force the operation to run when in production}'; + public $signature = 'pulse:purge {--force : Force the operation to run when in production}'; /** * The command's description. * * @var string */ - public $description = 'Clear Pulse data'; + public $description = 'Purge Pulse data'; /** * Handle the command. */ public function handle( Pulse $pulse, - Repository $config, - DatabaseManager $db, + Storage $storage, ): int { - $this->db = $db; - $this->config = $config; - if (! $this->confirmToProceed()) { return Command::FAILURE; } - $pulse->tables()->each(function ($table) { - $this->info("Clearing {$table}..."); + $storage->purge($pulse->tables()); - $this->connection()->table($table)->truncate(); - }); + $this->components->info("Tables purged."); return Command::SUCCESS; } diff --git a/src/Contracts/Storage.php b/src/Contracts/Storage.php index c655042d..de374efd 100644 --- a/src/Contracts/Storage.php +++ b/src/Contracts/Storage.php @@ -19,4 +19,11 @@ public function store(Collection $items): void; * @param \Illuminate\Support\Collection $tables */ public function trim(Collection $tables): void; + + /** + * Purge the stored entries from the given tables. + * + * @param \Illuminate\Support\Collection $tables + */ + public function purge(Collection $tables): void; } diff --git a/src/PulseServiceProvider.php b/src/PulseServiceProvider.php index 24f08631..d48e180e 100644 --- a/src/PulseServiceProvider.php +++ b/src/PulseServiceProvider.php @@ -202,7 +202,7 @@ protected function registerCommands(): void Commands\CheckCommand::class, Commands\RestartCommand::class, Commands\RegroupCommand::class, - Commands\ClearCommand::class, + Commands\PurgeCommand::class, ]); } } diff --git a/src/Storage/Database.php b/src/Storage/Database.php index ab03e521..50199c85 100644 --- a/src/Storage/Database.php +++ b/src/Storage/Database.php @@ -69,7 +69,9 @@ public function store(Collection $items): void } /** - * Trim the stored entries. + * Trim the stored entries from the given tables. + * + * @param \Illuminate\Support\Collection $tables */ public function trim(Collection $tables): void { @@ -79,6 +81,18 @@ public function trim(Collection $tables): void ->delete()); } + /** + * Purge the stored entries from the given tables. + * + * @param \Illuminate\Support\Collection $tables + */ + public function purge(Collection $tables): void + { + $tables->each(fn (string $table) => $this->connection() + ->table($table) + ->truncate()); + } + /** * The interval to trim the storage to. */