*
* @param <type> $data
* @param array $data
- * @param object $dao DAO / BAO object to be freed here
+ * @param array $dao (misnomer) apiRequest which led to this error (with keys "entity", "action", etc)
*
* @throws API_Exception
* @return array <type>
*/
function civicrm_api3_create_error($msg, $data = array(), &$dao = NULL) {
- //fix me - $dao should be param 4 & 3 should be $apiRequest
- if (is_object($dao)) {
- $dao->free();
- }
-
if (is_array($dao)) {
if ($msg == 'DB Error: constraint violation' || substr($msg, 0,9) == 'DB Error:' || $msg == 'DB Error: already exists') {
try {
// we will show sql to privelledged user only (not sure of a specific
// security hole here but seems sensible - perhaps should apply to the trace as well?
if(isset($data['sql']) && CRM_Core_Permission::check('Administer CiviCRM')) {
- $data['debug_information'] = $data['sql'];
+ $data['debug_information'] = $data['sql']; // Isn't this redundant?
+ } else {
+ unset($data['sql']);
}
if (is_array($dao) && isset($dao['params']) && is_array($dao['params']) && !empty($dao['params']['api.has_parent'])) {
$errorCode = empty($data['error_code']) ? 'chained_api_failed' : $data['error_code'];
if ($name == 'Im' || $name == 'Acl') {
$name = strtoupper($name);
}
- return CRM_Core_DAO_AllCoreTables::getFullName($name);
+ $dao = CRM_Core_DAO_AllCoreTables::getFullName($name);
+ if ($dao || !$name) {
+ return $dao;
+ }
+
+ // Really weird apis can declare their own DAO name. Not sure if this is a good idea...
+ include_once "api/v3/$name.php";
+ $daoFn = "_civicrm_api3_" . _civicrm_api_get_entity_name_from_camel($name) . "_DAO";
+ if (function_exists($daoFn)) {
+ return $daoFn();
+ }
+
+ return NULL;
}
/**