Skip to content

Commit 4efee7a

Browse files
committed
Ensure unserialize for description works.
1 parent d1560de commit 4efee7a

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed

config/mailator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
* Class that will mark the scheduled action as being completed so the action will do not be counted into the next iteration.
3232
*/
3333
'garbage_resolver' => Binarcode\LaravelMailator\Actions\ResolveGarbageAction::class,
34+
35+
/**
36+
* Mark action completed after this count of fails.
37+
*/
38+
'mark_complete_after_fails_count' => env('MAILATOR_FAILED_COUNTS', 3),
3439
],
3540

3641
'log_model' => Binarcode\LaravelMailator\Models\MailatorLog::class,

src/Actions/ResolveGarbageAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function shouldMarkComplete(MailatorSchedule $schedule): bool
3535
return true;
3636
}
3737

38-
if ($schedule->failedLastTimes(3)) {
38+
if ($schedule->failedLastTimes(config('mailator.scheduler.mark_complete_after_fails_count', 3))) {
3939
return true;
4040
}
4141

src/Models/Concerns/ConstraintsResolver.php

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Binarcode\LaravelMailator\Constraints\SendScheduleConstraint;
1515
use Binarcode\LaravelMailator\Constraints\WeeklyConstraint;
1616
use Binarcode\LaravelMailator\Models\MailatorSchedule;
17+
use Throwable;
1718

1819
/**
1920
* Trait ConstraintsResolver
@@ -53,22 +54,34 @@ public function eventsPasses(): bool
5354

5455
public function constraintsDescriptions(): array
5556
{
56-
return collect($this->constraints)
57-
->map(fn (string $event) => unserialize($event))
58-
->filter(fn ($event) => is_subclass_of($event, Descriptionable::class))
59-
->reduce(function ($base, Descriptionable $descriable) {
60-
return array_merge($base, $descriable::conditions());
61-
}, []);
57+
try {
58+
return collect($this->constraints)
59+
->map(fn(string $event) => unserialize($event))
60+
->filter(fn($event) => is_subclass_of($event, Descriptionable::class))
61+
->reduce(function ($base, Descriptionable $descriable) {
62+
return array_merge($base, $descriable::conditions());
63+
}, []);
64+
} catch (Throwable $e) {
65+
$this->markAsFailed($e->getMessage());
66+
67+
return [];
68+
}
6269
}
6370

6471
public function constraintsNotSatisfiedDescriptions(): array
6572
{
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+
try {
74+
return collect($this->constraints)
75+
->map(fn(string $event) => unserialize($event))
76+
->filter(fn($event) => is_subclass_of($event, Descriptionable::class))
77+
->filter(fn($event) => !$event->canSend($this, $this->logs))
78+
->reduce(function ($base, Descriptionable $descriable) {
79+
return array_merge($base, $descriable::conditions());
80+
}, []);
81+
} catch (Throwable $e) {
82+
$this->markAsFailed($e->getMessage());
83+
84+
return [];
85+
}
7386
}
7487
}

0 commit comments

Comments
 (0)