1 | <?php |
||
2 | |||
3 | namespace BeyondCode\Mailbox\Console; |
||
4 | |||
5 | use BeyondCode\Mailbox\InboundEmail; |
||
6 | use Carbon\Carbon; |
||
7 | use Illuminate\Console\Command; |
||
8 | |||
9 | class CleanEmails extends Command |
||
10 | { |
||
11 | protected $signature = 'mailbox:clean'; |
||
12 | |||
13 | protected $description = 'Clean up old incoming email logs.'; |
||
14 | |||
15 | protected $amountDeleted = 0; |
||
16 | |||
17 | public function handle() |
||
18 | { |
||
19 | $this->comment('Cleaning old incoming email logs...'); |
||
20 | |||
21 | $maxAgeInDays = config('mailbox.store_incoming_emails_for_days'); |
||
22 | |||
23 | if ($maxAgeInDays === INF) { |
||
24 | $this->error($this->signature.' is disabled because store_incoming_emails_for_days is set to INF.'); |
||
25 | |||
26 | return 1; |
||
27 | } |
||
28 | |||
29 | $cutOffDate = Carbon::now()->subDay($maxAgeInDays)->format('Y-m-d H:i:s'); |
||
0 ignored issues
–
show
|
|||
30 | |||
31 | /** @var InboundEmail $modelClass */ |
||
32 | $modelClass = config('mailbox.model'); |
||
33 | |||
34 | // chunk the deletion to avoid memory issues |
||
35 | |||
36 | $this->amountDeleted = 0; |
||
37 | |||
38 | $modelClass::where('created_at', '<', $cutOffDate) |
||
39 | ->select('id') |
||
40 | ->chunk(100, function ($models) use ($modelClass) { |
||
41 | foreach ($models as $model) { |
||
42 | $modelInstance = $modelClass::find($model->id); |
||
43 | $modelInstance->delete(); |
||
44 | $this->amountDeleted++; |
||
45 | } |
||
46 | }); |
||
47 | |||
48 | $this->info("Deleted {$this->amountDeleted} record(s) from the Mailbox logs."); |
||
49 | |||
50 | $this->comment('All done!'); |
||
51 | } |
||
52 | } |
||
53 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.