3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
29 * @package CiviCRM_APIv3
33 * Update function is basically a hack.
35 * We want to remove it but must resolve issues in
36 * http://issues.civicrm.org/jira/browse/CRM-12144
38 * It is not recommended & if update doesn't work & fix does then update will not be fixed
40 * To do this, perform a 'get' action to load the existing values, then merge in the updates
41 * and call 'create' to save the revised entity.
45 * @param array $apiRequest
50 * - function: callback (mixed)
51 * - params: array, varies
53 * @return array|int|mixed
55 function civicrm_api3_generic_update($apiRequest) {
56 //$key_id = strtolower ($apiRequest['entity'])."_id";
58 if (!array_key_exists($key_id, $apiRequest['params'])) {
59 return civicrm_api3_create_error("Mandatory parameter missing $key_id");
62 // tests show that contribution works better with create
63 // this is horrible but to make it work we'll just handle it separately
64 if (strtolower($apiRequest['entity']) == 'contribution') {
65 return civicrm_api($apiRequest['entity'], 'create', $apiRequest['params']);
67 $seek = array($key_id => $apiRequest['params'][$key_id], 'version' => $apiRequest['version']);
68 $existing = civicrm_api($apiRequest['entity'], 'get', $seek);
69 if ($existing['is_error']) {
72 if ($existing['count'] > 1) {
73 return civicrm_api3_create_error("More than one " . $apiRequest['entity'] . " with id " . $apiRequest['params'][$key_id]);
75 if ($existing['count'] == 0) {
76 return civicrm_api3_create_error("No " . $apiRequest['entity'] . " with id " . $apiRequest['params'][$key_id]);
79 $existing = array_pop($existing['values']);
80 $p = array_merge($existing, $apiRequest['params']);
81 return civicrm_api($apiRequest['entity'], 'create', $p);