Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
Massage returned data for accurate logging
Browse files Browse the repository at this point in the history
  • Loading branch information
besologic committed Jul 15, 2016
1 parent 6fcfddb commit 2e656e9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/DeleteOldSoftDeletes.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class DeleteOldSoftDeletes extends Command
public function handle()
{
$deletedRows = $this->deleteOldSoftDeletes()
->flatten(1)
->reject(function ($numRowsDeleted) {
return $numRowsDeleted === 0;
});
Expand All @@ -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) {
Expand All @@ -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)
Expand Down

0 comments on commit 2e656e9

Please sign in to comment.