Ejegg has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/389721 )
Change subject: WIP thank you sender is a queue consumer ...................................................................... WIP thank you sender is a queue consumer Bug: T172300 Change-Id: Ia4d6ffc16ed76745b115106163a0d97b65a1c755 --- A sites/all/modules/thank_you/ThankYouQueueConsumer.php M sites/all/modules/thank_you/thank_you.module M sites/all/modules/wmf_civicrm/wmf_civicrm.module 3 files changed, 64 insertions(+), 43 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm refs/changes/21/389721/1 diff --git a/sites/all/modules/thank_you/ThankYouQueueConsumer.php b/sites/all/modules/thank_you/ThankYouQueueConsumer.php new file mode 100644 index 0000000..b7871b9 --- /dev/null +++ b/sites/all/modules/thank_you/ThankYouQueueConsumer.php @@ -0,0 +1,19 @@ +<?php namespace thank_you; + +use wmf_common\WmfQueueConsumer; +use WmfException; + +class ThankYouQueueConsumer extends WmfQueueConsumer { + + /** + * Send thank you messages for contributions + * + * @param array $message + * @throws WmfException + */ + function processMessage( $message ) { + try { + thank_you_for_contribution( $message ); + } + } +} diff --git a/sites/all/modules/thank_you/thank_you.module b/sites/all/modules/thank_you/thank_you.module index 17bdbb1..ac32bb5 100644 --- a/sites/all/modules/thank_you/thank_you.module +++ b/sites/all/modules/thank_you/thank_you.module @@ -233,47 +233,12 @@ /** * Send a TY letter, and do bookkeeping on the Civi records * TODO: rewrite the civi api stuff to work like other code + * @param array $mailingData + * @return bool + * @throws WmfException */ -function thank_you_for_contribution( $contribution_id ) { - civicrm_initialize(); - $mailingData = CRM_Core_DAO::executeQuery(" - SELECT - cntr.id AS contribution_id, - cntr.currency, - cntr.receive_date, - cntr.thankyou_date, - cntr.total_amount, - cntr.trxn_id, - cntc.id AS contact_id, - cntc.display_name, - cntc.first_name, - cntc.last_name, - cntc.preferred_language, - e.email, - x.gateway, - x.no_thank_you, - x.original_amount, - x.original_currency - FROM civicrm_contribution cntr - INNER JOIN civicrm_contact cntc ON cntr.contact_id = cntc.id - LEFT JOIN civicrm_email e ON e.contact_id = cntc.id AND e.is_primary = 1 - INNER JOIN wmf_contribution_extra x ON cntr.id = x.entity_id - WHERE cntr.id = %1 - ", array( - 1 => array( - $contribution_id, - 'Int' - ) - )); - $found = $mailingData->fetch(); - - // check that the API result is a valid contribution result - if( !$found ){ - // the API result is bad - $msg = 'Could not retrieve contribution record for: ' . $contribution_id . '<pre>' . print_r( $mailingData, true ) . '</pre>'; - throw new WmfException( 'GET_CONTRIBUTION', $msg ); - } - $mailingData = $mailingData->toArray(); +function thank_you_for_contribution( $mailingData ) { + $contribution_id = $mailingData['contribution_id']; // don't send a Thank You email if one has already been sent if ( !empty($mailingData['thankyou_date']) ) { @@ -295,7 +260,7 @@ } if ( $mailingData['no_thank_you'] ) { - watchdog('thank_you', "Contribution has been marked no_thank_you={$mailingData['no_thank_you']}, skipping.", array(), WATCHDOG_INFO); + return false; } @@ -332,13 +297,12 @@ 'from_address' => variable_get( 'thank_you_from_address', 'don...@wikimedia.org' ), 'last_name' => $mailingData['last_name'], 'locale' => $locale, - 'name' => $mailingData['display_name'], 'receive_date' => $mailingData['receive_date'], 'recipient_address' => $mailingData['email'], 'recurring' => $is_recurring, 'transaction_id' => "CNTCT-{$mailingData['contact_id']}", 'unsubscribe_link' => build_unsub_link( $contribution_id, $mailingData['email'], $locale ), - 'contribution_tags' => wmf_thank_you_get_tag_names($contribution_id), + 'contribution_tags' => $mailingData['contribution_tags'], ); $success = thank_you_send_mail( $params ); @@ -761,6 +725,15 @@ watchdog( "thank_you", "Attempting to send $batch thank you mails for contributions from the last $days days.", array(), WATCHDOG_INFO ); + + $qc = new \thank_you\ThankYouQueueConsumer( + 'thank-you', + $timeLimit, + $batch + ); + $processed = $qc->dequeueMessages(); + + $dbs = wmf_civicrm_get_dbs(); $dbs->push( 'civicrm' ); diff --git a/sites/all/modules/wmf_civicrm/wmf_civicrm.module b/sites/all/modules/wmf_civicrm/wmf_civicrm.module index 2326ac1..7820b66 100644 --- a/sites/all/modules/wmf_civicrm/wmf_civicrm.module +++ b/sites/all/modules/wmf_civicrm/wmf_civicrm.module @@ -1,5 +1,6 @@ <?php +use SmashPig\Core\DataStores\QueueWrapper; use SmashPig\Core\UtcDate; use SmashPig\PaymentData\ReferenceData\CurrencyRates; @@ -302,6 +303,8 @@ wmf_civicrm_message_update_contribution_tracking( $msg, $contribution ); } + wmf_civicrm_send_thank_you_queue_message( $msg, $contribution ); + if ( !empty( $msg['notes'] ) ) { // TODO: Handle failure. civicrm_api3( "Note", "Create", array( @@ -314,6 +317,32 @@ return $contribution; } +function wmf_civicrm_send_thank_you_queue_message( $msg, $contribution ) { + if ( !empty( $msg['no_thank_you'] ) ) { + watchdog('thank_you', "Contribution has been marked no_thank_you={$msg['no_thank_you']}, skipping.", array(), WATCHDOG_INFO); + return; + } + $params = array( + 'contribution_id' => $contribution['id'], + 'currency' => $contribution['currency'], + 'receive_date' => $contribution['receive_date'], + 'total_amount' => $contribution['total_amount'], + 'trxn_id' => $contribution['trxn_id'], + 'contact_id' => $contribution['contact_id'], + 'first_name' => $msg['first_name'], + 'last_name' => $msg['last_name'], + 'preferred_language' => $msg['language'], // todo: deal with when this is blank + 'email' => $msg['email'], + 'gateway' => $msg['gateway'], + 'original_amount' => $msg['original_gross'], + 'original_currency' => $msg['original_currency'], + ); + if ( isset( $msg['contribution_tags'] ) ) { + $params['contribution_tags'] = $msg['contribution_tags']; + } + QueueWrapper::push( 'thank-you', $params ); +} + /** * Create a contact from the $msg array and set the contact_id. * -- To view, visit https://gerrit.wikimedia.org/r/389721 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ia4d6ffc16ed76745b115106163a0d97b65a1c755 Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/fundraising/crm Gerrit-Branch: master Gerrit-Owner: Ejegg <ej...@ejegg.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits