-
-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[REF] Add in CiviCRM Status checks to check for inconsistencies betwe…
…en the membership_payment participant_payment and line item tables
- Loading branch information
1 parent
b3b377c
commit 37302f0
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,44 @@ | ||
<?php | ||
|
||
require_once 'civi_event.civix.php'; | ||
|
||
/** | ||
* Implements hook_civicrm_check(). | ||
* | ||
* Check for any legacy data where there is a participant_payment record but not a matching line item | ||
* | ||
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_check/ | ||
*/ | ||
function civi_event_civicrm_check(&$messages) :void { | ||
$parcitipantPayments = CRM_Core_DAO::executeQuery("SELECT contribution_id, participant_id FROM civicrm_participant_payment"); | ||
$lineItemsMissingPayments = []; | ||
while ($parcitipantPayments->fetch()) { | ||
$lineItemCheck = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_line_item WHERE contribution_id = %1 AND entity_id = %2 AND entity_table = 'civicrm_participant'", [ | ||
1 => [$parcitipantPayments->contribution_id, 'Positive'], | ||
2 => [$parcitipantPayments->participant_id, 'Postivie'], | ||
]); | ||
if (empty($lineItemCheck)) { | ||
$lineItemsMissingPayments[] = [ | ||
'contribution_id' => $parcitipantPayments->contribution_id, | ||
'participant_id' => $parcitipantPayments->participant_id, | ||
]; | ||
} | ||
} | ||
if (!empty($lineItemsMissingPayments)) { | ||
$strings = ''; | ||
foreach ($lineItemsMissingPayments as $lineItemsMissingPayment) { | ||
$strings .= ts('<tr><td> "%1" </td><td> "%2"</td></tr>', [ | ||
1 => $lineItemsMissingPayment['contribution_id'], | ||
2 => $lineItemsMissingPayment['participant_id'], | ||
]); | ||
} | ||
$messages[] = new CRM_Utils_Check_Message( | ||
'civi_event_participant_payments_missing', | ||
ts('The Following Participant Payments do not have a corresponding line item record linking the contribution to participant. This should be corrected either by updating the relevant line item record or adding a line item record as appropriate.</p> | ||
<p></p><table><thead><th>Contribution ID</th><th>Participant ID</th></thead><tbody>') . $strings . ts('</tbody></table></p>'), | ||
ts('CiviCRM Participant Payment Records not matching'), | ||
\Psr\Log\LogLevel::WARNING, | ||
'fa-database', | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,45 @@ | ||
<?php | ||
|
||
require_once 'civi_member.civix.php'; | ||
|
||
|
||
/** | ||
* Implements hook_civicrm_check(). | ||
* | ||
* Check for any legacy data where there is a membership_payment record but not a matching line item | ||
* | ||
* @link https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_check/ | ||
*/ | ||
function civi_member_civicrm_check(&$messages) :void { | ||
$membershipPayments = CRM_Core_DAO::executeQuery("SELECT contribution_id, membership_id FROM civicrm_membership_payment"); | ||
$lineItemsMissingPayments = []; | ||
while ($membershipPayments->fetch()) { | ||
$lineItemCheck = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_line_item WHERE contribution_id = %1 AND entity_id = %2 AND entity_table = 'civicrm_membership'", [ | ||
1 => [$membershipPayments->contribution_id, 'Positive'], | ||
2 => [$membershipPayments->membership_id, 'Postivie'], | ||
]); | ||
if (empty($lineItemCheck)) { | ||
$lineItemsMissingPayments[] = [ | ||
'contribution_id' => $membershipPayments->contribution_id, | ||
'membership_id' => $membershipPayments->membership_id, | ||
]; | ||
} | ||
} | ||
if (!empty($lineItemsMissingPayments)) { | ||
$strings = ''; | ||
foreach ($lineItemsMissingPayments as $lineItemsMissingPayment) { | ||
$strings .= ts('<tr><td> "%1" </td><td> "%2"</td></tr>', [ | ||
1 => $lineItemsMissingPayment['contribution_id'], | ||
2 => $lineItemsMissingPayment['membership_id'], | ||
]); | ||
} | ||
$messages[] = new CRM_Utils_Check_Message( | ||
'civi_member_membership_payments_missing', | ||
ts('The Following Membership Payments do not have a corresponding line item record linking the contribution to membership. This should be corrected either by updating the relevant line item record or adding a line item record as appropriate.</p> | ||
<p></p><table><thead><th>Contribution ID</th><th>Membership ID</th></thead><tbody>') . $strings . ts('</tbody></table></p>'), | ||
ts('CiviCRM Membership Payment Records not matching'), | ||
\Psr\Log\LogLevel::WARNING, | ||
'fa-database', | ||
); | ||
} | ||
} |