Skip to content

Commit 37d1c52

Browse files
authored
Merge pull request #2554 from maloun96/fix_logs
Fix logs
2 parents 649d199 + e014ccc commit 37d1c52

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/Models/Concerns/ConstraintsResolver.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,15 @@ public function constraintsDescriptions(): array
6060
return array_merge($base, $descriable::conditions());
6161
}, []);
6262
}
63+
64+
public function constraintsNotSatisfiedDescriptions(): array
65+
{
66+
return collect($this->constraints)
67+
->map(fn (string $event) => unserialize($event))
68+
->filter(fn ($event) => is_subclass_of($event, Descriptionable::class))
69+
->filter(fn ($event) => !$event->canSend($this, $this->logs))
70+
->reduce(function ($base, Descriptionable $descriable) {
71+
return array_merge($base, $descriable::conditions());
72+
}, []);
73+
}
6374
}

src/Models/MailatorLog.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@
22

33
namespace Binarcode\LaravelMailator\Models;
44

5+
use Binarcode\LaravelMailator\Models\Concerns\ConstraintsResolver;
6+
use Binarcode\LaravelMailator\Models\Concerns\HasFuture;
7+
use Binarcode\LaravelMailator\Models\Concerns\HasTarget;
8+
use Binarcode\LaravelMailator\Support\ClassResolver;
59
use Carbon\Carbon;
610
use Illuminate\Database\Eloquent\Model;
711

812
/**
913
* Class MailatorLog
1014
* @property string $status
1115
* @property Carbon $created_at
16+
* @property array recipients
1217
* @package Binarcode\LaravelMailator\Models
1318
*/
1419
class MailatorLog extends Model
@@ -32,7 +37,7 @@ public function getTable()
3237
'updated_at',
3338
];
3439

35-
protected $cast = [
40+
protected $casts = [
3641
'action_at' => 'datetime',
3742
'created_at' => 'datetime',
3843
'updated_at' => 'datetime',

src/Models/MailatorSchedule.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Illuminate\Database\Eloquent\Model;
2121
use Illuminate\Database\Eloquent\Relations\HasMany;
2222
use Illuminate\Support\Arr;
23+
use Illuminate\Support\Collection;
2324
use Illuminate\Support\Facades\Validator;
2425
use Illuminate\Support\Str;
2526
use Opis\Closure\SerializableClosure;
@@ -381,7 +382,8 @@ public function markAsSent(): self
381382
{
382383
$this->logs()
383384
->create([
384-
// 'recipients' => $this->getRecipients(),
385+
'recipients' => $this->getRecipients(),
386+
'name' => $this->name,
385387
'status' => MailatorLog::STATUS_SENT,
386388
'action_at' => now(),
387389
'created_at' => now(),
@@ -397,6 +399,8 @@ public function markAsSent(): self
397399
public function markAsFailed(string $failureReason): self
398400
{
399401
$this->logs()->create([
402+
'recipients' => $this->getRecipients(),
403+
'name' => $this->name,
400404
'status' => MailatorLog::STATUS_FAILED,
401405
'action_at' => now(),
402406
'created_at' => now(),

0 commit comments

Comments
 (0)