[MediaWiki-commits] [Gerrit] Send failmail and set no_thank_you on TY errors - change (wikimedia...crm)
jenkins-bot has submitted this change and it was merged. Change subject: Send failmail and set no_thank_you on TY errors .. Send failmail and set no_thank_you on TY errors If it's a WATCHDOG_ERROR, we should hear about it... once. If there are enough bad errors in a row, we disable the thank you batch job. Introduces a new module setting thank_you_enabled to explicitly disable job rather than setting batch size to zero. Also convert error handling in thank you batch send to use exceptions rather than return values... mostly. I used WmfException, but maybe a TY-specific exception would be better. Bug: T131200 Change-Id: I4f71fecff7c7a3bd83878cad28498370e568b589 --- M sites/all/modules/thank_you/thank_you.module M sites/all/modules/wmf_common/WmfException.php 2 files changed, 107 insertions(+), 22 deletions(-) Approvals: Awight: Looks good to me, approved jenkins-bot: Verified diff --git a/sites/all/modules/thank_you/thank_you.module b/sites/all/modules/thank_you/thank_you.module index 582777a..5c02715 100644 --- a/sites/all/modules/thank_you/thank_you.module +++ b/sites/all/modules/thank_you/thank_you.module @@ -242,15 +242,14 @@ if( !WMFCiviAPICheck::check_api_contribution( $contribution, $contribution_id ) ){ // the API result is bad $msg = 'Could not retrieve contribution record for: ' . $contribution_id . '' . print_r( $contribution, true ) . ''; - wmf_common_failmail( 'thank_you', $msg ); - return false; + throw new WmfException( 'GET_CONTRIBUTION', $msg ); } // go ahead and remove the extra layer of indirection to make it easier to use $simplified = WMFCiviAPICheck::check_api_simplify( $contribution, $contribution_id ); if( !$simplified ){ // simplification failed - watchdog('thank_you', 'Could not simplify contribution record for: ' . $contribution_id . '' . print_r( $contribution, true ) . '', array(), WATCHDOG_ERROR); - return false; + $msg = 'Could not simplify contribution record for: ' . $contribution_id . '' . print_r( $contribution, true ) . ''; + throw new WmfException( 'GET_CONTRIBUTION', $msg ); } $contribution = $simplified; @@ -277,14 +276,15 @@ // check that the API result is a valid contact result if( !WMFCiviAPICheck::check_api_contact( $contact, $contribution[ 'contact_id' ] ) ){ // the API result is bad - watchdog('thank_you', 'Could not retrieve contact record for: ' . $contribution['contact_id'] . '' . print_r( $contact, true ) . '', array(), WATCHDOG_ERROR); - return false; + $msg = 'Could not retrieve contact record for: ' . $contribution['contact_id'] . '' . print_r( $contact, true ) . ''; + throw new WmfException( 'GET_CONTACT', $msg ); } // go ahead and remove the extra layer of indirection to make it easier to use $simplified = WMFCiviAPICheck::check_api_simplify( $contact, $contribution[ 'contact_id' ] ); if( !$simplified ){ // simplification failed - watchdog('thank_you', 'Could not simplify contact record for: ' . $contribution['contact_id']. '' . print_r( $contact, true ). '', array(), WATCHDOG_ERROR); + $msg = 'Could not simplify contact record for: ' . $contribution['contact_id']. '' . print_r( $contact, true ). ''; + throw new WmfException( 'GET_CONTACT', $msg ); } $contact = $simplified; @@ -292,7 +292,7 @@ if ( empty( $contact['email'] ) or $contact['email'] === 'nob...@wikimedia.org' ) { watchdog('thank_you', 'No email address found. Processing as anonymous.', array(), WATCHDOG_INFO); wmf_civicrm_set_no_thank_you( $contribution['contribution_id'], 'anonymous' ); -return true; +return false; } $custom_values = wmf_civicrm_get_custom_values( $contribution_id, array( @@ -353,9 +353,10 @@ if ( $success ) { watchdog('thank_you', "Thank you mail sent successfully for contribution id: $contribution_id to " . $params['recipient_address'], array(), WATCHDOG_INFO); thank_you_update_ty_date( $contribution ); + return true; } else { - watchdog('thank_you', "Thank you mail failed for contribution id: $contribution_id to " . $params['recipient_address'], array(), WATCHDOG_ERROR); -wmf_civicrm_set_no_thank_you( $contribution_id, 'failed' ); + $msg = "Thank you mail failed for contribution id: $contribution_id to " . $params['recipient_address']; + throw new WmfException( 'BAD_EMAIL', $msg ); } } @@ -430,8 +431,8 @@ if ( $missing ) { $as_list = implode( ', ', $missing ); watchdog( 'thank_you',
[MediaWiki-commits] [Gerrit] Send failmail and set no_thank_you on TY errors - change (wikimedia...crm)
Ejegg has uploaded a new change for review. https://gerrit.wikimedia.org/r/281842 Change subject: Send failmail and set no_thank_you on TY errors .. Send failmail and set no_thank_you on TY errors If it's a WATCHDOG_ERROR, we should hear about it... once. Bug: T131200 Change-Id: I4f71fecff7c7a3bd83878cad28498370e568b589 --- M sites/all/modules/thank_you/thank_you.module 1 file changed, 30 insertions(+), 6 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm refs/changes/42/281842/1 diff --git a/sites/all/modules/thank_you/thank_you.module b/sites/all/modules/thank_you/thank_you.module index 582777a..c0b02e1 100644 --- a/sites/all/modules/thank_you/thank_you.module +++ b/sites/all/modules/thank_you/thank_you.module @@ -242,14 +242,15 @@ if( !WMFCiviAPICheck::check_api_contribution( $contribution, $contribution_id ) ){ // the API result is bad $msg = 'Could not retrieve contribution record for: ' . $contribution_id . '' . print_r( $contribution, true ) . ''; - wmf_common_failmail( 'thank_you', $msg ); + thank_you_fail_and_mark( $contribution_id, $msg, 'Error retrieving contribution record' ); return false; } // go ahead and remove the extra layer of indirection to make it easier to use $simplified = WMFCiviAPICheck::check_api_simplify( $contribution, $contribution_id ); if( !$simplified ){ // simplification failed - watchdog('thank_you', 'Could not simplify contribution record for: ' . $contribution_id . '' . print_r( $contribution, true ) . '', array(), WATCHDOG_ERROR); + $msg = 'Could not simplify contribution record for: ' . $contribution_id . '' . print_r( $contribution, true ) . ''; + thank_you_fail_and_mark( $contribution_id, $msg, 'Error simplifying contribution record' ); return false; } $contribution = $simplified; @@ -277,14 +278,17 @@ // check that the API result is a valid contact result if( !WMFCiviAPICheck::check_api_contact( $contact, $contribution[ 'contact_id' ] ) ){ // the API result is bad - watchdog('thank_you', 'Could not retrieve contact record for: ' . $contribution['contact_id'] . '' . print_r( $contact, true ) . '', array(), WATCHDOG_ERROR); + $msg = 'Could not retrieve contact record for: ' . $contribution['contact_id'] . '' . print_r( $contact, true ) . ''; + thank_you_fail_and_mark( $contribution_id, $msg, 'Error retrieving contact' ); return false; } // go ahead and remove the extra layer of indirection to make it easier to use $simplified = WMFCiviAPICheck::check_api_simplify( $contact, $contribution[ 'contact_id' ] ); if( !$simplified ){ // simplification failed - watchdog('thank_you', 'Could not simplify contact record for: ' . $contribution['contact_id']. '' . print_r( $contact, true ). '', array(), WATCHDOG_ERROR); + $msg = 'Could not simplify contact record for: ' . $contribution['contact_id']. '' . print_r( $contact, true ). ''; + thank_you_fail_and_mark( $contribution_id, $msg, 'Error simplifying contact record' ); + return false; } $contact = $simplified; @@ -353,13 +357,33 @@ if ( $success ) { watchdog('thank_you', "Thank you mail sent successfully for contribution id: $contribution_id to " . $params['recipient_address'], array(), WATCHDOG_INFO); thank_you_update_ty_date( $contribution ); + return true; } else { - watchdog('thank_you', "Thank you mail failed for contribution id: $contribution_id to " . $params['recipient_address'], array(), WATCHDOG_ERROR); -wmf_civicrm_set_no_thank_you( $contribution_id, 'failed' ); + $msg = "Thank you mail failed for contribution id: $contribution_id to " . $params['recipient_address']; +thank_you_fail_and_mark( $contribution_id, $msg, 'failed' ); + return false; } } /** + * Send a failmail and mark the donation as unthankable + * + * @param int $contribution_id + * @param string $mailMessage + * @param string|null $noThankYou + */ +function thank_you_fail_and_mark( $contribution_id, $mailMessage, $noThankYou = null ) { + if ( $noThankYou ) { + $mailMessage .= "Setting no_thank_you to $noThankYou"; + } else { + $noThankYou = $mailMessage; + } + // Failmail also logs a WATCHDOG_ERROR + wmf_common_failmail( 'thank_you', $mailMessage ); + wmf_civicrm_set_no_thank_you( $contribution_id, $noThankYou ); +} + +/** * Get entity tag names. * * @param int $entity_id -- To view, visit