Skip to content
Permalink
Browse files

Merge pull request #497 from spatie/ft-command-days-option

Added optional days argument to clean command
  • Loading branch information...
Gummibeer committed Apr 15, 2019
2 parents 6e827c0 + 40931e4 commit 5bbd3f7efc166ce68f620b3a6b97df5cc4b69ab5
Showing with 24 additions and 2 deletions.
  1. +3 −2 src/CleanActivitylogCommand.php
  2. +21 −0 tests/CleanActivitylogCommandTest.php
@@ -9,7 +9,8 @@
class CleanActivitylogCommand extends Command
{
protected $signature = 'activitylog:clean
{log? : (optional) The log name that will be cleaned.}';
{log? : (optional) The log name that will be cleaned.}
{--days= : (optional) Records older than this number of days will be cleaned.}';
protected $description = 'Clean up old records from the activity log.';
@@ -19,7 +20,7 @@ public function handle()
$log = $this->argument('log');
$maxAgeInDays = config('activitylog.delete_records_older_than_days');
$maxAgeInDays = $this->option('days') ?? config('activitylog.delete_records_older_than_days');
$cutOffDate = Carbon::now()->subDays($maxAgeInDays)->format('Y-m-d H:i:s');
@@ -37,4 +37,25 @@ public function it_can_clean_the_activity_log()
$this->assertCount(0, Activity::where('created_at', '<', $cutOffDate)->get());
}
/** @test */
public function it_can_accept_days_as_option_to_override_config_setting()
{
collect(range(1, 60))->each(function (int $index) {
Activity::create([
'description' => "item {$index}",
'created_at' => Carbon::now()->subDays($index)->startOfDay(),
]);
});
$this->assertCount(60, Activity::all());
Artisan::call('activitylog:clean', ['--days' => 7]);
$this->assertCount(7, Activity::all());
$cutOffDate = Carbon::now()->subDays(7)->format('Y-m-d H:i:s');
$this->assertCount(0, Activity::where('created_at', '<', $cutOffDate)->get());
}
}

0 comments on commit 5bbd3f7

Please sign in to comment.
You can’t perform that action at this time.