4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.4 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
31 * APIv3 functions for registering/processing mailing events.
33 * @package CiviCRM_APIv3
34 * @subpackage API_Mailing
35 * @copyright CiviCRM LLC (c) 2004-2013
41 * Files required for this package
45 * Handle a create event.
47 * @param array $params
48 * @return array API Success Array
50 function civicrm_api3_mailing_create($params, $ids = array()) {
51 return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
55 * Adjust Metadata for Create action
57 * The metadata is used for setting defaults, documentation & validation
58 * @param array $params array or parameters determined by getfields
60 function _civicrm_api3_mailing_create_spec(&$params) {
61 $params['name']['api.required'] = 1;
62 $params['subject']['api.required'] = 1;
63 // should be able to default to 'user_contact_id' & have it work but it didn't work in test so
64 // making required for simplicity
65 $params['created_id']['api.required'] = 1;
66 $params['api.mailing_job.create']['api.default'] = 1;
70 * Handle a create event.
72 * @param array $params
73 * @return array API Success Array
75 function civicrm_api3_mailing_delete($params, $ids = array()) {
76 return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
83 * @param array $params
86 function civicrm_api3_mailing_get($params) {
87 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
91 * Process a bounce event by passing through to the BAOs.
93 * @param array $params
97 function civicrm_api3_mailing_event_bounce($params) {
99 $body = $params['body'];
100 unset($params['body']);
102 $params +
= CRM_Mailing_BAO_BouncePattern
::match($body);
104 if (CRM_Mailing_Event_BAO_Bounce
::create($params)) {
105 return civicrm_api3_create_success($params);
108 throw new API_Exception(ts('Queue event could not be found'),'no_queue_event
114 * Adjust Metadata for bounce_spec action
116 * The metadata is used for setting defaults, documentation & validation
117 * @param array $params array or parameters determined by getfields
119 function _civicrm_api3_mailing_event_bounce_spec(&$params) {
120 $params['job_id']['api.required'] = 1;
121 $params['event_queue_id']['api.required'] = 1;
122 $params['hash']['api.required'] = 1;
123 $params['body']['api.required'] = 1;
127 * Handle a confirm event
130 * @param array $params
134 function civicrm_api3_mailing_event_confirm($params) {
135 return civicrm_api('mailing_event_confirm', 'create', $params);
139 * Handle a reply event
141 * @param array $params
145 function civicrm_api3_mailing_event_reply($params) {
146 $job = $params['job_id'];
147 $queue = $params['event_queue_id'];
148 $hash = $params['hash'];
149 $replyto = $params['replyTo'];
150 $bodyTxt = CRM_Utils_Array
::value('bodyTxt', $params);
151 $bodyHTML = CRM_Utils_Array
::value('bodyHTML', $params);
152 $fullEmail = CRM_Utils_Array
::value('fullEmail', $params);
154 $mailing = CRM_Mailing_Event_BAO_Reply
::reply($job, $queue, $hash, $replyto);
156 if (empty($mailing)) {
157 return civicrm_api3_create_error('Queue event could not be found');
160 CRM_Mailing_Event_BAO_Reply
::send($queue, $mailing, $bodyTxt, $replyto, $bodyHTML, $fullEmail);
162 return civicrm_api3_create_success($params);
166 * Adjust Metadata for event_reply action
168 * The metadata is used for setting defaults, documentation & validation
169 * @param array $params array or parameters determined by getfields
171 function _civicrm_api3_mailing_event_reply_spec(&$params) {
172 $params['job_id']['api.required'] = 1;
173 $params['event_queue_id']['api.required'] = 1;
174 $params['hash']['api.required'] = 1;
175 $params['replyTo']['api.required'] = 0;
179 * Handle a forward event
181 * @param array $params
185 function civicrm_api3_mailing_event_forward($params) {
186 $job = $params['job_id'];
187 $queue = $params['event_queue_id'];
188 $hash = $params['hash'];
189 $email = $params['email'];
190 $fromEmail = CRM_Utils_Array
::value('fromEmail', $params);
191 $params = CRM_Utils_Array
::value('params', $params);
193 $forward = CRM_Mailing_Event_BAO_Forward
::forward($job, $queue, $hash, $email, $fromEmail, $params);
196 return civicrm_api3_create_success($params);
199 return civicrm_api3_create_error('Queue event could not be found');
203 * Adjust Metadata for event_forward action
205 * The metadata is used for setting defaults, documentation & validation
206 * @param array $params array or parameters determined by getfields
208 function _civicrm_api3_mailing_event_forward_spec(&$params) {
209 $params['job_id']['api.required'] = 1;
210 $params['event_queue_id']['api.required'] = 1;
211 $params['hash']['api.required'] = 1;
212 $params['email']['api.required'] = 1;
216 * Handle a click event
218 * @param array $params
222 function civicrm_api3_mailing_event_click($params) {
224 civicrm_api3_verify_mandatory($params,
225 'CRM_Mailing_Event_DAO_TrackableURLOpen',
226 array('event_queue_id', 'url_id'),
230 $url_id = $params['url_id'];
231 $queue = $params['event_queue_id'];
233 $url = CRM_Mailing_Event_BAO_TrackableURLOpen
::track($queue, $url_id);
236 $values['url'] = $url;
237 $values['is_error'] = 0;
239 return civicrm_api3_create_success($values);
243 * Handle an open event
245 * @param array $params
249 function civicrm_api3_mailing_event_open($params) {
251 civicrm_api3_verify_mandatory($params,
252 'CRM_Mailing_Event_DAO_Opened',
253 array('event_queue_id'),
257 $queue = $params['event_queue_id'];
258 $success = CRM_Mailing_Event_BAO_Opened
::open($queue);
261 return civicrm_api3_create_error('mailing open event failed');
264 return civicrm_api3_create_success($params);
268 * Fix the reset dates on the email record based on when a mail was last delivered
269 * We only consider mailings that were completed and finished in the last 3 to 7 days
270 * Both the min and max days can be set via the params
272 function civicrm_api3_mailing_update_email_resetdate($params) {
273 CRM_Mailing_Event_BAO_Delivered
::updateEmailResetDate(
274 CRM_Utils_Array
::value('minDays', $params, 3),
275 CRM_Utils_Array
::value('maxDays', $params, 3)
277 return civicrm_api3_create_success();