Permalink
Browse files

Adds a log_name argument to activitylog:clean command (#301)

* Adds a log_name argument to activitylog:clean command

Arguments:
log_name (optional) The log name that will be cleaned. [default: "default"]

* Renames argument "log_name" to simply "log"

* Added condition when $log is null

* StyleCI validation

* CleanActivitylogCommandTest now creates Activity with log_name = default

* Reverting to scope

* Reverting back to query conditional

* Changes signature + CleanActivitylogCommandTest restore
  • Loading branch information...
ricardoaugusto authored and freekmurze committed Nov 7, 2017
1 parent 2748d92 commit 512476e489125808e9cf3a93630ec6c9734b5842
Showing with 9 additions and 2 deletions.
  1. +9 −2 src/CleanActivitylogCommand.php
@@ -12,7 +12,8 @@ class CleanActivitylogCommand extends Command
*
* @var string
*/
protected $signature = 'activitylog:clean';
protected $signature = 'activitylog:clean
{log? : (optional) The log name that will be cleaned.}';
/**
* The console command description.
@@ -25,13 +26,19 @@ public function handle()
{
$this->comment('Cleaning activity log...');
$log = $this->argument('log');
$maxAgeInDays = config('activitylog.delete_records_older_than_days');
$cutOffDate = Carbon::now()->subDays($maxAgeInDays)->format('Y-m-d H:i:s');
$activity = ActivitylogServiceProvider::getActivityModelInstance();
$amountDeleted = $activity::where('created_at', '<', $cutOffDate)->delete();
$amountDeleted = $activity::where('created_at', '<', $cutOffDate)
->when($log !== null, function ($query) use ($log) {
$query->inLog($log);
})
->delete();
$this->info("Deleted {$amountDeleted} record(s) from the activity log.");

0 comments on commit 512476e

Please sign in to comment.