Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF] Add in CiviCRM Status checks to check for inconsistencies betwe… #31538

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions ext/civi_event/civi_event.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
<?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, 'Positive'],
]);
if (empty($lineItemCheck)) {
$lineItemsMissingPayments[] = [
'contribution_id' => $parcitipantPayments->contribution_id,
'participant_id' => $parcitipantPayments->participant_id,
];
}
}
if (!empty($lineItemsMissingPayments)) {
$strings = '';
foreach ($lineItemsMissingPayments as $lineItemsMissingPayment) {
$strings .= '<tr><td>'. $lineItemsMissingPayment['contribution_id'] . '</td><td>' . $lineItemsMissingPayment['participant_id'] . '</td></tr>';
}
$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.') . ts('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 . '</tbody></table></p>',
Copy link
Contributor

@demeritcowboy demeritcowboy Nov 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I wasn't clear what I meant. The paragraph of text should be together (the translator won't know what the word "this" means otherwise, and these sentences aren't going to be re-used elsewhere), and then the table should be separate except the column headers ts'd.

'<p>' . 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><table><thead><th>' . ts('Contribution ID') . '</th><th>' . ts('Participant ID') . '</th></thead><tbody>' . $strings  . '</tbody></table></p>',

Also there's some mismatched p's.

ts('CiviCRM Participant Payment Records not matching'),
\Psr\Log\LogLevel::WARNING,
'fa-database',
);
}
}
38 changes: 38 additions & 0 deletions ext/civi_member/civi_member.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
<?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, 'Positive'],
]);
if (empty($lineItemCheck)) {
$lineItemsMissingPayments[] = [
'contribution_id' => $membershipPayments->contribution_id,
'membership_id' => $membershipPayments->membership_id,
];
}
}
if (!empty($lineItemsMissingPayments)) {
$strings = '';
foreach ($lineItemsMissingPayments as $lineItemsMissingPayment) {
$strings .= '<tr><td>'. $lineItemsMissingPayment['contribution_id'] . '</td><td>' . $lineItemsMissingPayment['membership_id'] . '</td></tr>';
}
$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.') . ts('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 . '</tbody></table></p>',
ts('CiviCRM Membership Payment Records not matching'),
\Psr\Log\LogLevel::WARNING,
'fa-database',
);
}
}