5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.3 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2013 |
9 +--------------------------------------------------------------------+
10 | This file is a part of CiviCRM. |
12 | CiviCRM is free software; you can copy, modify, and distribute it |
13 | under the terms of the GNU Affero General Public License |
14 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
16 | CiviCRM is distributed in the hope that it will be useful, but |
17 | WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
19 | See the GNU Affero General Public License for more details. |
21 | You should have received a copy of the GNU Affero General Public |
22 | License and the CiviCRM Licensing Exception along |
23 | with this program; if not, contact CiviCRM LLC |
24 | at info[AT]civicrm[DOT]org. If you have questions about the |
25 | GNU Affero General Public License or the licensing of CiviCRM, |
26 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
27 +--------------------------------------------------------------------+
32 * APIv3 functions for registering/processing mailing events.
34 * @package CiviCRM_APIv3
35 * @subpackage API_Mailing
36 * @copyright CiviCRM LLC (c) 2004-2013
42 * Files required for this package
46 * Handle a create event.
48 * @param array $params
49 * @return array API Success Array
51 function civicrm_api3_mailing_create($params, $ids = array()) {
52 return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
56 * Adjust Metadata for Create action
58 * The metadata is used for setting defaults, documentation & validation
59 * @param array $params array or parameters determined by getfields
61 function _civicrm_api3_mailing_create_spec(&$params) {
62 $params['name']['api.required'] = 1;
63 $params['subject']['api.required'] = 1;
64 // should be able to default to 'user_contact_id' & have it work but it didn't work in test so
65 // making required for simplicity
66 $params['created_id']['api.required'] = 1;
67 $params['api.mailing_job.create']['api.default'] = 1;
73 * @param array $params
76 function civicrm_api3_mailing_get($params, $ids = array()) {
77 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
81 * Process a bounce event by passing through to the BAOs.
83 * @param array $params
87 function civicrm_api3_mailing_event_bounce($params) {
89 $body = $params['body'];
90 unset($params['body']);
92 $params +
= CRM_Mailing_BAO_BouncePattern
::match($body);
94 if (CRM_Mailing_Event_BAO_Bounce
::create($params)) {
95 return civicrm_api3_create_success($params);
98 throw new API_Exception(ts('Queue event could not be found'),'no_queue_event
104 * Adjust Metadata for bounce_spec action
106 * The metadata is used for setting defaults, documentation & validation
107 * @param array $params array or parameters determined by getfields
109 function _civicrm_api3_mailing_event_bounce_spec(&$params) {
110 $params['job_id']['api.required'] = 1;
111 $params['event_queue_id']['api.required'] = 1;
112 $params['hash']['api.required'] = 1;
113 $params['body']['api.required'] = 1;
117 * Handle a confirm event
120 * @param array $params
124 function civicrm_api3_mailing_event_confirm($params) {
125 return civicrm_api('mailing_event_confirm', 'create', $params);
129 * Handle a reply event
131 * @param array $params
135 function civicrm_api3_mailing_event_reply($params) {
136 $job = $params['job_id'];
137 $queue = $params['event_queue_id'];
138 $hash = $params['hash'];
139 $replyto = $params['replyTo'];
140 $bodyTxt = CRM_Utils_Array
::value('bodyTxt', $params);
141 $bodyHTML = CRM_Utils_Array
::value('bodyHTML', $params);
142 $fullEmail = CRM_Utils_Array
::value('fullEmail', $params);
144 $mailing = CRM_Mailing_Event_BAO_Reply
::reply($job, $queue, $hash, $replyto);
146 if (empty($mailing)) {
147 return civicrm_api3_create_error('Queue event could not be found');
150 CRM_Mailing_Event_BAO_Reply
::send($queue, $mailing, $bodyTxt, $replyto, $bodyHTML, $fullEmail);
152 return civicrm_api3_create_success($params);
156 * Adjust Metadata for event_reply action
158 * The metadata is used for setting defaults, documentation & validation
159 * @param array $params array or parameters determined by getfields
161 function _civicrm_api3_mailing_event_reply_spec(&$params) {
162 $params['job_id']['api.required'] = 1;
163 $params['event_queue_id']['api.required'] = 1;
164 $params['hash']['api.required'] = 1;
165 $params['replyTo']['api.required'] = 0;
169 * Handle a forward event
171 * @param array $params
175 function civicrm_api3_mailing_event_forward($params) {
176 $job = $params['job_id'];
177 $queue = $params['event_queue_id'];
178 $hash = $params['hash'];
179 $email = $params['email'];
180 $fromEmail = CRM_Utils_Array
::value('fromEmail', $params);
181 $params = CRM_Utils_Array
::value('params', $params);
183 $forward = CRM_Mailing_Event_BAO_Forward
::forward($job, $queue, $hash, $email, $fromEmail, $params);
186 return civicrm_api3_create_success($params);
189 return civicrm_api3_create_error('Queue event could not be found');
193 * Adjust Metadata for event_forward action
195 * The metadata is used for setting defaults, documentation & validation
196 * @param array $params array or parameters determined by getfields
198 function _civicrm_api3_mailing_event_forward_spec(&$params) {
199 $params['job_id']['api.required'] = 1;
200 $params['event_queue_id']['api.required'] = 1;
201 $params['hash']['api.required'] = 1;
202 $params['email']['api.required'] = 1;
206 * Handle a click event
208 * @param array $params
212 function civicrm_api3_mailing_event_click($params) {
214 civicrm_api3_verify_mandatory($params,
215 'CRM_Mailing_Event_DAO_TrackableURLOpen',
216 array('event_queue_id', 'url_id'),
220 $url_id = $params['url_id'];
221 $queue = $params['event_queue_id'];
223 $url = CRM_Mailing_Event_BAO_TrackableURLOpen
::track($queue, $url_id);
226 $values['url'] = $url;
227 $values['is_error'] = 0;
229 return civicrm_api3_create_success($values);
233 * Handle an open event
235 * @param array $params
239 function civicrm_api3_mailing_event_open($params) {
241 civicrm_api3_verify_mandatory($params,
242 'CRM_Mailing_Event_DAO_Opened',
243 array('event_queue_id'),
247 $queue = $params['event_queue_id'];
248 $success = CRM_Mailing_Event_BAO_Opened
::open($queue);
251 return civicrm_api3_create_error('mailing open event failed');
254 return civicrm_api3_create_success($params);
258 * Fix the reset dates on the email record based on when a mail was last delivered
259 * We only consider mailings that were completed and finished in the last 3 to 7 days
260 * Both the min and max days can be set via the params
262 function civicrm_api3_mailing_update_email_resetdate($params) {
263 CRM_Mailing_Event_BAO_Delivered
::updateEmailResetDate(
264 CRM_Utils_Array
::value('minDays', $params, 3),
265 CRM_Utils_Array
::value('maxDays', $params, 3)
267 return civicrm_api3_create_success();