Skip to content
Merged

5.0.2 #139

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/Console/CleanEmails.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,9 @@ public function handle()

$modelClass::where('created_at', '<', $cutOffDate)
->select('id')
->chunk(100, function ($models) use ($modelClass) {
foreach ($models as $model) {
$modelInstance = $modelClass::find($model->id);
$modelInstance->delete();
$this->amountDeleted++;
}
->eachById(count: 100, callback: function ($model) {
$model->delete();
$this->amountDeleted++;
});

$this->info("Deleted {$this->amountDeleted} record(s) from the Mailbox logs.");
Expand Down
10 changes: 5 additions & 5 deletions tests/Console/CleanEmailsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public function setUp(): void
/** @test */
public function it_can_clean_the_statistics()
{
Collection::times(60)->each(function (int $index) {
Collection::times(200)->each(function (int $index) {
InboundEmail::forceCreate([
'message' => Str::random(),
'created_at' => Carbon::now()->subDays($index)->startOfDay(),
]);
});

$this->assertCount(60, InboundEmail::all());
$this->assertCount(200, InboundEmail::all());

Artisan::call('mailbox:clean');

Expand All @@ -46,19 +46,19 @@ public function it_errors_if_max_age_inf()
{
$this->app['config']->set('mailbox.store_incoming_emails_for_days', INF);

Collection::times(60)->each(function (int $index) {
Collection::times(200)->each(function (int $index) {
InboundEmail::forceCreate([
'message' => Str::random(),
'created_at' => Carbon::now()->subDays($index)->startOfDay(),
]);
});

$this->assertCount(60, InboundEmail::all());
$this->assertCount(200, InboundEmail::all());

$this->artisan('mailbox:clean')
->expectsOutput('mailbox:clean is disabled because store_incoming_emails_for_days is set to INF.')
->assertExitCode(1);

$this->assertCount(60, InboundEmail::all());
$this->assertCount(200, InboundEmail::all());
}
}