CRM-15417 - Add safety checks to api deprecation utils
authorColeman Watts <coleman@civicrm.org>
Fri, 10 Oct 2014 18:23:03 +0000 (14:23 -0400)
committerColeman Watts <coleman@civicrm.org>
Mon, 13 Oct 2014 22:08:55 +0000 (18:08 -0400)
api/v3/utils.php
templates/CRM/Admin/Page/APIExplorer.js

index 4ad728ec4980850a234e57a64580d76a0591267f..2f6a105deb517efbc3ffac0d75795a73f1d79788 100644 (file)
@@ -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);
+    }
   }
 }
index 39ec4f6e6a26277aa305d1e47c8aa3003c65a38a..d76826a7edc5ddb2101aa6c2fc1c7dfef018396d 100644 (file)
     }
   }
 
+  function isActionDeprecated(action) {
+    return !!(typeof actions.deprecated === 'object' && actions.deprecated[action]);
+  }
+
   function renderAction(option) {
-    if (actions.deprecated && actions.deprecated[option.id]) {
-      return '<span class="strikethrough">' + option.text + '</span>';
-    }
-    return option.text;
+    return isActionDeprecated(option.id) ? '<span class="strikethrough">' + option.text + '</span>' : option.text;
   }
 
   /**
   }
 
   function onChangeAction(action) {
-    if (actions.deprecated && actions.deprecated[action]) {
+    if (isActionDeprecated(action)) {
       CRM.alert(actions.deprecated[action], action + ' deprecated');
     }
   }