*
* - _skip_evil_bao_auto_recipients_: bool
* - _skip_evil_bao_auto_schedule_: bool
- * - _evil_bao_validator_: string|callable
*
* </twowrongsmakesaright>
*
// check and attach and files as needed
CRM_Core_BAO_File::processAttachment($params, 'civicrm_mailing', $mailing->id);
- // If we're going to autosend, then check validity before saving.
- if (empty($params['is_completed']) && !empty($params['scheduled_date']) && $params['scheduled_date'] != 'null' && !empty($params['_evil_bao_validator_'])) {
- $cb = Civi\Core\Resolver::singleton()
- ->get($params['_evil_bao_validator_']);
- $errors = call_user_func($cb, $mailing);
- if (!empty($errors)) {
- $fields = implode(',', array_keys($errors));
- throw new CRM_Core_Exception("Mailing cannot be sent. There are missing or invalid fields ($fields).", 'cannot-send', $errors);
- }
- }
-
$transaction->commit();
// Create parent job if not yet created.
if (!$timestampCheck) {
throw new API_Exception("Mailing has not been saved, Content maybe out of date, please refresh the page and try again");
}
+ // If we're going to autosend, then check validity before saving.
+ if (empty($params['is_completed']) && !empty($params['scheduled_date'])
+ && $params['scheduled_date'] !== 'null'
+ // This might have been passed in as empty to prevent us validating, is set skip.
+ && !isset($params['_evil_bao_validator_'])) {
+
+ // FlexMailer is a refactoring of CiviMail which provides new hooks/APIs/docs. If the sysadmin has opted to enable it, then use that instead of CiviMail.
+ $function = \CRM_Utils_Constant::value('CIVICRM_FLEXMAILER_HACK_SENDABLE', 'CRM_Mailing_BAO_Mailing::checkSendable');
+ $validationFunction = Civi\Core\Resolver::singleton()->get($function);
+ $errors = call_user_func($validationFunction, $params);
+ if (!empty($errors)) {
+ $fields = implode(',', array_keys($errors));
+ throw new CiviCRM_API3_Exception("Mailing cannot be sent. There are missing or invalid fields ($fields).", 'cannot-send', $errors);
+ }
+ }
- // FlexMailer is a refactoring of CiviMail which provides new hooks/APIs/docs. If the sysadmin has opted to enable it, then use that instead of CiviMail.
- $safeParams['_evil_bao_validator_'] = \CRM_Utils_Constant::value('CIVICRM_FLEXMAILER_HACK_SENDABLE', 'CRM_Mailing_BAO_Mailing::checkSendable');
$result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $safeParams, 'Mailing');
return _civicrm_api3_mailing_get_formatResult($result);
}
const EVENT_CHECK_SENDABLE = 'civi.flexmailer.checkSendable';
/**
- * @param \CRM_Mailing_DAO_Mailing $mailing
+ * @param array $params
* The mailing which may or may not be sendable.
* @return array
* List of error messages.
*/
- public static function createAndRun($mailing) {
- $validator = new \Civi\FlexMailer\Validator();
- return $validator->run(array(
+ public static function createAndRun(array $params): array {
+ $mailing = new \CRM_Mailing_BAO_Mailing();
+ $mailing->id = $params['id'] ?? NULL;
+ if ($mailing->id) {
+ $mailing->find(TRUE);
+ }
+ $mailing->copyValues($params);
+
+ return (new Validator())->run(array(
'mailing' => $mailing,
'attachments' => \CRM_Core_BAO_File::getEntityFile('civicrm_mailing', $mailing->id),
));