From 15cbe793b3248e01265023419de7b6d816da10df Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Fri, 10 Oct 2014 14:23:03 -0400 Subject: [PATCH] CRM-15417 - Add safety checks to api deprecation utils --- api/v3/utils.php | 19 +++++++++++-------- templates/CRM/Admin/Page/APIExplorer.js | 11 ++++++----- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/api/v3/utils.php b/api/v3/utils.php index 4ad728ec49..2f6a105deb 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -1974,15 +1974,18 @@ function _civicrm_api3_api_resolve_alias($entity, $fieldName) { /** * @param string $entity * @param array $result + * @return string|array|null */ function _civicrm_api3_deprecation_check($entity, $result = array()) { - $apiFile = 'api/v3/' . _civicrm_api_get_camel_name($entity) . '.php'; - if (CRM_Utils_File::isIncludable($apiFile)) { - require_once $apiFile; - } - $entity = _civicrm_api_get_entity_name_from_camel($entity); - $fnName = "_civicrm_api3_{$entity}_deprecation"; - if (function_exists($fnName)) { - return $fnName($result); + if ($entity) { + $apiFile = 'api/v3/' . _civicrm_api_get_camel_name($entity) . '.php'; + if (CRM_Utils_File::isIncludable($apiFile)) { + require_once $apiFile; + } + $entity = _civicrm_api_get_entity_name_from_camel($entity); + $fnName = "_civicrm_api3_{$entity}_deprecation"; + if (function_exists($fnName)) { + return $fnName($result); + } } } diff --git a/templates/CRM/Admin/Page/APIExplorer.js b/templates/CRM/Admin/Page/APIExplorer.js index 39ec4f6e6a..d76826a7ed 100644 --- a/templates/CRM/Admin/Page/APIExplorer.js +++ b/templates/CRM/Admin/Page/APIExplorer.js @@ -142,11 +142,12 @@ } } + function isActionDeprecated(action) { + return !!(typeof actions.deprecated === 'object' && actions.deprecated[action]); + } + function renderAction(option) { - if (actions.deprecated && actions.deprecated[option.id]) { - return '' + option.text + ''; - } - return option.text; + return isActionDeprecated(option.id) ? '' + option.text + '' : option.text; } /** @@ -167,7 +168,7 @@ } function onChangeAction(action) { - if (actions.deprecated && actions.deprecated[action]) { + if (isActionDeprecated(action)) { CRM.alert(actions.deprecated[action], action + ' deprecated'); } } -- 2.25.1