From 33f5ac695a55d6cdbadcfe1b46e3409e4a66df16 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 24 Dec 2020 12:50:47 -0600 Subject: [PATCH] add files --- .../Bus/DatabaseBatchRepository.php | 30 +++++++++---------- ...unable.php => PrunableBatchRepository.php} | 4 +-- .../Queue/Console/PruneBatchesCommand.php | 6 +--- 3 files changed, 18 insertions(+), 22 deletions(-) rename src/Illuminate/Bus/{Prunable.php => PrunableBatchRepository.php} (68%) diff --git a/src/Illuminate/Bus/DatabaseBatchRepository.php b/src/Illuminate/Bus/DatabaseBatchRepository.php index bfad496fc352..ece6301c126f 100644 --- a/src/Illuminate/Bus/DatabaseBatchRepository.php +++ b/src/Illuminate/Bus/DatabaseBatchRepository.php @@ -9,7 +9,7 @@ use Illuminate\Database\Query\Expression; use Illuminate\Support\Str; -class DatabaseBatchRepository implements BatchRepository, Prunable +class DatabaseBatchRepository implements PrunableBatchRepository { /** * The batch factory instance. @@ -231,23 +231,10 @@ public function delete(string $batchId) $this->connection->table($this->table)->where('id', $batchId)->delete(); } - /** - * Execute the given Closure within a storage specific transaction. - * - * @param \Closure $callback - * @return mixed - */ - public function transaction(Closure $callback) - { - return $this->connection->transaction(function () use ($callback) { - return $callback(); - }); - } - /** * Prune all of the entries older than the given date. * - * @param DateTimeInterface $before + * @param \DateTimeInterface $before * @return int */ public function prune(DateTimeInterface $before) @@ -267,6 +254,19 @@ public function prune(DateTimeInterface $before) return $totalDeleted; } + /** + * Execute the given Closure within a storage specific transaction. + * + * @param \Closure $callback + * @return mixed + */ + public function transaction(Closure $callback) + { + return $this->connection->transaction(function () use ($callback) { + return $callback(); + }); + } + /** * Convert the given raw batch to a Batch object. * diff --git a/src/Illuminate/Bus/Prunable.php b/src/Illuminate/Bus/PrunableBatchRepository.php similarity index 68% rename from src/Illuminate/Bus/Prunable.php rename to src/Illuminate/Bus/PrunableBatchRepository.php index 5441a00dc5bf..3f972553b597 100644 --- a/src/Illuminate/Bus/Prunable.php +++ b/src/Illuminate/Bus/PrunableBatchRepository.php @@ -4,12 +4,12 @@ use DateTimeInterface; -interface Prunable +interface PrunableBatchRepository extends BatchRepository { /** * Prune all of the entries older than the given date. * - * @param DateTimeInterface $before + * @param \DateTimeInterface $before * @return int */ public function prune(DateTimeInterface $before); diff --git a/src/Illuminate/Queue/Console/PruneBatchesCommand.php b/src/Illuminate/Queue/Console/PruneBatchesCommand.php index d30b6fdb0e8d..e519c9a7759d 100644 --- a/src/Illuminate/Queue/Console/PruneBatchesCommand.php +++ b/src/Illuminate/Queue/Console/PruneBatchesCommand.php @@ -35,11 +35,7 @@ public function handle() $repository = $this->laravel[BatchRepository::class]; if ($repository instanceof Prunable) { - $hours = $this->option('hours'); - - $before = Carbon::now()->subHours($hours); - - $count = $repository->prune($before); + $count = $repository->prune(Carbon::now()->subHours($this->option('hours'))); } $this->info("{$count} entries deleted!");