X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FEvent%2FBAO%2FParticipantPayment.php;h=555df5dd25a36a523cef8d4e452da1f88bd0add0;hb=95ca1e4e775ce88e3f371abe8390a3526ba537e7;hp=db00d49166a5b13401faa3a827a917eb5ebeeee8;hpb=06b69b1899b6304f7832f6d4d2f5af4a0acfde8c;p=civicrm-core.git diff --git a/CRM/Event/BAO/ParticipantPayment.php b/CRM/Event/BAO/ParticipantPayment.php index db00d49166..555df5dd25 100644 --- a/CRM/Event/BAO/ParticipantPayment.php +++ b/CRM/Event/BAO/ParticipantPayment.php @@ -44,7 +44,7 @@ class CRM_Event_BAO_ParticipantPayment extends CRM_Event_DAO_ParticipantPayment * @return object the partcipant payment record * @static */ - static function &create(&$params, &$ids) { + static function create(&$params, &$ids) { if (isset($ids['id'])) { CRM_Utils_Hook::pre('edit', 'ParticipantPayment', $ids['id'], $params); } @@ -69,6 +69,16 @@ class CRM_Event_BAO_ParticipantPayment extends CRM_Event_DAO_ParticipantPayment CRM_Utils_Hook::post('create', 'ParticipantPayment', NULL, $participantPayment); } + //generally if people are creating participant_payments via the api they won't be setting the line item correctly - we can't help them if they are doing complex transactions + // but if they have a single line item for the contribution we can assume it should refer to the participant line + $lineItemCount = CRM_Core_DAO::singleValueQuery("select count(*) FROM civicrm_line_item WHERE contribution_id = %1", array(1 => array($participantPayment->contribution_id, 'Integer'))); + if($lineItemCount == 1) { + $sql = "UPDATE civicrm_line_item li + SET entity_table = 'civicrm_participant', entity_id = %1 + WHERE contribution_id = %2 AND entity_table = 'civicrm_contribution'"; + CRM_Core_DAO::executeQuery($sql, array(1 => array($participantPayment->participant_id, 'Integer'), 2 => array($participantPayment->contribution_id, 'Integer'))); + } + return $participantPayment; }