Make sure values are found

[MAILPOET-2535]
This commit is contained in:
Pavel Dohnal
2019-11-19 15:30:28 +01:00
committed by Jack Kitterhing
parent 2f262bc8ac
commit 52b4d67eca

View File

@ -129,11 +129,16 @@ class PostNotificationScheduler {
$schedule = '* * * * *';
break;
}
$relation = null;
$option_field = NewsletterOptionField::where('name', 'schedule')->findOne();
$relation = NewsletterOption::where('newsletter_id', $newsletter->id)
->where('option_field_id', $option_field->id)
->findOne();
if (!$relation) {
if ($option_field instanceof NewsletterOptionField) {
$relation = NewsletterOption::where('newsletter_id', $newsletter->id)
->where('option_field_id', $option_field->id)
->findOne();
} else {
throw new \Exception('NewsletterOptionField for schedule doesnt exist.');
}
if (!$relation instanceof NewsletterOption) {
$relation = NewsletterOption::create();
$relation->newsletter_id = $newsletter->id;
$relation->option_field_id = (int)$option_field->id;