Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
1f4ea726 | 6 | | Copyright CiviCRM LLC (c) 2004-2017 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
244bbdd8 | 29 | * This api is used for working with scheduled "cron" jobs. |
6a488035 TO |
30 | * |
31 | * @package CiviCRM_APIv3 | |
6a488035 TO |
32 | */ |
33 | ||
6a488035 | 34 | /** |
c1a920f1 EM |
35 | * Adjust metadata for "Create" action. |
36 | * | |
37 | * The metadata is used for setting defaults, documentation & validation. | |
6a488035 | 38 | * |
cf470720 | 39 | * @param array $params |
b081365f | 40 | * Array of parameters determined by getfields. |
6a488035 TO |
41 | */ |
42 | function _civicrm_api3_job_create_spec(&$params) { | |
43 | $params['run_frequency']['api.required'] = 1; | |
44 | $params['name']['api.required'] = 1; | |
45 | $params['api_entity']['api.required'] = 1; | |
46 | $params['api_action']['api.required'] = 1; | |
47 | ||
48 | $params['domain_id']['api.default'] = CRM_Core_Config::domainID(); | |
49 | $params['is_active']['api.default'] = 1; | |
50 | } | |
51 | ||
52 | /** | |
c1a920f1 | 53 | * Create scheduled job. |
6a488035 | 54 | * |
cf470720 TO |
55 | * @param array $params |
56 | * Associative array of property name/value pairs to insert in new job. | |
6a488035 | 57 | * |
72b3a70c | 58 | * @return array |
6a488035 TO |
59 | */ |
60 | function civicrm_api3_job_create($params) { | |
f39bacdf | 61 | return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); |
6a488035 TO |
62 | } |
63 | ||
64 | /** | |
211e2fca | 65 | * Retrieve one or more job. |
971d41b1 CW |
66 | * |
67 | * @param array $params | |
68 | * input parameters | |
971d41b1 | 69 | * |
211e2fca | 70 | * @return array |
6a488035 TO |
71 | */ |
72 | function civicrm_api3_job_get($params) { | |
73 | return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params); | |
74 | } | |
75 | ||
76 | /** | |
211e2fca | 77 | * Delete a job. |
6a488035 | 78 | * |
9657ccf2 | 79 | * @param array $params |
6a488035 TO |
80 | */ |
81 | function civicrm_api3_job_delete($params) { | |
61ef23bd | 82 | _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params); |
6a488035 TO |
83 | } |
84 | ||
85 | /** | |
211e2fca EM |
86 | * Dumb wrapper to execute scheduled jobs. |
87 | * | |
88 | * Always creates success - errors and results are handled in the job log. | |
6a488035 | 89 | * |
cf470720 | 90 | * @param array $params |
971d41b1 | 91 | * input parameters (unused). |
6a488035 | 92 | * |
a6c01b45 | 93 | * @return array |
72b3a70c | 94 | * API Result Array |
6a488035 | 95 | */ |
608e6658 | 96 | function civicrm_api3_job_execute($params) { |
608e6658 | 97 | |
6a488035 TO |
98 | $facility = new CRM_Core_JobManager(); |
99 | $facility->execute(FALSE); | |
100 | ||
61fe4988 | 101 | // Always creates success - results are handled elsewhere. |
244bbdd8 | 102 | return civicrm_api3_create_success(1, $params, 'Job'); |
6a488035 TO |
103 | } |
104 | ||
105 | /** | |
211e2fca | 106 | * Adjust Metadata for Execute action. |
6a488035 | 107 | * |
cf470720 | 108 | * @param array $params |
b081365f | 109 | * Array of parameters determined by getfields. |
6a488035 TO |
110 | */ |
111 | function _civicrm_api3_job_execute_spec(&$params) { | |
112 | } | |
113 | ||
114 | /** | |
211e2fca | 115 | * Geocode group of contacts based on given params. |
6a488035 | 116 | * |
cf470720 | 117 | * @param array $params |
971d41b1 | 118 | * input parameters. |
6a488035 | 119 | * |
a6c01b45 | 120 | * @return array |
72b3a70c | 121 | * API Result Array |
6a488035 TO |
122 | */ |
123 | function civicrm_api3_job_geocode($params) { | |
6a488035 TO |
124 | $gc = new CRM_Utils_Address_BatchUpdate($params); |
125 | ||
6a488035 TO |
126 | $result = $gc->run(); |
127 | ||
128 | if ($result['is_error'] == 0) { | |
129 | return civicrm_api3_create_success($result['messages']); | |
130 | } | |
131 | else { | |
132 | return civicrm_api3_create_error($result['messages']); | |
133 | } | |
134 | } | |
9657ccf2 | 135 | |
6a488035 | 136 | /** |
c1a920f1 | 137 | * First check on Code documentation. |
9657ccf2 EM |
138 | * |
139 | * @param array $params | |
6a488035 TO |
140 | */ |
141 | function _civicrm_api3_job_geocode_spec(&$params) { | |
d142432b | 142 | $params['start'] = array( |
8ebf8a02 DG |
143 | 'title' => 'Starting Contact ID', |
144 | 'type' => CRM_Utils_Type::T_INT, | |
d142432b EM |
145 | ); |
146 | $params['end'] = array( | |
8ebf8a02 DG |
147 | 'title' => 'Ending Contact ID', |
148 | 'type' => CRM_Utils_Type::T_INT, | |
d142432b EM |
149 | ); |
150 | $params['geocoding'] = array( | |
151 | 'title' => 'Geocode address?', | |
152 | 'type' => CRM_Utils_Type::T_BOOLEAN, | |
153 | ); | |
154 | $params['parse'] = array( | |
155 | 'title' => 'Parse street address?', | |
156 | 'type' => CRM_Utils_Type::T_BOOLEAN, | |
157 | ); | |
b2ed8e73 CW |
158 | $params['throttle'] = array( |
159 | 'title' => 'Throttle?', | |
d142432b EM |
160 | 'description' => 'If enabled, geo-codes at a slow rate', |
161 | 'type' => CRM_Utils_Type::T_BOOLEAN, | |
b2ed8e73 | 162 | ); |
6a488035 TO |
163 | } |
164 | ||
165 | /** | |
c1a920f1 | 166 | * Send the scheduled reminders for all contacts (either for activities or events). |
6a488035 | 167 | * |
cf470720 TO |
168 | * @param array $params |
169 | * (reference ) input parameters. | |
6a488035 TO |
170 | * now - the time to use, in YmdHis format |
171 | * - makes testing a bit simpler since we can simulate past/future time | |
172 | * | |
c23f45d3 | 173 | * @return array |
6a488035 TO |
174 | */ |
175 | function civicrm_api3_job_send_reminder($params) { | |
e27a3472 EM |
176 | //note that $params['rowCount' can be overridden by one of the preferred syntaxes ($options['limit'] = x |
177 | //It's not clear whether than syntax can be passed in via the UI config - but this keeps the pre 4.4.4 behaviour | |
c23f45d3 | 178 | // in that case (ie. makes it non-configurable via the UI). Another approach would be to set a default of 0 |
e27a3472 EM |
179 | // in the _spec function - but since that is a deprecated value it seems more contentious than this approach |
180 | $params['rowCount'] = 0; | |
83617886 | 181 | $lock = Civi::lockManager()->acquire('worker.core.ActionSchedule'); |
39fefc30 | 182 | if (!$lock->isAcquired()) { |
33c5988b | 183 | return civicrm_api3_create_error('Could not acquire lock, another ActionSchedule process is running'); |
39fefc30 KJ |
184 | } |
185 | ||
73f3e293 | 186 | $result = CRM_Core_BAO_ActionSchedule::processQueue(CRM_Utils_Array::value('now', $params), $params); |
39fefc30 | 187 | $lock->release(); |
6a488035 TO |
188 | |
189 | if ($result['is_error'] == 0) { | |
190 | return civicrm_api3_create_success(); | |
191 | } | |
192 | else { | |
193 | return civicrm_api3_create_error($result['messages']); | |
194 | } | |
195 | } | |
73f3e293 | 196 | /** |
c1a920f1 EM |
197 | * Adjust metadata for "send_reminder" action. |
198 | * | |
199 | * The metadata is used for setting defaults, documentation & validation. | |
73f3e293 | 200 | * |
cf470720 | 201 | * @param array $params |
b081365f | 202 | * Array of parameters determined by getfields. |
73f3e293 E |
203 | */ |
204 | function _civicrm_api3_job_send_reminder(&$params) { | |
205 | //@todo this function will now take all fields in action_schedule as params | |
206 | // as it is calling the api fn to set the filters - update getfields to reflect | |
207 | $params['id'] = array( | |
208 | 'type' => CRM_Utils_Type::T_INT, | |
21dfd5f5 | 209 | 'title' => 'Action Schedule ID', |
73f3e293 E |
210 | ); |
211 | } | |
6a488035 | 212 | /** |
c1a920f1 | 213 | * Execute a specific report instance and send the output via email. |
6a488035 | 214 | * |
cf470720 TO |
215 | * @param array $params |
216 | * (reference ) input parameters. | |
6a488035 TO |
217 | * sendmail - Boolean - should email be sent?, required |
218 | * instanceId - Integer - the report instance ID | |
219 | * resetVal - Integer - should we reset form state (always true)? | |
220 | * | |
c23f45d3 | 221 | * @return array |
6a488035 TO |
222 | */ |
223 | function civicrm_api3_job_mail_report($params) { | |
6a488035 TO |
224 | $result = CRM_Report_Utils_Report::processReport($params); |
225 | ||
226 | if ($result['is_error'] == 0) { | |
227 | // this should be handling by throwing exceptions but can't remove until we can test that. | |
228 | return civicrm_api3_create_success(); | |
229 | } | |
230 | else { | |
231 | return civicrm_api3_create_error($result['messages']); | |
232 | } | |
233 | } | |
234 | ||
235 | /** | |
6a488035 | 236 | * This method allows to update Email Greetings, Postal Greetings and Addressee for a specific contact type. |
211e2fca | 237 | * |
6a488035 TO |
238 | * IMPORTANT: You must first create valid option value before using via admin interface. |
239 | * Check option lists for Email Greetings, Postal Greetings and Addressee | |
240 | * | |
211e2fca | 241 | * @todo - is this here by mistake or should it be added to _spec function :id - Integer - greetings option group. |
6a488035 | 242 | * |
9657ccf2 | 243 | * @param array $params |
77b97be7 | 244 | * |
3f83a242 | 245 | * @return array |
6a488035 TO |
246 | */ |
247 | function civicrm_api3_job_update_greeting($params) { | |
6a488035 | 248 | if (isset($params['ct']) && isset($params['gt'])) { |
6a488035 TO |
249 | $ct = explode(',', $params['ct']); |
250 | $gt = explode(',', $params['gt']); | |
251 | foreach ($ct as $ctKey => $ctValue) { | |
252 | foreach ($gt as $gtKey => $gtValue) { | |
253 | $params['ct'] = trim($ctValue); | |
254 | $params['gt'] = trim($gtValue); | |
3f83a242 | 255 | CRM_Contact_BAO_Contact_Utils::updateGreeting($params); |
6a488035 TO |
256 | } |
257 | } | |
258 | } | |
259 | else { | |
3f83a242 | 260 | CRM_Contact_BAO_Contact_Utils::updateGreeting($params); |
6a488035 | 261 | } |
3f83a242 | 262 | return civicrm_api3_create_success(); |
6a488035 TO |
263 | } |
264 | ||
265 | /** | |
211e2fca | 266 | * Adjust Metadata for Get action. |
72b3a70c | 267 | * |
c1a920f1 EM |
268 | * The metadata is used for setting defaults, documentation & validation. |
269 | * | |
72b3a70c | 270 | * @param array $params |
b081365f | 271 | * Array of parameters determined by getfields. |
72b3a70c | 272 | */ |
6a488035 TO |
273 | function _civicrm_api3_job_update_greeting_spec(&$params) { |
274 | $params['ct'] = array( | |
275 | 'api.required' => 1, | |
276 | 'title' => 'Contact Type', | |
277 | 'type' => CRM_Utils_Type::T_STRING, | |
278 | ); | |
279 | $params['gt'] = array( | |
971d41b1 CW |
280 | 'api.required' => 1, |
281 | 'title' => 'Greeting Type', | |
282 | 'type' => CRM_Utils_Type::T_STRING, | |
6a488035 TO |
283 | ); |
284 | } | |
285 | ||
286 | /** | |
c1a920f1 | 287 | * Mass update pledge statuses. |
6a488035 | 288 | * |
cf470720 | 289 | * @param array $params |
c1a920f1 | 290 | * |
c23f45d3 | 291 | * @return array |
6a488035 TO |
292 | */ |
293 | function civicrm_api3_job_process_pledge($params) { | |
294 | // *** Uncomment the next line if you want automated reminders to be sent | |
295 | // $params['send_reminders'] = true; | |
296 | $result = CRM_Pledge_BAO_Pledge::updatePledgeStatus($params); | |
297 | ||
298 | if ($result['is_error'] == 0) { | |
299 | // experiment: detailed execution log is a result here | |
300 | return civicrm_api3_create_success($result['messages']); | |
301 | } | |
302 | else { | |
303 | return civicrm_api3_create_error($result['error_message']); | |
304 | } | |
305 | } | |
306 | ||
307 | /** | |
c1a920f1 | 308 | * Process mail queue. |
6a488035 TO |
309 | * |
310 | * @param array $params | |
311 | * | |
312 | * @return array | |
313 | */ | |
314 | function civicrm_api3_job_process_mailing($params) { | |
ec782609 | 315 | $mailsProcessedOrig = CRM_Mailing_BAO_MailingJob::$mailsProcessed; |
6a488035 TO |
316 | |
317 | if (!CRM_Mailing_BAO_Mailing::processQueue()) { | |
318 | return civicrm_api3_create_error('Process Queue failed'); | |
319 | } | |
320 | else { | |
ec782609 TO |
321 | $values = array( |
322 | 'processed' => CRM_Mailing_BAO_MailingJob::$mailsProcessed - $mailsProcessedOrig, | |
323 | ); | |
244bbdd8 | 324 | return civicrm_api3_create_success($values, $params, 'Job', 'process_mailing'); |
6a488035 TO |
325 | } |
326 | } | |
327 | ||
328 | /** | |
cd5823ae | 329 | * Process sms queue. |
6a488035 TO |
330 | * |
331 | * @param array $params | |
332 | * | |
333 | * @return array | |
334 | */ | |
335 | function civicrm_api3_job_process_sms($params) { | |
ec782609 TO |
336 | $mailsProcessedOrig = CRM_Mailing_BAO_MailingJob::$mailsProcessed; |
337 | ||
6a488035 TO |
338 | if (!CRM_Mailing_BAO_Mailing::processQueue('sms')) { |
339 | return civicrm_api3_create_error('Process Queue failed'); | |
340 | } | |
341 | else { | |
ec782609 TO |
342 | $values = array( |
343 | 'processed' => CRM_Mailing_BAO_MailingJob::$mailsProcessed - $mailsProcessedOrig, | |
344 | ); | |
244bbdd8 | 345 | return civicrm_api3_create_success($values, $params, 'Job', 'process_sms'); |
6a488035 TO |
346 | } |
347 | } | |
39fefc30 | 348 | |
6a488035 | 349 | /** |
c1a920f1 | 350 | * Job to get mail responses from civiMailing. |
9657ccf2 EM |
351 | * |
352 | * @param array $params | |
353 | * | |
354 | * @return array | |
6a488035 TO |
355 | */ |
356 | function civicrm_api3_job_fetch_bounces($params) { | |
83617886 | 357 | $lock = Civi::lockManager()->acquire('worker.mailing.EmailProcessor'); |
6a488035 TO |
358 | if (!$lock->isAcquired()) { |
359 | return civicrm_api3_create_error('Could not acquire lock, another EmailProcessor process is running'); | |
360 | } | |
3ff238ae | 361 | CRM_Utils_Mail_EmailProcessor::processBounces($params['is_create_activities']); |
6a488035 | 362 | $lock->release(); |
39fefc30 | 363 | |
3ff238ae | 364 | return civicrm_api3_create_success(1, $params, 'Job', 'fetch_bounces'); |
365 | } | |
366 | ||
367 | /** | |
368 | * Metadata for bounce function. | |
369 | * | |
370 | * @param array $params | |
371 | */ | |
372 | function _civicrm_api3_job_fetch_bounces_spec(&$params) { | |
373 | $params['is_create_activities'] = array( | |
374 | 'api.default' => 0, | |
375 | 'type' => CRM_Utils_Type::T_BOOLEAN, | |
376 | 'title' => ts('Create activities for replies?'), | |
377 | ); | |
6a488035 TO |
378 | } |
379 | ||
380 | /** | |
35823763 | 381 | * Job to get mail and create activities. |
9657ccf2 EM |
382 | * |
383 | * @param array $params | |
384 | * | |
385 | * @return array | |
6a488035 TO |
386 | */ |
387 | function civicrm_api3_job_fetch_activities($params) { | |
83617886 | 388 | $lock = Civi::lockManager()->acquire('worker.mailing.EmailProcessor'); |
6a488035 TO |
389 | if (!$lock->isAcquired()) { |
390 | return civicrm_api3_create_error('Could not acquire lock, another EmailProcessor process is running'); | |
391 | } | |
39fefc30 KJ |
392 | |
393 | try { | |
394 | CRM_Utils_Mail_EmailProcessor::processActivities(); | |
481a74f4 | 395 | $values = array(); |
6a488035 | 396 | $lock->release(); |
244bbdd8 | 397 | return civicrm_api3_create_success($values, $params, 'Job', 'fetch_activities'); |
0db6c3e1 TO |
398 | } |
399 | catch (Exception $e) { | |
6a488035 | 400 | $lock->release(); |
e7b952ac | 401 | return civicrm_api3_create_error($e->getMessage()); |
6a488035 TO |
402 | } |
403 | } | |
404 | ||
405 | /** | |
35823763 | 406 | * Process participant statuses. |
6a488035 | 407 | * |
cf470720 | 408 | * @param array $params |
35823763 | 409 | * Input parameters. |
6a488035 | 410 | * |
a6c01b45 | 411 | * @return array |
72b3a70c | 412 | * array of properties, if error an array with an error id and error message |
6a488035 TO |
413 | */ |
414 | function civicrm_api3_job_process_participant($params) { | |
6a488035 TO |
415 | $result = CRM_Event_BAO_ParticipantStatusType::process($params); |
416 | ||
417 | if (!$result['is_error']) { | |
418 | return civicrm_api3_create_success(implode("\r\r", $result['messages'])); | |
419 | } | |
420 | else { | |
421 | return civicrm_api3_create_error('Error while processing participant statuses'); | |
422 | } | |
423 | } | |
424 | ||
425 | ||
426 | /** | |
61fe4988 EM |
427 | * This api checks and updates the status of all membership records for a given domain. |
428 | * | |
429 | * The function uses the calc_membership_status and update_contact_membership APIs. | |
6a488035 TO |
430 | * |
431 | * IMPORTANT: | |
432 | * Sending renewal reminders has been migrated from this job to the Scheduled Reminders function as of 4.3. | |
433 | * | |
cf470720 TO |
434 | * @param array $params |
435 | * Input parameters NOT USED. | |
6a488035 | 436 | * |
971d41b1 | 437 | * @return bool |
72b3a70c | 438 | * true if success, else false |
6a488035 | 439 | */ |
608e6658 | 440 | function civicrm_api3_job_process_membership($params) { |
83617886 | 441 | $lock = Civi::lockManager()->acquire('worker.member.UpdateMembership'); |
39fefc30 | 442 | if (!$lock->isAcquired()) { |
017877e1 | 443 | return civicrm_api3_create_error('Could not acquire lock, another Membership Processing process is running'); |
39fefc30 KJ |
444 | } |
445 | ||
6a488035 | 446 | $result = CRM_Member_BAO_Membership::updateAllMembershipStatus(); |
39fefc30 | 447 | $lock->release(); |
6a488035 TO |
448 | |
449 | if ($result['is_error'] == 0) { | |
244bbdd8 | 450 | return civicrm_api3_create_success($result['messages'], $params, 'Job', 'process_membership'); |
6a488035 TO |
451 | } |
452 | else { | |
453 | return civicrm_api3_create_error($result['messages']); | |
454 | } | |
455 | } | |
456 | ||
457 | /** | |
3f83a242 | 458 | * This api checks and updates the status of all survey respondents. |
6a488035 | 459 | * |
cf470720 TO |
460 | * @param array $params |
461 | * (reference ) input parameters. | |
6a488035 | 462 | * |
971d41b1 | 463 | * @return bool |
72b3a70c | 464 | * true if success, else false |
6a488035 TO |
465 | */ |
466 | function civicrm_api3_job_process_respondent($params) { | |
6a488035 TO |
467 | $result = CRM_Campaign_BAO_Survey::releaseRespondent($params); |
468 | ||
469 | if ($result['is_error'] == 0) { | |
470 | return civicrm_api3_create_success(); | |
471 | } | |
472 | else { | |
473 | return civicrm_api3_create_error($result['messages']); | |
474 | } | |
475 | } | |
476 | ||
477 | /** | |
478 | * Merges given pair of duplicate contacts. | |
479 | * | |
cf470720 TO |
480 | * @param array $params |
481 | * Input parameters. | |
6a488035 | 482 | * |
a6c01b45 | 483 | * @return array |
72b3a70c | 484 | * API Result Array |
76ddbc8e | 485 | * @throws \CiviCRM_API3_Exception |
6a488035 TO |
486 | */ |
487 | function civicrm_api3_job_process_batch_merge($params) { | |
6c866f0c | 488 | $rule_group_id = CRM_Utils_Array::value('rule_group_id', $params); |
76ddbc8e | 489 | if (!$rule_group_id) { |
490 | $rule_group_id = civicrm_api3('RuleGroup', 'getvalue', array( | |
491 | 'contact_type' => 'Individual', | |
492 | 'used' => 'Unsupervised', | |
493 | 'return' => 'id', | |
6c866f0c | 494 | 'options' => array('limit' => 1), |
76ddbc8e | 495 | )); |
496 | } | |
6a488035 | 497 | $gid = CRM_Utils_Array::value('gid', $params); |
6a488035 | 498 | $mode = CRM_Utils_Array::value('mode', $params, 'safe'); |
6a488035 | 499 | |
d13a105a | 500 | $result = CRM_Dedupe_Merger::batchMerge($rule_group_id, $gid, $mode, 1, 2, CRM_Utils_Array::value('criteria', $params, array()), CRM_Utils_Array::value('check_permissions', $params)); |
6a488035 | 501 | |
76ddbc8e | 502 | return civicrm_api3_create_success($result, $params); |
6a488035 TO |
503 | } |
504 | ||
3f83a242 | 505 | /** |
61fe4988 EM |
506 | * Metadata for batch merge function. |
507 | * | |
3f83a242 EM |
508 | * @param $params |
509 | */ | |
510 | function _civicrm_api3_job_process_batch_merge_spec(&$params) { | |
6c866f0c | 511 | $params['rule_group_id'] = array( |
76ddbc8e | 512 | 'title' => 'Dedupe rule group id, defaults to Contact Unsupervised rule', |
3f83a242 | 513 | 'type' => CRM_Utils_Type::T_INT, |
6c866f0c | 514 | 'api.aliases' => array('rgid'), |
3f83a242 EM |
515 | ); |
516 | $params['gid'] = array( | |
517 | 'title' => 'group id', | |
518 | 'type' => CRM_Utils_Type::T_INT, | |
519 | ); | |
520 | $params['mode'] = array( | |
521 | 'title' => 'Mode', | |
608e6658 | 522 | 'description' => 'helps decide how to behave when there are conflicts. A \'safe\' value skips the merge if there are no conflicts. Does a force merge otherwise.', |
3f83a242 EM |
523 | 'type' => CRM_Utils_Type::T_STRING, |
524 | ); | |
525 | $params['auto_flip'] = array( | |
526 | 'title' => 'Auto Flip', | |
527 | 'description' => 'let the api decide which contact to retain and which to delete?', | |
528 | 'type' => CRM_Utils_Type::T_BOOLEAN, | |
529 | ); | |
530 | } | |
531 | ||
6a488035 | 532 | /** |
61fe4988 | 533 | * Runs handlePaymentCron method in the specified payment processor. |
6a488035 | 534 | * |
cf470720 TO |
535 | * @param array $params |
536 | * Input parameters. | |
6a488035 | 537 | * |
61fe4988 EM |
538 | * Expected @params array keys are: INCORRECTLY DOCUMENTED AND SHOULD BE IN THE _spec function |
539 | * for retrieval via getfields. | |
6a488035 | 540 | * {string 'processor_name' - the name of the payment processor, eg: Sagepay} |
6a488035 TO |
541 | */ |
542 | function civicrm_api3_job_run_payment_cron($params) { | |
543 | ||
6a488035 TO |
544 | // live mode |
545 | CRM_Core_Payment::handlePaymentMethod( | |
546 | 'PaymentCron', | |
547 | array_merge( | |
548 | $params, | |
549 | array( | |
550 | 'caller' => 'api', | |
551 | ) | |
552 | ) | |
553 | ); | |
554 | ||
555 | // test mode | |
556 | CRM_Core_Payment::handlePaymentMethod( | |
557 | 'PaymentCron', | |
558 | array_merge( | |
559 | $params, | |
560 | array( | |
561 | 'mode' => 'test', | |
562 | ) | |
563 | ) | |
564 | ); | |
565 | } | |
566 | ||
567 | /** | |
61fe4988 EM |
568 | * This api cleans up all the old session entries and temp tables. |
569 | * | |
570 | * We recommend that sites run this on an hourly basis. | |
6a488035 | 571 | * |
cf470720 | 572 | * @param array $params |
971d41b1 | 573 | * Sends in various config parameters to decide what needs to be cleaned. |
6a488035 | 574 | */ |
481a74f4 | 575 | function civicrm_api3_job_cleanup($params) { |
971d41b1 CW |
576 | $session = CRM_Utils_Array::value('session', $params, TRUE); |
577 | $tempTable = CRM_Utils_Array::value('tempTables', $params, TRUE); | |
578 | $jobLog = CRM_Utils_Array::value('jobLog', $params, TRUE); | |
579 | $prevNext = CRM_Utils_Array::value('prevNext', $params, TRUE); | |
580 | $dbCache = CRM_Utils_Array::value('dbCache', $params, FALSE); | |
581 | $memCache = CRM_Utils_Array::value('memCache', $params, FALSE); | |
9db8dfb7 | 582 | $tplCache = CRM_Utils_Array::value('tplCache', $params, FALSE); |
583 | $wordRplc = CRM_Utils_Array::value('wordRplc', $params, FALSE); | |
6a488035 | 584 | |
481a74f4 TO |
585 | if ($session || $tempTable || $prevNext) { |
586 | CRM_Core_BAO_Cache::cleanup($session, $tempTable, $prevNext); | |
6a488035 TO |
587 | } |
588 | ||
481a74f4 TO |
589 | if ($jobLog) { |
590 | CRM_Core_BAO_Job::cleanup(); | |
6a488035 TO |
591 | } |
592 | ||
9db8dfb7 | 593 | if ($tplCache) { |
4dd6dceb | 594 | $config = CRM_Core_Config::singleton(); |
595 | $config->cleanup(1, FALSE); | |
596 | } | |
597 | ||
481a74f4 TO |
598 | if ($dbCache) { |
599 | CRM_Core_Config::clearDBCache(); | |
6a488035 TO |
600 | } |
601 | ||
481a74f4 TO |
602 | if ($memCache) { |
603 | CRM_Utils_System::flushCache(); | |
6a488035 | 604 | } |
4dd6dceb | 605 | |
9db8dfb7 | 606 | if ($wordRplc) { |
4dd6dceb | 607 | CRM_Core_BAO_WordReplacement::rebuild(); |
608 | } | |
6a488035 TO |
609 | } |
610 | ||
611 | /** | |
612 | * Set expired relationships to disabled. | |
61fe4988 EM |
613 | * |
614 | * @param array $params | |
615 | * | |
9657ccf2 | 616 | * @return array |
3f83a242 | 617 | * @throws \API_Exception |
6a488035 | 618 | */ |
608e6658 | 619 | function civicrm_api3_job_disable_expired_relationships($params) { |
6a488035 | 620 | $result = CRM_Contact_BAO_Relationship::disableExpiredRelationships(); |
3f83a242 EM |
621 | if (!$result) { |
622 | throw new API_Exception('Failed to disable all expired relationships.'); | |
6a488035 | 623 | } |
244bbdd8 | 624 | return civicrm_api3_create_success(1, $params, 'Job', 'disable_expired_relationships'); |
6a488035 TO |
625 | } |
626 | ||
627 | /** | |
61fe4988 EM |
628 | * This api reloads all the smart groups. |
629 | * | |
630 | * If the org has a large number of smart groups it is recommended that they use the limit clause | |
631 | * to limit the number of smart groups evaluated on a per job basis. | |
632 | * | |
633 | * Might also help to increase the smartGroupCacheTimeout and use the cache. | |
9657ccf2 EM |
634 | * |
635 | * @param array $params | |
61fe4988 | 636 | * |
9657ccf2 | 637 | * @return array |
3f83a242 | 638 | * @throws \API_Exception |
6a488035 | 639 | */ |
9657ccf2 | 640 | function civicrm_api3_job_group_rebuild($params) { |
83617886 | 641 | $lock = Civi::lockManager()->acquire('worker.core.GroupRebuild'); |
39fefc30 | 642 | if (!$lock->isAcquired()) { |
0feefbc7 | 643 | throw new API_Exception('Could not acquire lock, another GroupRebuild process is running'); |
39fefc30 KJ |
644 | } |
645 | ||
481a74f4 | 646 | $limit = CRM_Utils_Array::value('limit', $params, 0); |
6a488035 | 647 | |
971d41b1 | 648 | CRM_Contact_BAO_GroupContactCache::loadAll(NULL, $limit); |
39fefc30 KJ |
649 | $lock->release(); |
650 | ||
f9e16e9a | 651 | return civicrm_api3_create_success(); |
6a488035 | 652 | } |
999128a9 | 653 | |
a357281f | 654 | /** |
655 | * Flush smart groups caches. | |
656 | * | |
657 | * This job purges aged smart group cache data (based on the timeout value). Sites can decide whether they want this | |
658 | * job and / or the group cache rebuild job to run. In some cases performance is better when old caches are cleared out | |
659 | * prior to any attempt to rebuild them. Also, many sites are very happy to have caches built on demand, provided the | |
660 | * user is not having to wait for deadlocks to clear when invalidating them. | |
661 | * | |
662 | * @param array $params | |
663 | * | |
664 | * @return array | |
665 | * @throws \API_Exception | |
666 | */ | |
667 | function civicrm_api3_job_group_cache_flush($params) { | |
2b68a50c | 668 | CRM_Contact_BAO_GroupContactCache::deterministicCacheFlush(); |
a357281f | 669 | return civicrm_api3_create_success(); |
670 | } | |
671 | ||
999128a9 CW |
672 | /** |
673 | * Check for CiviCRM software updates. | |
674 | * | |
675 | * Anonymous site statistics are sent back to civicrm.org during this check. | |
676 | */ | |
677 | function civicrm_api3_job_version_check() { | |
678 | $vc = new CRM_Utils_VersionCheck(); | |
679 | $vc->fetch(); | |
e9e60a8c | 680 | return civicrm_api3_create_success(); |
999128a9 | 681 | } |