Merge pull request #1238 from sfe-ev/CRM-12995_amend
[civicrm-core.git] / api / api.php
index dd79c69f59365775d7a8f93fe3635df409d54f29..104d8cb9ff2f13644b8bfc1177a3ab835bb2253f 100644 (file)
@@ -205,7 +205,6 @@ function _civicrm_api_resolve($apiRequest) {
     'api/v' . $apiRequest['version'] . '/' . $camelName . '/' . $actionCamelName . '.php',
   );
   foreach ($stdFiles as $stdFile) {
-    require_once 'CRM/Utils/File.php';
     if (CRM_Utils_File::isIncludable($stdFile)) {
       require_once $stdFile;
       if (function_exists($stdFunction)) {
@@ -225,7 +224,6 @@ function _civicrm_api_resolve($apiRequest) {
     'api/v' . $apiRequest['version'] . '/Generic/' . $actionCamelName . '.php',
   );
   foreach ($genericFiles as $genericFile) {
-    require_once 'CRM/Utils/File.php';
     if (CRM_Utils_File::isIncludable($genericFile)) {
       require_once $genericFile;
       if (function_exists($genericFunction)) {
@@ -238,6 +236,22 @@ function _civicrm_api_resolve($apiRequest) {
   $cache[$cachekey] = array('function' => FALSE, 'is_generic' => FALSE);
   return $cache[$cachekey];
 }
+/**
+ * Version 3 wrapper for civicrm_api. Throws exception
+ * @param string $entity type of entities to deal with
+ * @param string $action create, get, delete or some special action name.
+ * @param array $params array to be passed to function
+ *
+ * @return array
+ *
+ */
+function civicrm_api3($entity, $action, $params){
+  $params['version'] = 3;
+  $result = civicrm_api($entity, $action, $params);
+  if($result['is_error']){
+    throw new CiviCRM_API3_Exception($result['error_message'], CRM_Utils_Array::value('error_code', $result, 'undefined'), $result);
+  }
+}
 
 /**
  * Load/require all files related to an entity.
@@ -261,7 +275,6 @@ function _civicrm_api_loadEntity($entity, $version = 3) {
   $camelName = _civicrm_api_get_camel_name($entity, $version);
 
   // Check for master entity file; to match _civicrm_api_resolve(), only load the first one
-  require_once 'CRM/Utils/File.php';
   $stdFile = 'api/v' . $version . '/' . $camelName . '.php';
   if (CRM_Utils_File::isIncludable($stdFile)) {
     require_once $stdFile;
@@ -534,10 +547,9 @@ function _civicrm_api_get_entity_name_from_camel($entity) {
  */
 function _civicrm_api_get_entity_name_from_dao($bao){
   $daoName = str_replace("BAO", "DAO", get_class($bao));
-  return _civicrm_api_get_entity_name_from_camel(CRM_Core_AllCoreTables::getFullName($daoName));
+  return _civicrm_api_get_entity_name_from_camel(CRM_Core_DAO_AllCoreTables::getBriefName($daoName));
 }
 
-
 /**
  * Sets the tsLocale and dbLocale for multi-lingual sites.
  * Some code duplication from CRM/Core/BAO/ConfigSetting.php retrieve()