Skip to content

Commit

Permalink
trash pruning config changed
Browse files Browse the repository at this point in the history
  • Loading branch information
ajaycalicut17 committed Sep 14, 2023
1 parent a2b8bc5 commit 26e371c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
6 changes: 4 additions & 2 deletions config/trash.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
|
*/

'pruning_status' => false,
'pruning_period' => now()->subMonth(),
'pruning' => [
'status' => false,
'period' => now()->subMonth(),
],
];
4 changes: 2 additions & 2 deletions src/Models/Trash.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ public static function emptyTrash(): LazyCollection
*/
public function prunable(): Builder
{
return static::where('created_at', '<=', config('trash.pruning_period'))
->when(! config('trash.pruning_status'), function ($when) {
return static::where('created_at', '<=', config('trash.pruning.period'))
->when(! config('trash.pruning.status'), function ($when) {
$when->whereNull('id');
});
}
Expand Down
10 changes: 5 additions & 5 deletions tests/Feature/TrashTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@
$trashes[$key]['trashable_type'] = $user::class;
$trashes[$key]['trashable_id'] = $user->id;
$trashes[$key]['name'] = User::trashName($user);
$trashes[$key]['created_at'] = config('trash.pruning_period');
$trashes[$key]['updated_at'] = config('trash.pruning_period');
$trashes[$key]['created_at'] = config('trash.pruning.period');
$trashes[$key]['updated_at'] = config('trash.pruning.period');
});

Trash::insert($trashes);

assertDatabaseCount('trashes', 10);

config(['trash.pruning_status' => true]);
config(['trash.pruning.status' => true]);

$result = artisan('model:prune', [
'--model' => Trash::class,
Expand All @@ -129,8 +129,8 @@
$trashes[$key]['trashable_type'] = $user::class;
$trashes[$key]['trashable_id'] = $user->id;
$trashes[$key]['name'] = User::trashName($user);
$trashes[$key]['created_at'] = config('trash.pruning_period');
$trashes[$key]['updated_at'] = config('trash.pruning_period');
$trashes[$key]['created_at'] = config('trash.pruning.period');
$trashes[$key]['updated_at'] = config('trash.pruning.period');
});

Trash::insert($trashes);
Expand Down

0 comments on commit 26e371c

Please sign in to comment.