Eileen has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/329650 )
Change subject: Do not keep 'artificial' contribution_tracking record on failure. ...................................................................... Do not keep 'artificial' contribution_tracking record on failure. If the contribution_tracking has just been created & the transaction fails let's delete it. I have only added this to one place that I hit in testing & it perhaps warrants more thought - although the general issue here is not new. Bug: T153791 Change-Id: Ic2c1dda45b36cc424664b48d9d879676e21f832c --- M sites/all/modules/wmf_civicrm/wmf_civicrm.module 1 file changed, 20 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm refs/changes/50/329650/1 diff --git a/sites/all/modules/wmf_civicrm/wmf_civicrm.module b/sites/all/modules/wmf_civicrm/wmf_civicrm.module index 0103fd7..ff203db 100644 --- a/sites/all/modules/wmf_civicrm/wmf_civicrm.module +++ b/sites/all/modules/wmf_civicrm/wmf_civicrm.module @@ -885,6 +885,7 @@ $settlement_convert = exchange_rate_convert($msg['original_currency'], 1, $msg['date']) / exchange_rate_convert($settlement_currency, 1, $msg['date']); } catch (ExchangeRatesException $ex) { + wmf_civicrm_rollback_contribution_tracking($msg); throw new WmfException( 'INVALID_MESSAGE', "UNKNOWN_CURRENCY: '{$msg['original_currency']}': " . $ex->getMessage() ); } @@ -902,6 +903,23 @@ $msg['net'] = round( $msg['net'], $significantDecimals ); return $msg; +} + +/** + * Remove the contribution tracking record. + * + * If we have only just created the contribution tracking record (e.g as part of an + * offline import) it makes sense to remove it again if the full transaction fails. + * + * @param array $msg + */ +function wmf_civicrm_rollback_contribution_tracking($msg) { + if (!empty($msg['contribution_tracking_is_new'])) { + db_delete('contribution_tracking') + ->isNull('contribution_id') + ->condition('id', $msg['contribution_tracking_id']) + ->execute(); + } } /** @@ -1777,6 +1795,8 @@ $contribution_tracking_id = wmf_civicrm_insert_contribution_tracking( $source, $medium, $campaign, wmf_common_date_unix_to_sql( $msg['date'] ), null, $optout, $anonymous ); //ACK! this should not be handled this way! should be dynamic! watchdog( 'wmf_civicrm', 'Newly inserted contribution tracking id: @id', array( '@id' => $contribution_tracking_id ), WATCHDOG_DEBUG ); $msg['contribution_tracking_id'] = $contribution_tracking_id; + // Denote that it has just been created so it can be deleted if there is a failure. + $msg['contribution_tracking_is_new'] = TRUE; } } -- To view, visit https://gerrit.wikimedia.org/r/329650 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic2c1dda45b36cc424664b48d9d879676e21f832c Gerrit-PatchSet: 1 Gerrit-Project: wikimedia/fundraising/crm Gerrit-Branch: master Gerrit-Owner: Eileen <emcnaugh...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits