3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
30 * APIv3 functions for registering/processing mailing events.
32 * @package CiviCRM_APIv3
36 * Handle a create event.
38 * @param array $params
42 * @throws \API_Exception
43 * @throws \Civi\API\Exception\UnauthorizedException
45 function civicrm_api3_mailing_create($params) {
46 if (isset($params['template_options']) && is_array($params['template_options'])) {
47 $params['template_options'] = ($params['template_options'] === array()) ?
'{}' : json_encode($params['template_options']);
49 if (CRM_Mailing_Info
::workflowEnabled()) {
50 // Note: 'schedule mailings' and 'approve mailings' can update certain fields, but can't create.
52 if (empty($params['id'])) {
53 if (!CRM_Core_Permission
::check('access CiviMail') && !CRM_Core_Permission
::check('create mailings')) {
54 throw new \Civi\API\Exception\
UnauthorizedException("Cannot create new mailing. Required permission: 'access CiviMail' or 'create mailings'");
58 $safeParams = array();
59 $fieldPerms = CRM_Mailing_BAO_Mailing
::getWorkflowFieldPerms();
60 foreach (array_keys($params) as $field) {
61 if (CRM_Core_Permission
::check($fieldPerms[$field])) {
62 $safeParams[$field] = $params[$field];
67 $safeParams = $params;
69 $timestampCheck = TRUE;
70 if (!empty($params['id']) && !empty($params['modified_date'])) {
71 $timestampCheck = _civicrm_api3_compare_timestamps($safeParams['modified_date'], $safeParams['id'], 'Mailing');
72 unset($safeParams['modified_date']);
74 if (!$timestampCheck) {
75 throw new API_Exception("Mailing has not been saved, Content maybe out of date, please refresh the page and try again");
78 // 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.
79 $safeParams['_evil_bao_validator_'] = \CRM_Utils_Constant
::value('CIVICRM_FLEXMAILER_HACK_SENDABLE', 'CRM_Mailing_BAO_Mailing::checkSendable');
80 $result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__
), $safeParams);
81 return _civicrm_api3_mailing_get_formatResult($result);
85 * Get tokens for one or more entity type
87 * Output will be formatted either as a flat list,
88 * or pass sequential=1 to retrieve as a hierarchy formatted for select2.
90 * @param array $params
91 * Should contain an array of entities to retrieve tokens for.
94 * @throws \API_Exception
96 function civicrm_api3_mailing_gettokens($params) {
98 foreach ((array) $params['entity'] as $ent) {
99 $func = lcfirst($ent) . 'Tokens';
100 if (!method_exists('CRM_Core_SelectValues', $func)) {
101 throw new API_Exception('Unknown token entity: ' . $ent);
103 $tokens = array_merge(CRM_Core_SelectValues
::$func(), $tokens);
105 if (!empty($params['sequential'])) {
106 $tokens = CRM_Utils_Token
::formatTokensForDisplay($tokens);
108 return civicrm_api3_create_success($tokens, $params, 'Mailing', 'gettokens');
112 * Adjust Metadata for Create action.
114 * The metadata is used for setting defaults, documentation & validation.
116 * @param array $params
117 * Array of parameters determined by getfields.
119 function _civicrm_api3_mailing_gettokens_spec(&$params) {
120 $params['entity'] = array(
121 'api.default' => array('contact'),
125 'options' => array(),
127 // Fetch a list of token functions and format to look like entity names
128 foreach (get_class_methods('CRM_Core_SelectValues') as $func) {
129 if (strpos($func, 'Tokens')) {
130 $ent = ucfirst(str_replace('Tokens', '', $func));
131 $params['entity']['options'][$ent] = $ent;
137 * Adjust Metadata for Create action.
139 * The metadata is used for setting defaults, documentation & validation.
141 * @param array $params
142 * Array of parameters determined by getfields.
144 function _civicrm_api3_mailing_create_spec(&$params) {
145 $params['created_id']['api.default'] = 'user_contact_id';
147 $params['override_verp']['api.default'] = !CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::MAILING_PREFERENCES_NAME
, 'track_civimail_replies');
148 $params['visibility']['api.default'] = 'Public Pages';
149 $params['dedupe_email']['api.default'] = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::MAILING_PREFERENCES_NAME
, 'dedupe_email_default');
151 $params['forward_replies']['api.default'] = FALSE;
152 $params['auto_responder']['api.default'] = FALSE;
153 $params['open_tracking']['api.default'] = TRUE;
154 $params['url_tracking']['api.default'] = TRUE;
156 $params['header_id']['api.default'] = CRM_Mailing_PseudoConstant
::defaultComponent('Header', '');
157 $params['footer_id']['api.default'] = CRM_Mailing_PseudoConstant
::defaultComponent('Footer', '');
158 $params['optout_id']['api.default'] = CRM_Mailing_PseudoConstant
::defaultComponent('OptOut', '');
159 $params['reply_id']['api.default'] = CRM_Mailing_PseudoConstant
::defaultComponent('Reply', '');
160 $params['resubscribe_id']['api.default'] = CRM_Mailing_PseudoConstant
::defaultComponent('Resubscribe', '');
161 $params['unsubscribe_id']['api.default'] = CRM_Mailing_PseudoConstant
::defaultComponent('Unsubscribe', '');
162 $params['mailing_type']['api.default'] = 'standalone';
163 $defaultAddress = CRM_Core_BAO_Domain
::getNameAndEmail(TRUE, TRUE);
164 foreach ($defaultAddress as $value) {
165 if (preg_match('/"(.*)" <(.*)>/', $value, $match)) {
166 $params['from_email']['api.default'] = $match[2];
167 $params['from_name']['api.default'] = $match[1];
173 * Adjust metadata for clone spec action.
177 function _civicrm_api3_mailing_clone_spec(&$spec) {
178 $mailingFields = CRM_Mailing_DAO_Mailing
::fields();
179 $spec['id'] = $mailingFields['id'];
180 $spec['id']['api.required'] = 1;
186 * @param array $params
189 * @throws \CiviCRM_API3_Exception
191 function civicrm_api3_mailing_clone($params) {
201 'approval_status_id',
208 $get = civicrm_api3('Mailing', 'getsingle', array('id' => $params['id']));
210 $newParams = array();
211 $newParams['debug'] = CRM_Utils_Array
::value('debug', $params);
212 $newParams['groups']['include'] = array();
213 $newParams['groups']['exclude'] = array();
214 $newParams['mailings']['include'] = array();
215 $newParams['mailings']['exclude'] = array();
216 foreach ($get as $field => $value) {
217 if (!in_array($field, $BLACKLIST)) {
218 $newParams[$field] = $value;
222 $dao = new CRM_Mailing_DAO_MailingGroup();
223 $dao->mailing_id
= $params['id'];
225 while ($dao->fetch()) {
226 // CRM-11431; account for multi-lingual
227 $entity = (substr($dao->entity_table
, 0, 15) == 'civicrm_mailing') ?
'mailings' : 'groups';
228 $newParams[$entity][strtolower($dao->group_type
)][] = $dao->entity_id
;
231 return civicrm_api3('Mailing', 'create', $newParams);
235 * Handle a delete event.
237 * @param array $params
242 function civicrm_api3_mailing_delete($params) {
243 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
247 * Handle a get event.
249 * @param array $params
253 function civicrm_api3_mailing_get($params) {
254 $result = _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
255 return _civicrm_api3_mailing_get_formatResult($result);
261 * @param array $result
264 * @throws \CRM_Core_Exception
266 function _civicrm_api3_mailing_get_formatResult($result) {
267 if (isset($result['values']) && is_array($result['values'])) {
268 foreach ($result['values'] as $key => $caseType) {
269 if (isset($result['values'][$key]['template_options']) && is_string($result['values'][$key]['template_options'])) {
270 $result['values'][$key]['template_options'] = json_decode($result['values'][$key]['template_options'], TRUE);
278 * Adjust metadata for mailing submit api function.
282 function _civicrm_api3_mailing_submit_spec(&$spec) {
283 $mailingFields = CRM_Mailing_DAO_Mailing
::fields();
284 $spec['id'] = $mailingFields['id'];
285 $spec['scheduled_date'] = $mailingFields['scheduled_date'];
286 $spec['approval_date'] = $mailingFields['approval_date'];
287 $spec['approval_status_id'] = $mailingFields['approval_status_id'];
288 $spec['approval_note'] = $mailingFields['approval_note'];
289 // _skip_evil_bao_auto_recipients_: bool
295 * @param array $params
298 * @throws API_Exception
300 function civicrm_api3_mailing_submit($params) {
301 civicrm_api3_verify_mandatory($params, 'CRM_Mailing_DAO_Mailing', array('id'));
303 if (!isset($params['scheduled_date']) && !isset($updateParams['approval_date'])) {
304 throw new API_Exception("Missing parameter scheduled_date and/or approval_date");
306 if (!is_numeric(CRM_Core_Session
::getLoggedInContactID())) {
307 throw new API_Exception("Failed to determine current user");
310 $updateParams = array();
311 $updateParams['id'] = $params['id'];
313 // Note: we'll pass along scheduling/approval fields, but they may get ignored
314 // if we don't have permission.
315 if (isset($params['scheduled_date'])) {
316 $updateParams['scheduled_date'] = $params['scheduled_date'];
317 $updateParams['scheduled_id'] = CRM_Core_Session
::getLoggedInContactID();
319 if (isset($params['approval_date'])) {
320 $updateParams['approval_date'] = $params['approval_date'];
321 $updateParams['approver_id'] = CRM_Core_Session
::getLoggedInContactID();
322 $updateParams['approval_status_id'] = CRM_Utils_Array
::value('approval_status_id', $updateParams, CRM_Core_OptionGroup
::getDefaultValue('mail_approval_status'));
324 if (isset($params['approval_note'])) {
325 $updateParams['approval_note'] = $params['approval_note'];
327 if (isset($params['_skip_evil_bao_auto_recipients_'])) {
328 $updateParams['_skip_evil_bao_auto_recipients_'] = $params['_skip_evil_bao_auto_recipients_'];
331 $updateParams['options']['reload'] = 1;
332 return civicrm_api3('Mailing', 'create', $updateParams);
336 * Process a bounce event by passing through to the BAOs.
338 * @param array $params
340 * @throws API_Exception
343 function civicrm_api3_mailing_event_bounce($params) {
344 $body = $params['body'];
345 unset($params['body']);
347 $params +
= CRM_Mailing_BAO_BouncePattern
::match($body);
349 if (CRM_Mailing_Event_BAO_Bounce
::create($params)) {
350 return civicrm_api3_create_success($params);
353 throw new API_Exception(ts('Queue event could not be found'), 'no_queue_event');
358 * Adjust Metadata for bounce_spec action.
360 * The metadata is used for setting defaults, documentation & validation.
362 * @param array $params
363 * Array of parameters determined by getfields.
365 function _civicrm_api3_mailing_event_bounce_spec(&$params) {
366 $params['job_id']['api.required'] = 1;
367 $params['job_id']['title'] = 'Job ID';
368 $params['event_queue_id']['api.required'] = 1;
369 $params['event_queue_id']['title'] = 'Event Queue ID';
370 $params['hash']['api.required'] = 1;
371 $params['hash']['title'] = 'Hash';
372 $params['body']['api.required'] = 1;
373 $params['body']['title'] = 'Body';
377 * Handle a confirm event.
381 * @param array $params
385 function civicrm_api3_mailing_event_confirm($params) {
386 return civicrm_api('MailingEventConfirm', 'create', $params);
390 * Declare deprecated functions.
392 * @deprecated api notice
394 * Array of deprecated actions
396 function _civicrm_api3_mailing_deprecation() {
397 return array('event_confirm' => 'Mailing api "event_confirm" action is deprecated. Use the mailing_event_confirm api instead.');
401 * Handle a reply event.
403 * @param array $params
407 function civicrm_api3_mailing_event_reply($params) {
408 $job = $params['job_id'];
409 $queue = $params['event_queue_id'];
410 $hash = $params['hash'];
411 $replyto = $params['replyTo'];
412 $bodyTxt = CRM_Utils_Array
::value('bodyTxt', $params);
413 $bodyHTML = CRM_Utils_Array
::value('bodyHTML', $params);
414 $fullEmail = CRM_Utils_Array
::value('fullEmail', $params);
416 $mailing = CRM_Mailing_Event_BAO_Reply
::reply($job, $queue, $hash, $replyto);
418 if (empty($mailing)) {
419 return civicrm_api3_create_error('Queue event could not be found');
422 CRM_Mailing_Event_BAO_Reply
::send($queue, $mailing, $bodyTxt, $replyto, $bodyHTML, $fullEmail);
424 return civicrm_api3_create_success($params);
428 * Adjust Metadata for event_reply action.
430 * The metadata is used for setting defaults, documentation & validation.
432 * @param array $params
433 * Array of parameters determined by getfields.
435 function _civicrm_api3_mailing_event_reply_spec(&$params) {
436 $params['job_id']['api.required'] = 1;
437 $params['job_id']['title'] = 'Job ID';
438 $params['event_queue_id']['api.required'] = 1;
439 $params['event_queue_id']['title'] = 'Event Queue ID';
440 $params['hash']['api.required'] = 1;
441 $params['hash']['title'] = 'Hash';
442 $params['replyTo']['api.required'] = 0;
443 $params['replyTo']['title'] = 'Reply To';//doesn't really explain adequately
447 * Handle a forward event.
449 * @param array $params
453 function civicrm_api3_mailing_event_forward($params) {
454 $job = $params['job_id'];
455 $queue = $params['event_queue_id'];
456 $hash = $params['hash'];
457 $email = $params['email'];
458 $fromEmail = CRM_Utils_Array
::value('fromEmail', $params);
459 $params = CRM_Utils_Array
::value('params', $params);
461 $forward = CRM_Mailing_Event_BAO_Forward
::forward($job, $queue, $hash, $email, $fromEmail, $params);
464 return civicrm_api3_create_success($params);
467 return civicrm_api3_create_error('Queue event could not be found');
471 * Adjust Metadata for event_forward action.
473 * The metadata is used for setting defaults, documentation & validation.
475 * @param array $params
476 * Array of parameters determined by getfields.
478 function _civicrm_api3_mailing_event_forward_spec(&$params) {
479 $params['job_id']['api.required'] = 1;
480 $params['job_id']['title'] = 'Job ID';
481 $params['event_queue_id']['api.required'] = 1;
482 $params['event_queue_id']['title'] = 'Event Queue ID';
483 $params['hash']['api.required'] = 1;
484 $params['hash']['title'] = 'Hash';
485 $params['email']['api.required'] = 1;
486 $params['email']['title'] = 'Forwarded to Email';
490 * Handle a click event.
492 * @param array $params
496 function civicrm_api3_mailing_event_click($params) {
497 civicrm_api3_verify_mandatory($params,
498 'CRM_Mailing_Event_DAO_TrackableURLOpen',
499 array('event_queue_id', 'url_id'),
503 $url_id = $params['url_id'];
504 $queue = $params['event_queue_id'];
506 $url = CRM_Mailing_Event_BAO_TrackableURLOpen
::track($queue, $url_id);
509 $values['url'] = $url;
510 $values['is_error'] = 0;
512 return civicrm_api3_create_success($values);
516 * Handle an open event.
518 * @param array $params
522 function civicrm_api3_mailing_event_open($params) {
524 civicrm_api3_verify_mandatory($params,
525 'CRM_Mailing_Event_DAO_Opened',
526 array('event_queue_id'),
530 $queue = $params['event_queue_id'];
531 $success = CRM_Mailing_Event_BAO_Opened
::open($queue);
534 return civicrm_api3_create_error('mailing open event failed');
537 return civicrm_api3_create_success($params);
543 * @param array $params
544 * Array per getfields metadata.
547 * @throws \API_Exception
549 function civicrm_api3_mailing_preview($params) {
550 civicrm_api3_verify_mandatory($params,
551 'CRM_Mailing_DAO_Mailing',
557 if (!empty($params['from_email'])) {
558 $fromEmail = $params['from_email'];
561 $session = CRM_Core_Session
::singleton();
562 $mailing = new CRM_Mailing_BAO_Mailing();
563 $mailing->id
= $params['id'];
564 $mailing->find(TRUE);
566 CRM_Mailing_BAO_Mailing
::tokenReplace($mailing);
568 // get and format attachments
569 $attachments = CRM_Core_BAO_File
::getEntityFile('civicrm_mailing', $mailing->id
);
571 $returnProperties = $mailing->getReturnProperties();
572 $contactID = CRM_Utils_Array
::value('contact_id', $params);
574 $contactID = $session->get('userID');
576 $mailingParams = array('contact_id' => $contactID);
578 $details = CRM_Utils_Token
::getTokenDetails($mailingParams, $returnProperties, TRUE, TRUE, NULL, $mailing->getFlattenedTokens());
580 $mime = $mailing->compose(NULL, NULL, NULL, $session->get('userID'), $fromEmail, $fromEmail,
581 TRUE, $details[0][$contactID], $attachments
584 return civicrm_api3_create_success(array(
585 'id' => $params['id'],
586 'contact_id' => $contactID,
587 'subject' => $mime->_headers
['Subject'],
588 'body_html' => $mime->getHTMLBody(),
589 'body_text' => $mime->getTXTBody(),
594 * Adjust metadata for send test function.
598 function _civicrm_api3_mailing_send_test_spec(&$spec) {
599 $spec['test_group']['title'] = 'Test Group ID';
600 $spec['test_email']['title'] = 'Test Email Address';
606 * @param array $params
609 * @throws \API_Exception
610 * @throws \CiviCRM_API3_Exception
612 function civicrm_api3_mailing_send_test($params) {
613 if (!array_key_exists('test_group', $params) && !array_key_exists('test_email', $params)) {
614 throw new API_Exception("Mandatory key(s) missing from params array: test_group and/or test_email field are required");
616 civicrm_api3_verify_mandatory($params,
617 'CRM_Mailing_DAO_MailingJob',
622 $testEmailParams = _civicrm_api3_generic_replace_base_params($params);
623 $testEmailParams['is_test'] = 1;
624 $testEmailParams['status'] = 'Scheduled';
625 $testEmailParams['scheduled_date'] = CRM_Utils_Date
::processDate(date('Y-m-d'), date('H:i:s'));
626 $job = civicrm_api3('MailingJob', 'create', $testEmailParams);
627 $testEmailParams['job_id'] = $job['id'];
628 $testEmailParams['emails'] = array_key_exists('test_email', $testEmailParams) ?
explode(',', $testEmailParams['test_email']) : NULL;
629 if (!empty($params['test_email'])) {
630 $query = CRM_Utils_SQL_Select
::from('civicrm_email e')
631 ->select(array('e.id', 'e.contact_id', 'e.email'))
632 ->join('c', 'INNER JOIN civicrm_contact c ON e.contact_id = c.id')
633 ->where('e.email IN (@emails)', array('@emails' => $testEmailParams['emails']))
634 ->where('e.on_hold = 0')
635 ->where('c.is_opt_out = 0')
636 ->where('c.do_not_email = 0')
637 ->where('c.is_deceased = 0')
638 ->where('c.is_deleted = 0')
640 ->orderBy(array('e.is_bulkmail DESC', 'e.is_primary DESC'))
642 $dao = CRM_Core_DAO
::executeQuery($query);
643 $emailDetail = array();
644 // fetch contact_id and email id for all existing emails
645 while ($dao->fetch()) {
646 $emailDetail[$dao->email
] = array(
647 'contact_id' => $dao->contact_id
,
648 'email_id' => $dao->id
,
652 foreach ($testEmailParams['emails'] as $key => $email) {
653 $email = trim($email);
654 $contactId = $emailId = NULL;
655 if (array_key_exists($email, $emailDetail)) {
656 $emailId = $emailDetail[$email]['email_id'];
657 $contactId = $emailDetail[$email]['contact_id'];
660 //create new contact.
661 $contact = civicrm_api3('Contact', 'create',
663 'contact_type' => 'Individual',
665 'api.Email.get' => array('return' => 'id'),
668 $contactId = $contact['id'];
669 $emailId = $contact['values'][$contactId]['api.Email.get']['id'];
671 civicrm_api3('MailingEventQueue', 'create',
673 'job_id' => $job['id'],
674 'email_id' => $emailId,
675 'contact_id' => $contactId,
682 $config = CRM_Core_Config
::singleton();
683 $mailerJobSize = Civi
::settings()->get('mailerJobSize');
684 while (!$isComplete) {
685 // Q: In CRM_Mailing_BAO_Mailing::processQueue(), the three runJobs*()
686 // functions are all called. Why does Mailing.send_test only call one?
687 // CRM_Mailing_BAO_MailingJob::runJobs_pre($mailerJobSize, NULL);
688 $isComplete = CRM_Mailing_BAO_MailingJob
::runJobs($testEmailParams);
689 // CRM_Mailing_BAO_MailingJob::runJobs_post(NULL);
692 //return delivered mail info
693 $mailDelivered = CRM_Mailing_Event_BAO_Delivered
::getRows($params['mailing_id'], $job['id'], TRUE, NULL, NULL, NULL, TRUE);
695 return civicrm_api3_create_success($mailDelivered);
699 * Adjust Metadata for send_mail action.
701 * The metadata is used for setting defaults, documentation & validation.
703 * @param array $params
704 * Array of parameters determined by getfields.
706 function _civicrm_api3_mailing_stats_spec(&$params) {
707 $params['date']['api.default'] = 'now';
708 $params['date']['title'] = 'Date';
709 $params['is_distinct']['api.default'] = FALSE;
710 $params['is_distinct']['title'] = 'Is Distinct';
714 * Function which needs to be explained.
716 * @param array $params
719 * @throws \API_Exception
721 function civicrm_api3_mailing_stats($params) {
722 civicrm_api3_verify_mandatory($params,
723 'CRM_Mailing_DAO_MailingJob',
728 if ($params['date'] == 'now') {
729 $params['date'] = date('YmdHis');
732 $params['date'] = CRM_Utils_Date
::processDate($params['date'] . ' ' . $params['date_time']);
735 $stats[$params['mailing_id']] = array();
736 if (empty($params['job_id'])) {
737 $params['job_id'] = NULL;
739 foreach (array('Delivered', 'Bounces', 'Unsubscribers', 'Unique Clicks', 'Opened') as $detail) {
742 $stats[$params['mailing_id']] +
= array(
743 $detail => CRM_Mailing_Event_BAO_Delivered
::getTotalCount($params['mailing_id'], $params['job_id'], (bool) $params['is_distinct'], $params['date']),
748 $stats[$params['mailing_id']] +
= array(
749 $detail => CRM_Mailing_Event_BAO_Bounce
::getTotalCount($params['mailing_id'], $params['job_id'], (bool) $params['is_distinct'], $params['date']),
753 case 'Unsubscribers':
754 $stats[$params['mailing_id']] +
= array(
755 $detail => CRM_Mailing_Event_BAO_Unsubscribe
::getTotalCount($params['mailing_id'], $params['job_id'], (bool) $params['is_distinct'], NULL, $params['date']),
759 case 'Unique Clicks':
760 $stats[$params['mailing_id']] +
= array(
761 $detail => CRM_Mailing_Event_BAO_TrackableURLOpen
::getTotalCount($params['mailing_id'], $params['job_id'], (bool) $params['is_distinct'], NULL, $params['date']),
766 $stats[$params['mailing_id']] +
= array(
767 $detail => CRM_Mailing_Event_BAO_Opened
::getTotalCount($params['mailing_id'], $params['job_id'], (bool) $params['is_distinct'], $params['date']),
772 return civicrm_api3_create_success($stats);
776 * Fix the reset dates on the email record based on when a mail was last delivered.
778 * We only consider mailings that were completed and finished in the last 3 to 7 days
779 * Both the min and max days can be set via the params
781 * @param array $params
785 function civicrm_api3_mailing_update_email_resetdate($params) {
786 CRM_Mailing_Event_BAO_Delivered
::updateEmailResetDate(
787 CRM_Utils_Array
::value('minDays', $params, 3),
788 CRM_Utils_Array
::value('maxDays', $params, 3)
790 return civicrm_api3_create_success();