From 736eec431993cb8057e86eee6fc1a4853201ac6a Mon Sep 17 00:00:00 2001 From: Eileen Date: Tue, 19 Nov 2013 14:19:31 +1300 Subject: [PATCH] CRM-13493 api don't fatal on duplicate invoice id ---------------------------------------- ---------------------------------------- * CRM-13493: Nasty fatal if you try to create a contribution via the api with an invoice id matching an existing http://issues.civicrm.org/jira/browse/CRM-13493 --- api/v3/utils.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/api/v3/utils.php b/api/v3/utils.php index 36e84b9080..ba36384aee 100644 --- a/api/v3/utils.php +++ b/api/v3/utils.php @@ -996,6 +996,16 @@ function _civicrm_api3_basic_create($bao_name, &$params, $entity = NULL) { if (is_null($bao)) { return civicrm_api3_create_error('Entity not created (' . $fct_name . ')'); } + elseif (is_a($bao, 'CRM_Core_Error')) { + //some wierd circular thing means the error takes itself as an argument + $msg = $bao->getMessages($bao); + // the api deals with entities on a one-by-one basis. However, the contribution bao pushes entities + // onto the error object - presumably because the contribution import is not handling multiple errors correctly + // so we need to reset the error object here to avoid getting concatenated errors + //@todo - the mulitple error handling should be moved out of the contribution object to the import / multiple entity processes + CRM_Core_Error::singleton()->reset(); + throw new API_Exception($msg); + } else { $values = array(); _civicrm_api3_object_to_array($bao, $values[$bao->id]); -- 2.25.1