From 2e656e97a97aca7831358af3fcf54dae751ea4d5 Mon Sep 17 00:00:00 2001 From: Benson Lee Date: Fri, 15 Jul 2016 13:39:15 -0700 Subject: [PATCH] Massage returned data for accurate logging --- src/DeleteOldSoftDeletes.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/DeleteOldSoftDeletes.php b/src/DeleteOldSoftDeletes.php index 1a32d68..893ce3c 100644 --- a/src/DeleteOldSoftDeletes.php +++ b/src/DeleteOldSoftDeletes.php @@ -17,6 +17,7 @@ class DeleteOldSoftDeletes extends Command public function handle() { $deletedRows = $this->deleteOldSoftDeletes() + ->flatten(1) ->reject(function ($numRowsDeleted) { return $numRowsDeleted === 0; }); @@ -30,7 +31,7 @@ private function deleteOldSoftDeletes() $daysBeforeDeletion = config('quicksand.days'); if (empty($daysBeforeDeletion)) { - return collect([]); + return new Collection; } return $models->map(function ($modelConfig, $modelName) use ($daysBeforeDeletion) { @@ -40,16 +41,16 @@ private function deleteOldSoftDeletes() } return $this->deleteOldSoftDeletesForModel($modelName, $modelConfig, $daysBeforeDeletion); - }); + })->values(); } private function deleteOldSoftDeletesForModel($modelName, $modelConfig, $daysBeforeDeletion) { $daysBeforeDeletion = empty($modelConfig['days']) ? $daysBeforeDeletion : $modelConfig['days']; - return DB::table((new $modelName)::getTableName()) + return [$modelName => DB::table((new $modelName)::getTableName()) ->where('deleted_at', '<', Carbon::today()->subDays($daysBeforeDeletion)) - ->delete(); + ->delete()]; } private function logAffectedRows(Collection $deletedRows)