From a57505074ac550dabebfd9c374972aa4d6b71ed5 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 26 Feb 2018 11:03:58 +1300 Subject: [PATCH] Fix another entity to be standardised & support custom data --- CRM/Event/BAO/ParticipantPayment.php | 22 ++++++++++++------- CRM/Event/Cart/Form/Checkout/Payment.php | 3 +-- CRM/Event/Form/Participant.php | 3 +-- CRM/Event/Form/Registration.php | 3 +-- api/v3/ParticipantPayment.php | 12 +--------- .../CRM/Contribute/BAO/ContributionTest.php | 3 +-- .../phpunit/api/v3/SyntaxConformanceTest.php | 4 ---- 7 files changed, 19 insertions(+), 31 deletions(-) diff --git a/CRM/Event/BAO/ParticipantPayment.php b/CRM/Event/BAO/ParticipantPayment.php index c39284c7b60b..dc9dcfd12cc3 100644 --- a/CRM/Event/BAO/ParticipantPayment.php +++ b/CRM/Event/BAO/ParticipantPayment.php @@ -41,14 +41,15 @@ class CRM_Event_BAO_ParticipantPayment extends CRM_Event_DAO_ParticipantPayment * @param array $params * of values to initialize the record with. * @param array $ids - * with one values of id for this participantPayment record (for update). + * deprecated array. * * @return object * the partcipant payment record */ - public static function create(&$params, &$ids) { - if (isset($ids['id'])) { - CRM_Utils_Hook::pre('edit', 'ParticipantPayment', $ids['id'], $params); + public static function create(&$params, $ids = []) { + $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('id', $ids)); + if ($id) { + CRM_Utils_Hook::pre('edit', 'ParticipantPayment', $id, $params); } else { CRM_Utils_Hook::pre('create', 'ParticipantPayment', NULL, $params); @@ -56,16 +57,21 @@ public static function create(&$params, &$ids) { $participantPayment = new CRM_Event_BAO_ParticipantPayment(); $participantPayment->copyValues($params); - if (isset($ids['id'])) { - $participantPayment->id = CRM_Utils_Array::value('id', $ids); + if ($id) { + $participantPayment->id = $id; } else { $participantPayment->find(TRUE); } $participantPayment->save(); - if (isset($ids['id'])) { - CRM_Utils_Hook::post('edit', 'ParticipantPayment', $ids['id'], $participantPayment); + if (empty($participantPayment->contribution_id)) { + // For an id update contribution_id may be unknown. We want it + // further down so perhaps get it before the hooks. + $participantPayment->find(TRUE); + } + if ($id) { + CRM_Utils_Hook::post('edit', 'ParticipantPayment', $id, $participantPayment); } else { CRM_Utils_Hook::post('create', 'ParticipantPayment', NULL, $participantPayment); diff --git a/CRM/Event/Cart/Form/Checkout/Payment.php b/CRM/Event/Cart/Form/Checkout/Payment.php index 51f9126b9da5..abb0488e557d 100644 --- a/CRM/Event/Cart/Form/Checkout/Payment.php +++ b/CRM/Event/Cart/Form/Checkout/Payment.php @@ -86,8 +86,7 @@ public function registerParticipant($params, &$participant, $event) { 'participant_id' => $participant->id, 'contribution_id' => $params['contributionID'], ); - $ids = array(); - CRM_Event_BAO_ParticipantPayment::create($payment_params, $ids); + CRM_Event_BAO_ParticipantPayment::create($payment_params); } $transaction->commit(); diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index e3d7fafefd7f..05596f1f06f4 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -1308,9 +1308,8 @@ public function submit($params) { 'participant_id' => $participants[0]->id, 'contribution_id' => $contribution->id, ); - $ids = array(); - CRM_Event_BAO_ParticipantPayment::create($paymentParticipant, $ids); + CRM_Event_BAO_ParticipantPayment::create($paymentParticipant); $this->_contactIds[] = $this->_contactId; } else { diff --git a/CRM/Event/Form/Registration.php b/CRM/Event/Form/Registration.php index 8c91912ef248..67d25120ea35 100644 --- a/CRM/Event/Form/Registration.php +++ b/CRM/Event/Form/Registration.php @@ -761,8 +761,7 @@ public function confirmPostProcess($contactID = NULL, $contribution = NULL, $pay 'participant_id' => $participant->id, 'contribution_id' => $contribution->id, ); - $ids = array(); - $paymentPartcipant = CRM_Event_BAO_ParticipantPayment::create($paymentParams, $ids); + $paymentPartcipant = CRM_Event_BAO_ParticipantPayment::create($paymentParams); } //set only primary participant's params for transfer checkout. diff --git a/api/v3/ParticipantPayment.php b/api/v3/ParticipantPayment.php index 422049a920a6..7a231e78d6d5 100644 --- a/api/v3/ParticipantPayment.php +++ b/api/v3/ParticipantPayment.php @@ -43,17 +43,7 @@ * @return array */ function civicrm_api3_participant_payment_create($params) { - - $ids = array(); - if (!empty($params['id'])) { - $ids['id'] = $params['id']; - } - $participantPayment = CRM_Event_BAO_ParticipantPayment::create($params, $ids); - - $payment = array(); - _civicrm_api3_object_to_array($participantPayment, $payment[$participantPayment->id]); - - return civicrm_api3_create_success($payment, $params); + return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params, 'ParticipantPayment'); } /** diff --git a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php index 4429f8f2adac..e0c142175df4 100644 --- a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php @@ -748,8 +748,7 @@ public function addParticipantWithContribution() { 'participant_id' => $participant->id, 'contribution_id' => $contribution['id'], ); - $ids = array(); - CRM_Event_BAO_ParticipantPayment::create($paymentParticipant, $ids); + CRM_Event_BAO_ParticipantPayment::create($paymentParticipant); $contributionObject = new CRM_Contribute_BAO_Contribution(); $contributionObject->id = $contribution['id']; diff --git a/tests/phpunit/api/v3/SyntaxConformanceTest.php b/tests/phpunit/api/v3/SyntaxConformanceTest.php index fe44e0ec78ec..b4cd5187dc39 100644 --- a/tests/phpunit/api/v3/SyntaxConformanceTest.php +++ b/tests/phpunit/api/v3/SyntaxConformanceTest.php @@ -393,7 +393,6 @@ public static function toBeSkipped_custom_data_creatable($sequential = FALSE) { 'UFJoin', 'UFField', 'PriceFieldValue', - 'Website', 'JobLog', 'GroupContact', 'EntityTag', @@ -401,7 +400,6 @@ public static function toBeSkipped_custom_data_creatable($sequential = FALSE) { 'PaymentProcessorType', 'Relationship', 'RelationshipType', - 'ParticipantPayment', // ones that are not real entities hence not extendable. 'ActivityType', @@ -466,7 +464,6 @@ public static function toBeSkipped_automock($sequential = FALSE) { 'MailingContact', 'EntityTag', 'Participant', - 'ParticipantPayment', 'Setting', 'SurveyRespondant', 'MailingRecipients', @@ -535,7 +532,6 @@ public static function toBeSkipped_updatesingle($sequential = FALSE) { 'GroupContact', 'MembershipPayment', 'Participant', - 'ParticipantPayment', 'LineItem', 'PledgePayment', 'ContributionPage',