From f4dc5180d120715cc9a1f5622070c5461008edcf Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Sun, 3 Oct 2021 16:05:24 -0700 Subject: [PATCH] flexmailer - Preview jobs are strictly unsaved --- ext/flexmailer/src/API/MailingPreview.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/ext/flexmailer/src/API/MailingPreview.php b/ext/flexmailer/src/API/MailingPreview.php index cdd11ac428..576fa1545e 100644 --- a/ext/flexmailer/src/API/MailingPreview.php +++ b/ext/flexmailer/src/API/MailingPreview.php @@ -41,11 +41,24 @@ class MailingPreview { $contactID = \CRM_Utils_Array::value('contact_id', $params, \CRM_Core_Session::singleton()->get('userID')); - $job = new \CRM_Mailing_BAO_MailingJob(); + $job = new class extends \CRM_Mailing_BAO_MailingJob { + + public function insert() { + throw new \RuntimeException('MailingJob is just a preview. It cannot be saved.'); + } + + public function update($dataObject = FALSE) { + throw new \RuntimeException('MailingJob is just a preview. It cannot be saved.'); + } + + public function save($hook = TRUE) { + throw new \RuntimeException('MailingJob is just a preview. It cannot be saved.'); + } + + }; $job->mailing_id = $mailing->id ?: NULL; $job->is_test = 1; $job->status = 'Complete'; - // $job->save(); $flexMailer = new FlexMailer(array( 'is_preview' => TRUE, -- 2.25.1