* @return CRM_Contribute_BAO_Contribution
*/
public static function create(&$params, $ids = []) {
+ $contributionID = CRM_Utils_Array::value('contribution', $ids, CRM_Utils_Array::value('id', $params));
+ $action = $contributionID ? 'edit' : 'create';
+
$dateFields = [
'receive_date',
'cancel_date',
if (!empty($params['custom']) &&
is_array($params['custom'])
) {
- CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_contribution', $contribution->id);
+ CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_contribution', $contribution->id, $action);
}
$session = CRM_Core_Session::singleton();
/**
* @param array $customParams
+ * @param string $parentOperation Operation being taken on the parent entity.
+ * If we know the parent entity is doing an insert we can skip the
+ * ON DUPLICATE UPDATE - which improves performance and reduces deadlocks.
+ * - edit
+ * - create
*
* @throws Exception
*/
- public static function create($customParams) {
+ public static function create($customParams, $parentOperation = NULL) {
if (empty($customParams) ||
!is_array($customParams)
) {
$fieldValues = implode(',', array_values($set));
$query = "$sqlOP ( $fieldNames ) VALUES ( $fieldValues )";
// for multiple values we dont do on duplicate key update
- if (!$isMultiple) {
+ if (!$isMultiple && $parentOperation !== 'create') {
$query .= " ON DUPLICATE KEY UPDATE $setClause";
}
}
* @param array $params
* @param $entityTable
* @param int $entityID
+ * @param string $parentOperation Operation being taken on the parent entity.
+ * If we know the parent entity is doing an insert we can skip the
+ * ON DUPLICATE UPDATE - which improves performance and reduces deadlocks.
+ * - edit
+ * - create
*/
- public static function store($params, $entityTable, $entityID) {
+ public static function store($params, $entityTable, $entityID, $parentOperation = NULL) {
$cvParams = [];
foreach ($params as $fieldID => $param) {
foreach ($param as $index => $customValue) {
}
}
if (!empty($cvParams)) {
- self::create($cvParams);
+ self::create($cvParams, $parentOperation);
}
}