// we do this before we
_civicrm_api3_swap_out_aliases($apiRequest, $fields);
if (strtolower($action) != 'getfields') {
- if (!CRM_Utils_Array::value('id', $apiRequest['params'])) {
+ if (empty($apiRequest['params']['id'])) {
$apiRequest['params'] = array_merge(_civicrm_api3_getdefaults($apiRequest, $fields), $apiRequest['params']);
}
//if 'id' is set then only 'version' will be checked but should still be checked for consistency
$result = isset($extra) ? $function($apiRequest['params'], $extra) : $function($apiRequest['params']);
}
else {
- return civicrm_api3_create_error("API (" . $apiRequest['entity'] . "," . $apiRequest['action'] . ") does not exist (join the API team and implement it!)");
+ return civicrm_api3_create_error("API (" . $apiRequest['entity'] . ", " . $apiRequest['action'] . ") does not exist (join the API team and implement it!)");
}
// For output filtering, process $apiWrappers in reverse order
return 0;
}
}
- if (CRM_Utils_Array::value('format.only_id', $apiRequest['params']) && isset($result['id'])) {
+ if (!empty($apiRequest['params']['format.only_id']) && isset($result['id'])) {
return $result['id'];
}
if (CRM_Utils_Array::value('is_error', $result, 0) == 0) {
$data["error_code"] = DB::errorMessage($error->getCode());
$data["sql"] = $error->getDebugInfo();
}
- if (CRM_Utils_Array::value('debug', $apiRequest['params'])) {
+ if (!empty($apiRequest['params']['debug'])) {
if(method_exists($e, 'getUserInfo')) {
$data['debug_info'] = $error->getUserInfo();
}
$data['tip'] = "add debug=1 to your API call to have more info about the error";
}
$err = civicrm_api3_create_error($e->getMessage(), $data, $apiRequest);
- if (CRM_Utils_Array::value('is_transactional', $apiRequest)) {
+ if (!empty($apiRequest['is_transactional'])) {
$transaction->rollback();
}
return $err;
) {
$err['trace'] = $e->getTraceAsString();
}
- if (CRM_Utils_Array::value('is_transactional', $apiRequest)) {
+ if (!empty($apiRequest['is_transactional'])) {
$transaction->rollback();
}
return $err;
}
$data = array();
$err = civicrm_api3_create_error($e->getMessage(), $data, $apiRequest, $e->getCode());
- if (CRM_Utils_Array::value('debug', $apiRequest['params'])) {
+ if (!empty($apiRequest['params']['debug'])) {
$err['trace'] = $e->getTraceAsString();
}
- if (CRM_Utils_Array::value('is_transactional', $apiRequest)) {
+ if (!empty($apiRequest['is_transactional'])) {
$transaction->rollback();
}
return $err;
* @throws CiviCRM_API3_Exception
* @return array
*/
-function civicrm_api3($entity, $action, $params) {
+function civicrm_api3($entity, $action, $params = array()) {
$params['version'] = 3;
$result = civicrm_api($entity, $action, $params);
if(is_array($result) && !empty($result['is_error'])){
if (strtolower($apiRequest['action'] == 'getfields')) {
// the main param getfields takes is 'action' - however this param is not compatible with REST
// so we accept 'api_action' as an alias of action on getfields
- if (CRM_Utils_Array::value('api_action', $apiRequest['params'])) {
+ if (!empty($apiRequest['params']['api_action'])) {
// $apiRequest['params']['action'] = $apiRequest['params']['api_action'];
// unset($apiRequest['params']['api_action']);
}
- return array('action' => array('api_aliases' => array('action')));
+ return array('action' => array('api.aliases' => array('api_action')));
}
$getFieldsParams = array('action' => $apiRequest['action']);
$entity = $apiRequest['entity'];
*/
function _civicrm_api_call_nested_api(&$params, &$result, $action, $entity, $version) {
$entity = _civicrm_api_get_entity_name_from_camel($entity);
+
+ //we don't need to worry about nested api in the getfields/getoptions actions, so just return immediately
+ if (in_array(strtolower($action), array('getfields', 'getoptions'))) {
+ return;
+ }
+
if(strtolower($action) == 'getsingle'){
// I don't understand the protocol here, but we don't want
// $result to be a recursive array
if (array_key_exists(0, $newparams)) {
$genericParams = $subParams;
// it is a numerically indexed array - ie. multiple creates
- foreach ($newparams as $entity => $entityparams) {
+ foreach ($newparams as $entityparams) {
$subParams = array_merge($genericParams, $entityparams);
_civicrm_api_replace_variables($subAPI[1], $subaction, $subParams, $result['values'][$idIndex], $separator);
$result['values'][$result['id']][$field][] = civicrm_api($subEntity, $subaction, $subParams);