Merge pull request #4806 from civicrm/4.5
[civicrm-core.git] / api / v3 / Generic / Update.php
index 1c95bcae6a14a942428067b237144afbbe51ae3a..02743a2c11d95b837e120c5487c9e5e057982927 100644 (file)
@@ -2,9 +2,9 @@
 
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  * To do this, perform a 'get' action to load the existing values, then merge in the updates
  * and call 'create' to save the revised entity.
  *
- * @param $apiRequest an array with keys:
+ * @param array $apiRequest array with keys:
  *  - entity: string
  *  - action: string
  *  - version: string
  *  - function: callback (mixed)
  *  - params: array, varies
+ *
+ * @return array|int|mixed
  */
 function civicrm_api3_generic_update($apiRequest) {
-  $errorFnName = 'civicrm_api3_create_error';
-
   //$key_id = strtolower ($apiRequest['entity'])."_id";
   $key_id = "id";
   if (!array_key_exists($key_id, $apiRequest['params'])) {
-    return $errorFnName("Mandatory parameter missing $key_id");
+    return civicrm_api3_create_error("Mandatory parameter missing $key_id");
   }
   // @fixme
   // tests show that contribution works better with create
@@ -62,14 +62,13 @@ function civicrm_api3_generic_update($apiRequest) {
     return $existing;
   }
   if ($existing['count'] > 1) {
-    return $errorFnName("More than one " . $apiRequest['entity'] . " with id " . $apiRequest['params'][$key_id]);
+    return civicrm_api3_create_error("More than one " . $apiRequest['entity'] . " with id " . $apiRequest['params'][$key_id]);
   }
   if ($existing['count'] == 0) {
-    return $errorFnName("No " . $apiRequest['entity'] . " with id " . $apiRequest['params'][$key_id]);
+    return civicrm_api3_create_error("No " . $apiRequest['entity'] . " with id " . $apiRequest['params'][$key_id]);
   }
 
   $existing = array_pop($existing['values']);
   $p = array_merge($existing, $apiRequest['params']);
   return civicrm_api($apiRequest['entity'], 'create', $p);
 }
-