This commit is contained in:
Oliver Davies 2025-06-24 00:59:50 +01:00
parent 88d5d4a126
commit bde36ee056

View file

@ -15,18 +15,7 @@ readonly final class AddRandomCtaToDailyEmail {
}
public function __invoke(DailyEmail $email): void {
if (!$email->isNew()) {
return;
}
if ($email->get('field_daily_email_cta')->getValue() !== []) {
return;
}
$body = $email->get('body')->value;
assert(is_string($body));
if (str_contains(haystack: $body, needle: 'P.S.')) {
if (!$this->shouldUpdate($email)) {
return;
}
@ -51,4 +40,23 @@ readonly final class AddRandomCtaToDailyEmail {
return Ctas::fromNodes($ctaNodes);
}
private function shouldUpdate(DailyEmail $email): bool {
if (!$email->isNew()) {
return FALSE;
}
if ($email->get('field_daily_email_cta')->getValue() !== []) {
return FALSE;
}
$body = $email->get('body')->value;
assert(is_string($body));
if (str_contains(haystack: $body, needle: 'P.S.')) {
return FALSE;
}
return TRUE;
}
}