From a01fa90c31d8976c31d0dd0c11946654c44d6fdd Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Thu, 13 Mar 2014 17:53:36 +1300 Subject: [PATCH] CRM-14319 standardise action_schedule api in the course of trying to write tests for this I found the api was non-standard in ways that suggested copy & paste rather than intention. The mandatory fields said one of title, mapping_id, entity_value & entity_status - whereas it seemed to me that all are required except entity_status, also I found that one date field was required, other changes were only legacy boilerplate ---------------------------------------- * CRM-14319: not all scheduled reminders are being sent http://issues.civicrm.org/jira/browse/CRM-14319 Conflicts: api/v3/ActionSchedule.php --- api/v3/ActionSchedule.php | 37 +++++++------------------------------ 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/api/v3/ActionSchedule.php b/api/v3/ActionSchedule.php index b2b63bf48d..1236fa402c 100644 --- a/api/v3/ActionSchedule.php +++ b/api/v3/ActionSchedule.php @@ -42,11 +42,7 @@ * */ function civicrm_api3_action_schedule_get($params) { - $bao = new CRM_Core_BAO_ActionSchedule(); - _civicrm_api3_dao_set_filter($bao, $params, true, 'ActionSchedule'); - $actionSchedules = _civicrm_api3_dao_to_array($bao, $params, true,'ActionSchedule'); - - return civicrm_api3_create_success($actionSchedules, $params, 'action_schedule', 'get', $bao); + return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'action_schedule'); } @@ -60,33 +56,11 @@ function civicrm_api3_action_schedule_get($params) { * {@getfields action_schedule_create} */ function civicrm_api3_action_schedule_create($params) { - if (empty($params['id'])) { - // an update does not require any mandatory parameters - civicrm_api3_verify_one_mandatory($params, - NULL, - array( - 'title','mapping_id', 'entity_status', 'entity_value', - ) - ); - } - - $ids = array(); - if (isset($params['id']) && !CRM_Utils_Rule::integer($params['id'])) { - return civicrm_api3_create_error('Invalid value for ID'); - } - + civicrm_api3_verify_one_mandatory($params, NULL, array('start_action_date', 'absolute_date')); if (!array_key_exists('name', $params) && !array_key_exists('id', $params)) { $params['name'] = CRM_Utils_String::munge($params['title']); } - - $actionSchedule = new CRM_Core_BAO_ActionSchedule(); - $actionSchedule = CRM_Core_BAO_ActionSchedule::add($params, $ids); - - $actSchedule = array(); - - _civicrm_api3_object_to_array($actionSchedule, $actSchedule[$actionSchedule->id]); - - return civicrm_api3_create_success($actSchedule, $params, 'action_schedule', 'create', $actionSchedule); + return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'action_schedule'); } /** @@ -96,7 +70,10 @@ function civicrm_api3_action_schedule_create($params) { * @param array $params array or parameters determined by getfields */ function _civicrm_api3_action_schedule_create_spec(&$params) { - unset($params['version']); + $params['title']['api.required'] = TRUE; + $params['mapping_id']['api.required'] = TRUE; +// $params['entity_status']['api.required'] = TRUE; + $params['entity_value']['api.required'] = TRUE; } /** -- 2.25.1