CiviMail - Fix validation error
authorTim Otten <totten@civicrm.org>
Fri, 8 Apr 2022 22:01:31 +0000 (15:01 -0700)
committerTim Otten <totten@civicrm.org>
Fri, 8 Apr 2022 22:01:31 +0000 (15:01 -0700)
Steps to reproduce:

- Disable Flexmailer
- Use web UI
- Create a new mailing
- Fill out fields
- Submit mailing
- Observe inaccurate error - Mailing cannot be sent. There are missing or invalid fields (subject,name,from_name,from_email,body).

See also: https://civicrm.stackexchange.com/questions/41654/after-upgrade-to-civicrm-5-48-0-all-submissions-say-mailing-cannot-be-sent-th

CRM/Mailing/BAO/Mailing.php

index 5b59f5329458f11341456db35d2a4f3e83d77079..83ddc6dad59b48c9958eecef7970609df8416c4e 100644 (file)
@@ -1654,12 +1654,22 @@ ORDER BY   civicrm_email.is_bulkmail DESC
   /**
    * @deprecated
    *   This is used by CiviMail but will be made redundant by FlexMailer.
-   * @param CRM_Mailing_DAO_Mailing $mailing
+   * @param CRM_Mailing_DAO_Mailing|array $mailing
    *   The mailing which may or may not be sendable.
    * @return array
    *   List of error messages.
    */
   public static function checkSendable($mailing) {
+    if (is_array($mailing)) {
+      $params = $mailing;
+      $mailing = new \CRM_Mailing_BAO_Mailing();
+      $mailing->id = $params['id'] ?? NULL;
+      if ($mailing->id) {
+        $mailing->find(TRUE);
+      }
+      $mailing->copyValues($params);
+    }
+
     $errors = [];
     foreach (['subject', 'name', 'from_name', 'from_email'] as $field) {
       if (empty($mailing->{$field})) {