X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=api%2Fv3%2FMailing.php;h=a89cb0d471fd9cf6b10daf72534969813fa6d093;hb=742ef03771e554d62c94faac38f469064118ad0b;hp=83bc28b7412cbb2ab05c3826cc6e8dd9583dd7ac;hpb=dec6eb78086f0c401380a06e8d64144b111dd7be;p=civicrm-core.git diff --git a/api/v3/Mailing.php b/api/v3/Mailing.php index 83bc28b741..a89cb0d471 100644 --- a/api/v3/Mailing.php +++ b/api/v3/Mailing.php @@ -36,9 +36,22 @@ function civicrm_api3_mailing_create($params) { 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); } @@ -716,17 +729,23 @@ function civicrm_api3_mailing_stats($params) { if (empty($params['job_id'])) { $params['job_id'] = NULL; } - foreach (['Delivered', 'Bounces', 'Unsubscribers', 'Unique Clicks', 'Opened'] as $detail) { + foreach (['Recipients', 'Delivered', 'Bounces', 'Unsubscribers', 'Unique Clicks', 'Opened'] as $detail) { switch ($detail) { + case 'Recipients': + $stats[$params['mailing_id']] += [ + $detail => CRM_Mailing_Event_BAO_Queue::getTotalCount($params['mailing_id'], $params['job_id']), + ]; + break; + case 'Delivered': $stats[$params['mailing_id']] += [ - $detail => CRM_Mailing_Event_BAO_Delivered::getTotalCount($params['mailing_id'], $params['job_id'], (bool) $params['is_distinct'], $params['date']), + $detail => CRM_Mailing_Event_BAO_Delivered::getTotalCount($params['mailing_id'], $params['job_id'], $params['date']), ]; break; case 'Bounces': $stats[$params['mailing_id']] += [ - $detail => CRM_Mailing_Event_BAO_Bounce::getTotalCount($params['mailing_id'], $params['job_id'], (bool) $params['is_distinct'], $params['date']), + $detail => CRM_Mailing_Event_BAO_Bounce::getTotalCount($params['mailing_id'], $params['job_id'], $params['date']), ]; break;