Skip to content

Commit 276f643

Browse files
authored
Merge pull request #53 from LukeeeeBennett/disable-cleanup
Disable cleanup artisan command if store_incoming_emails_for_days is INF
2 parents 5839bdb + 91bf919 commit 276f643

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

config/mailbox.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* The amount of days that incoming emails should be stored in your
3030
* application. You can use the cleanup artisan command to
3131
* delete all older inbound emails on a regular basis.
32+
* Set to INF to disable the cleanup artisan command.
3233
*/
3334
'store_incoming_emails_for_days' => 7,
3435

src/Console/CleanEmails.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ public function handle()
1818

1919
$maxAgeInDays = config('mailbox.store_incoming_emails_for_days');
2020

21+
if ($maxAgeInDays === INF)
22+
{
23+
$this->error($this->signature . ' is disabled because store_incoming_emails_for_days is set to INF.');
24+
return 1;
25+
}
26+
2127
$cutOffDate = Carbon::now()->subDay($maxAgeInDays)->format('Y-m-d H:i:s');
2228

2329
/** @var InboundEmail $modelClass */

tests/Console/CleanEmailsTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,25 @@ public function it_can_clean_the_statistics()
4040

4141
$this->assertCount(0, InboundEmail::where('created_at', '<', $cutOffDate)->get());
4242
}
43+
44+
/** @test */
45+
public function it_errors_if_max_age_inf()
46+
{
47+
$this->app['config']->set('mailbox.store_incoming_emails_for_days', INF);
48+
49+
Collection::times(60)->each(function (int $index) {
50+
InboundEmail::forceCreate([
51+
'message' => Str::random(),
52+
'created_at' => Carbon::now()->subDays($index)->startOfDay(),
53+
]);
54+
});
55+
56+
$this->assertCount(60, InboundEmail::all());
57+
58+
$this->artisan('mailbox:clean')
59+
->expectsOutput('mailbox:clean is disabled because store_incoming_emails_for_days is set to INF.')
60+
->assertExitCode(1);
61+
62+
$this->assertCount(60, InboundEmail::all());
63+
}
4364
}

0 commit comments

Comments
 (0)