5 +--------------------------------------------------------------------+
6 | CiviCRM version 4.6 |
7 +--------------------------------------------------------------------+
8 | Copyright CiviCRM LLC (c) 2004-2014 |
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 +--------------------------------------------------------------------+
31 * new version of civicrm apis. See blog post at
32 * http://civicrm.org/node/131
35 * @package CiviCRM_APIv3
37 * @copyright CiviCRM LLC (c) 2004-2014
38 * $Id: Contact.php 30879 2010-11-22 15:45:55Z shot $
43 * Adjust metadata for "Create" action
45 * The metadata is used for setting defaults, documentation & validation
46 * @param array $params
47 * Array or parameters determined by getfields.
49 function _civicrm_api3_job_create_spec(&$params) {
50 $params['run_frequency']['api.required'] = 1;
51 $params['name']['api.required'] = 1;
52 $params['api_entity']['api.required'] = 1;
53 $params['api_action']['api.required'] = 1;
55 $params['domain_id']['api.default'] = CRM_Core_Config
::domainID();
56 $params['is_active']['api.default'] = 1;
60 * create scheduled job
62 * @param array $params
63 * Associative array of property name/value pairs to insert in new job.
66 * {@getfields Job_create}
68 * {@schema Core/Job.xml}
70 function civicrm_api3_job_create($params) {
71 return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
75 * Retrieve one or more job
76 * @param array input parameters
79 * {@getfields email_get}
82 function civicrm_api3_job_get($params) {
83 return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
89 * @param array $params
93 * {@getfields Job_delete}
96 function civicrm_api3_job_delete($params) {
97 _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__
), $params);
101 * Dumb wrapper to execute scheduled jobs. Always creates success - errors
102 * and results are handled in the job log.
104 * @param array $params
105 * (reference ) input parameters.
113 function civicrm_api3_job_execute($params) {
114 $facility = new CRM_Core_JobManager();
115 $facility->execute(FALSE);
117 // always creates success - results are handled elsewhere
118 return civicrm_api3_create_success();
122 * Adjust Metadata for Execute action
124 * @param array $params
125 * Array or parameters determined by getfields.
127 function _civicrm_api3_job_execute_spec(&$params) {
131 * Geocode group of contacts based on given params
133 * @param array $params
134 * (reference ) input parameters.
138 * {@getfields contact_geocode}
144 function civicrm_api3_job_geocode($params) {
145 $gc = new CRM_Utils_Address_BatchUpdate($params);
148 $result = $gc->run();
150 if ($result['is_error'] == 0) {
151 return civicrm_api3_create_success($result['messages']);
154 return civicrm_api3_create_error($result['messages']);
159 * First check on Code documentation
161 * @param array $params
163 function _civicrm_api3_job_geocode_spec(&$params) {
164 $params['start'] = array('title' => 'Start Date');
165 $params['end'] = array('title' => 'End Date');
166 $params['geocoding'] = array('title' => 'Geocode address?');
167 $params['parse'] = array('title' => 'Parse street address?');
168 $params['throttle'] = array('title' => 'Throttle? if enabled, geocodes at a slow rate');
172 * Send the scheduled reminders for all contacts (either for activities or events)
174 * @param array $params
175 * (reference ) input parameters.
176 * now - the time to use, in YmdHis format
177 * - makes testing a bit simpler since we can simulate past/future time
180 * true if success, else false
184 function civicrm_api3_job_send_reminder($params) {
185 //note that $params['rowCount' can be overridden by one of the preferred syntaxes ($options['limit'] = x
186 //It's not clear whether than syntax can be passed in via the UI config - but this keeps the pre 4.4.4 behaviour
187 // in that case (ie. makes it unconfigurable via the UI). Another approach would be to set a default of 0
188 // in the _spec function - but since that is a deprecated value it seems more contentious than this approach
189 $params['rowCount'] = 0;
190 $lock = new CRM_Core_Lock('civimail.job.EmailProcessor');
191 if (!$lock->isAcquired()) {
192 return civicrm_api3_create_error('Could not acquire lock, another EmailProcessor process is running');
195 $result = CRM_Core_BAO_ActionSchedule
::processQueue(CRM_Utils_Array
::value('now', $params), $params);
198 if ($result['is_error'] == 0) {
199 return civicrm_api3_create_success();
202 return civicrm_api3_create_error($result['messages']);
206 * Adjust metadata for "send_reminder" action
208 * The metadata is used for setting defaults, documentation & validation
209 * @param array $params
210 * Array or parameters determined by getfields.
212 function _civicrm_api3_job_send_reminder(&$params) {
213 //@todo this function will now take all fields in action_schedule as params
214 // as it is calling the api fn to set the filters - update getfields to reflect
215 $params['id'] = array(
216 'type' => CRM_Utils_Type
::T_INT
,
217 'title' => 'Action Schedule ID',
221 * Execute a specific report instance and send the output via email
223 * @param array $params
224 * (reference ) input parameters.
225 * sendmail - Boolean - should email be sent?, required
226 * instanceId - Integer - the report instance ID
227 * resetVal - Integer - should we reset form state (always true)?
230 * true if success, else false
234 function civicrm_api3_job_mail_report($params) {
235 $result = CRM_Report_Utils_Report
::processReport($params);
237 if ($result['is_error'] == 0) {
238 // this should be handling by throwing exceptions but can't remove until we can test that.
239 return civicrm_api3_create_success();
242 return civicrm_api3_create_error($result['messages']);
248 * This method allows to update Email Greetings, Postal Greetings and Addressee for a specific contact type.
249 * IMPORTANT: You must first create valid option value before using via admin interface.
250 * Check option lists for Email Greetings, Postal Greetings and Addressee
252 * id - Integer - greetings option group
254 * @param array $params
257 * true if success, else false
260 function civicrm_api3_job_update_greeting($params) {
262 if (isset($params['ct']) && isset($params['gt'])) {
264 $ct = explode(',', $params['ct']);
265 $gt = explode(',', $params['gt']);
266 foreach ($ct as $ctKey => $ctValue) {
267 foreach ($gt as $gtKey => $gtValue) {
268 $params['ct'] = trim($ctValue);
269 $params['gt'] = trim($gtValue);
270 $result[] = CRM_Contact_BAO_Contact_Utils
::updateGreeting($params);
275 $result = CRM_Contact_BAO_Contact_Utils
::updateGreeting($params);
278 foreach ($result as $resultKey => $resultValue) {
279 if ($resultValue['is_error'] == 0) {
280 //really we should rely on the exception mechanism here - but we need to test that before removing this line
281 return civicrm_api3_create_success();
284 return civicrm_api3_create_error($resultValue['messages']);
290 * Adjust Metadata for Get action
292 * The metadata is used for setting defaults, documentation & validation
293 * @param array $params
294 * Array or parameters determined by getfields.
296 function _civicrm_api3_job_update_greeting_spec(&$params) {
297 $params['ct'] = array(
299 'title' => 'Contact Type',
300 'type' => CRM_Utils_Type
::T_STRING
,
302 $params['gt'] = array(
304 'title' => 'Greeting Type',
305 'type' => CRM_Utils_Type
::T_STRING
,
310 * Mass update pledge statuses
312 * @param array $params
313 * (reference ) input parameters.
316 * true if success, else false
320 function civicrm_api3_job_process_pledge($params) {
321 // *** Uncomment the next line if you want automated reminders to be sent
322 // $params['send_reminders'] = true;
323 $result = CRM_Pledge_BAO_Pledge
::updatePledgeStatus($params);
325 if ($result['is_error'] == 0) {
326 // experiment: detailed execution log is a result here
327 return civicrm_api3_create_success($result['messages']);
330 return civicrm_api3_create_error($result['error_message']);
337 * @param array $params
341 function civicrm_api3_job_process_mailing($params) {
343 if (!CRM_Mailing_BAO_Mailing
::processQueue()) {
344 return civicrm_api3_create_error('Process Queue failed');
348 return civicrm_api3_create_success($values, $params, 'mailing', 'process');
355 * @param array $params
359 function civicrm_api3_job_process_sms($params) {
360 if (!CRM_Mailing_BAO_Mailing
::processQueue('sms')) {
361 return civicrm_api3_create_error('Process Queue failed');
365 return civicrm_api3_create_success($values, $params, 'mailing', 'process');
370 * Job to get mail responses from civimailing
372 * @param array $params
376 function civicrm_api3_job_fetch_bounces($params) {
377 $lock = new CRM_Core_Lock('civimail.job.EmailProcessor');
378 if (!$lock->isAcquired()) {
379 return civicrm_api3_create_error('Could not acquire lock, another EmailProcessor process is running');
381 if (!CRM_Utils_Mail_EmailProcessor
::processBounces()) {
383 return civicrm_api3_create_error('Process Bounces failed');
387 // FIXME: processBounces doesn't return true/false on success/failure
389 return civicrm_api3_create_success($values, $params, 'mailing', 'bounces');
393 * Job to get mail and create activities
395 * @param array $params
399 function civicrm_api3_job_fetch_activities($params) {
400 $lock = new CRM_Core_Lock('civimail.job.EmailProcessor');
401 if (!$lock->isAcquired()) {
402 return civicrm_api3_create_error('Could not acquire lock, another EmailProcessor process is running');
406 CRM_Utils_Mail_EmailProcessor
::processActivities();
409 return civicrm_api3_create_success($values, $params,'mailing','activities');
411 catch (Exception
$e) {
413 return civicrm_api3_create_error('Process Activities failed');
418 * Process participant statuses
420 * @param array $params
421 * (reference ) input parameters.
424 * array of properties, if error an array with an error id and error message
427 function civicrm_api3_job_process_participant($params) {
428 $result = CRM_Event_BAO_ParticipantStatusType
::process($params);
430 if (!$result['is_error']) {
431 return civicrm_api3_create_success(implode("\r\r", $result['messages']));
434 return civicrm_api3_create_error('Error while processing participant statuses');
440 * This api checks and updates the status of all membership records for a given domain using the calc_membership_status and
441 * update_contact_membership APIs.
444 * Sending renewal reminders has been migrated from this job to the Scheduled Reminders function as of 4.3.
446 * @param array $params
447 * Input parameters NOT USED.
450 * true if success, else false
453 function civicrm_api3_job_process_membership($params) {
454 $lock = new CRM_Core_Lock('civimail.job.updateMembership');
455 if (!$lock->isAcquired()) {
456 return civicrm_api3_create_error('Could not acquire lock, another Membership Processing process is running');
459 $result = CRM_Member_BAO_Membership
::updateAllMembershipStatus();
462 if ($result['is_error'] == 0) {
463 return civicrm_api3_create_success($result['messages']);
466 return civicrm_api3_create_error($result['messages']);
471 * This api checks and updates the status of all survey respondants.
473 * @param array $params
474 * (reference ) input parameters.
477 * true if success, else false
480 function civicrm_api3_job_process_respondent($params) {
481 $result = CRM_Campaign_BAO_Survey
::releaseRespondent($params);
483 if ($result['is_error'] == 0) {
484 return civicrm_api3_create_success();
487 return civicrm_api3_create_error($result['messages']);
492 * Merges given pair of duplicate contacts.
494 * @param array $params
497 * Allowed @params array keys are:
498 * {int $rgid rule group id}
499 * {int $gid group id}
500 * {string mode helps decide how to behave when there are conflicts.
501 * A 'safe' value skips the merge if there are no conflicts. Does a force merge otherwise.}
502 * {boolean auto_flip wether to let api decide which contact to retain and which to delete.}
509 function civicrm_api3_job_process_batch_merge($params) {
510 $rgid = CRM_Utils_Array
::value('rgid', $params);
511 $gid = CRM_Utils_Array
::value('gid', $params);
513 $mode = CRM_Utils_Array
::value('mode', $params, 'safe');
514 $autoFlip = CRM_Utils_Array
::value('auto_flip', $params, TRUE);
516 $result = CRM_Dedupe_Merger
::batchMerge($rgid, $gid, $mode, $autoFlip);
518 if ($result['is_error'] == 0) {
519 return civicrm_api3_create_success();
522 return civicrm_api3_create_error($result['messages']);
527 * Runs handlePaymentCron method in the specified payment processor
529 * @param array $params
532 * Expected @params array keys are:
533 * {string 'processor_name' - the name of the payment processor, eg: Sagepay}
537 function civicrm_api3_job_run_payment_cron($params) {
540 CRM_Core_Payment
::handlePaymentMethod(
551 CRM_Core_Payment
::handlePaymentMethod(
563 * This api cleans up all the old session entries and temp tables. We recommend that sites run this on an hourly basis
565 * @param array $params
566 * (reference ) - sends in various config parameters to decide what needs to be cleaned.
569 * true if success, else false
572 function civicrm_api3_job_cleanup($params) {
573 $session = CRM_Utils_Array
::value('session', $params, true );
574 $tempTable = CRM_Utils_Array
::value('tempTables', $params, true );
575 $jobLog = CRM_Utils_Array
::value('jobLog', $params, true );
576 $prevNext = CRM_Utils_Array
::value('prevNext', $params, true );
577 $dbCache = CRM_Utils_Array
::value('dbCache', $params, false);
578 $memCache = CRM_Utils_Array
::value('memCache', $params, false);
580 if ($session ||
$tempTable ||
$prevNext) {
581 CRM_Core_BAO_Cache
::cleanup($session, $tempTable, $prevNext);
585 CRM_Core_BAO_Job
::cleanup();
589 CRM_Core_Config
::clearDBCache();
593 CRM_Utils_System
::flushCache();
598 * Set expired relationships to disabled.
600 * @param array $params
604 function civicrm_api3_job_disable_expired_relationships($params) {
605 $result = CRM_Contact_BAO_Relationship
::disableExpiredRelationships();
607 return civicrm_api3_create_success();
610 return civicrm_api3_create_error('Failed to disable all expired relationships.');
615 * This api reloads all the smart groups. If the org has a large number of smart groups
616 * it is recommended that they use the limit clause to limit the number of smart groups
617 * evaluated on a per job basis. Might also help to increase the smartGroupCacheTimeout
620 * @param array $params
624 function civicrm_api3_job_group_rebuild($params) {
625 $lock = new CRM_Core_Lock('civimail.job.groupRebuild');
626 if (!$lock->isAcquired()) {
627 return civicrm_api3_create_error('Could not acquire lock, another EmailProcessor process is running');
630 $limit = CRM_Utils_Array
::value('limit', $params, 0);
632 CRM_Contact_BAO_GroupContactCache
::loadAll(null, $limit);
635 return civicrm_api3_create_success();