Awight has uploaded a new change for review. https://gerrit.wikimedia.org/r/149613
Change subject: Transaction around recurring Globalcollect charge ...................................................................... Transaction around recurring Globalcollect charge Change-Id: I837dcb5390a1e8e6fa63054c05367cd666c4069e --- M sites/all/modules/recurring_globalcollect/recurring_globalcollect.module M sites/all/modules/wmf_common/Queue.php A sites/all/modules/wmf_common/WmfDatabase.php M sites/all/modules/wmf_common/wmf_common.info 4 files changed, 49 insertions(+), 42 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm refs/changes/13/149613/1 diff --git a/sites/all/modules/recurring_globalcollect/recurring_globalcollect.module b/sites/all/modules/recurring_globalcollect/recurring_globalcollect.module index d42b6a5..a4ffef1 100644 --- a/sites/all/modules/recurring_globalcollect/recurring_globalcollect.module +++ b/sites/all/modules/recurring_globalcollect/recurring_globalcollect.module @@ -260,13 +260,12 @@ foreach ($contribution_batch as $contribution_recur) { try { - $status = recurring_globalcollect_charge($contribution_recur, $options); + WmfDatabase::transactionalCall( + 'recurring_globalcollect_charge', + array( $contribution_recur, $options ) + ); - if ($status) { - $succeeded[] = $contribution_recur; - } else { - $failed[] = $contribution_recur; - } + $succeeded[] = $contribution_recur; } catch ( WmfException $e ) { @@ -420,8 +419,6 @@ _recurring_globalcollect_update_record_failure($contribution_recur['id']); throw new WmfException( 'PAYMENT_FAILED', 'recurring charge failed', $result); } - - return $result; } /** diff --git a/sites/all/modules/wmf_common/Queue.php b/sites/all/modules/wmf_common/Queue.php index 789c5b5..babc2cc 100644 --- a/sites/all/modules/wmf_common/Queue.php +++ b/sites/all/modules/wmf_common/Queue.php @@ -104,7 +104,9 @@ try { $this->commonMessageNormalize( $msg ); - $this->transactionalCall( $callback, $msg ); + WmfDatabase::transactionalCall( + $callback, array( $msg ) + ); $this->ack( $msg ); } catch ( WmfException $ex ) { watchdog( 'wmf_common', 'Failure while processing message: ' . $ex->getMessage(), NULL, WATCHDOG_ERROR ); @@ -183,39 +185,6 @@ $messages[] = $msg; } return $messages; - } - - /** - * Call the message processing callback and perform common error handling - * - * TODO: move the remaining error handling in here - */ - protected function transactionalCall( $callback, $msg ) { - watchdog( 'wmf_common', "Beginning DB transaction", NULL, WATCHDOG_INFO ); - $drupal_transaction = db_transaction( 'dequeue_default', array( 'target' => 'default' ) ); - $ct_transaction = db_transaction( 'dequeue_donations', array( 'target' => 'donations' ) ); - $crm_transaction = db_transaction( 'dequeue_civicrm', array( 'target' => 'civicrm' ) ); - $native_civi_transaction = new CRM_Core_Transaction(); - - try { - // Do the right thing - $callback( $msg ); - } - catch ( Exception $ex ) { - watchdog( 'wmf_common', "Aborting DB transaction.", NULL, WATCHDOG_INFO ); - $native_civi_transaction->rollback(); - $crm_transaction->rollback(); - $ct_transaction->rollback(); - $drupal_transaction->rollback(); - - throw $ex; - } - - watchdog( 'wmf_common', "Committing DB transaction", NULL, WATCHDOG_INFO ); - $native_civi_transaction->commit(); - unset( $crm_transaction ); - unset( $ct_transaction ); - unset( $drupal_transaction ); } function getByCorrelationId( $queue, $correlationId ) { diff --git a/sites/all/modules/wmf_common/WmfDatabase.php b/sites/all/modules/wmf_common/WmfDatabase.php new file mode 100644 index 0000000..d1867fb --- /dev/null +++ b/sites/all/modules/wmf_common/WmfDatabase.php @@ -0,0 +1,40 @@ +<?php + +//TODO: namespace +class WmfDatabase { + /** + * Multiple-database transaction around your callback + * + * FIXME: This is not even two-phase locking. If any commit fails, the dbs become inconsistent. + * + * @param callable $callback + * @param array $params + */ + static function transactionalCall( $callback, $params ) { + watchdog( 'wmf_common', "Beginning DB transaction", NULL, WATCHDOG_INFO ); + $drupal_transaction = db_transaction( 'wmf_default', array( 'target' => 'default' ) ); + $ct_transaction = db_transaction( 'wmf_donations', array( 'target' => 'donations' ) ); + $crm_transaction = db_transaction( 'wmf_civicrm', array( 'target' => 'civicrm' ) ); + $native_civi_transaction = new CRM_Core_Transaction(); + + try { + // Do the thing itself + call_user_func_array( $callback, $params ); + } + catch ( Exception $ex ) { + watchdog( 'wmf_common', "Aborting DB transaction.", NULL, WATCHDOG_INFO ); + $native_civi_transaction->rollback(); + $crm_transaction->rollback(); + $ct_transaction->rollback(); + $drupal_transaction->rollback(); + + throw $ex; + } + + watchdog( 'wmf_common', "Committing DB transaction", NULL, WATCHDOG_INFO ); + $native_civi_transaction->commit(); + unset( $crm_transaction ); + unset( $ct_transaction ); + unset( $drupal_transaction ); + } +} diff --git a/sites/all/modules/wmf_common/wmf_common.info b/sites/all/modules/wmf_common/wmf_common.info index 0ccf3c2..066386e 100755 --- a/sites/all/modules/wmf_common/wmf_common.info +++ b/sites/all/modules/wmf_common/wmf_common.info @@ -4,6 +4,7 @@ package = Wikimedia configure = admin/config/wmf_common files[] = Queue.php +files[] = WmfDatabase.php files[] = WmfException.php files[] = twigext_l10n/CldrData.php files[] = twigext_l10n/TwigLocalization.php -- To view, visit https://gerrit.wikimedia.org/r/149613 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I837dcb5390a1e8e6fa63054c05367cd666c4069e Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/fundraising/crm Gerrit-Branch: master Gerrit-Owner: Awight <awi...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits