jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/329647 )
Change subject: Add support for importing campaign source, medium for CoinBase. ...................................................................... Add support for importing campaign source, medium for CoinBase. Bug: T153791 Change-Id: I4ead63974309f149f63323d9bac663761a78687e --- M sites/all/modules/offline2civicrm/CoinbaseFile.php M sites/all/modules/offline2civicrm/tests/CoinBaseTest.php M sites/all/modules/offline2civicrm/tests/data/coinbase.csv M sites/all/modules/wmf_civicrm/wmf_civicrm.module 4 files changed, 19 insertions(+), 8 deletions(-) Approvals: jenkins-bot: Verified Ejegg: Looks good to me, approved diff --git a/sites/all/modules/offline2civicrm/CoinbaseFile.php b/sites/all/modules/offline2civicrm/CoinbaseFile.php index 2bfe8c6..1f604f4 100644 --- a/sites/all/modules/offline2civicrm/CoinbaseFile.php +++ b/sites/all/modules/offline2civicrm/CoinbaseFile.php @@ -12,7 +12,6 @@ return array( 'BTC Price', 'Currency', - //'Custom', 'Customer Email', 'Native Price', 'Phone Number', @@ -41,6 +40,9 @@ $msg['gateway'] = 'coinbase'; $msg['contribution_type'] = 'cash'; $msg['payment_instrument'] = 'Bitcoin'; + // It seems that payment_method is used for creating the contribution_tracking source + // whereas payment_instrument is used for CiviCRM contributions payment_instrument_id field. + $msg['payment_method'] = 'bitcoin'; list($msg['first_name'], $msg['last_name']) = wmf_civicrm_janky_split_name( $msg['full_name'] ); @@ -71,10 +73,12 @@ protected function getFieldMapping() { return array( + 'Banner' => 'utm_source', + 'Campaign' => 'utm_campaign', //'BTC Price' => 'original_gross', 'Currency' => 'currency', - //'Custom' => 'contribution_tracking', // TODO 'Customer Email' => 'email', + 'Medium' => 'utm_medium', // FIXME: this will destroy recurring subscription import, for now. 'Native Price' => 'gross', 'Phone Number' => 'phone', // TODO: not stored diff --git a/sites/all/modules/offline2civicrm/tests/CoinBaseTest.php b/sites/all/modules/offline2civicrm/tests/CoinBaseTest.php index 91e1744..e7f9f78 100644 --- a/sites/all/modules/offline2civicrm/tests/CoinBaseTest.php +++ b/sites/all/modules/offline2civicrm/tests/CoinBaseTest.php @@ -24,8 +24,9 @@ $importer->import(); $contribution = wmf_civicrm_get_contributions_from_gateway_id($this->gateway, $this->trxn_id); - $this->assertEquals( 1, count( $contribution ) ); - $this->assertEquals( 'COINBASE PLUTO', $contribution[0]['trxn_id'] ); + $this->assertEquals(1, count($contribution)); + $this->assertEquals('COINBASE PLUTO', $contribution[0]['trxn_id']); + $this->assertEquals('online', db_query("SELECT {utm_medium} from {contribution_tracking} WHERE contribution_id = {$contribution[0]['id']}")->fetchField()); } } diff --git a/sites/all/modules/offline2civicrm/tests/data/coinbase.csv b/sites/all/modules/offline2civicrm/tests/data/coinbase.csv index b336848..d0c8678 100644 --- a/sites/all/modules/offline2civicrm/tests/data/coinbase.csv +++ b/sites/all/modules/offline2civicrm/tests/data/coinbase.csv @@ -1,2 +1,2 @@ -BTC Price,Currency,Customer Email,Native Price,Phone Number,Recurring Payment ID,Refund Transaction ID,Shipping Address 1,Shipping Address 2,Shipping City,Shipping Country,Shipping Name,Shipping Postal Code,Shipping State,Status,Timestamp,Tracking Code -5.0009,BTC,mic...@mouse.com,1,456 789,,,52 Disney Lane,,Disneyland,US,Mickey Mouse,,,,2016-09-15,Pluto +BTC Price,Currency,Customer Email,Native Price,Phone Number,Recurring Payment ID,Refund Transaction ID,Shipping Address 1,Shipping Address 2,Shipping City,Shipping Country,Shipping Name,Shipping Postal Code,Shipping State,Status,Timestamp,Tracking Code,Campaign,Medium,Banner +5.0009,BTC,mic...@mouse.com,1,456 789,,,52 Disney Lane,,Disneyland,US,Mickey Mouse,,,,2016-09-15,Pluto,Planet drive,online,mouse-drive diff --git a/sites/all/modules/wmf_civicrm/wmf_civicrm.module b/sites/all/modules/wmf_civicrm/wmf_civicrm.module index a3e8b65..0103fd7 100644 --- a/sites/all/modules/wmf_civicrm/wmf_civicrm.module +++ b/sites/all/modules/wmf_civicrm/wmf_civicrm.module @@ -1755,9 +1755,15 @@ // if we're missing a contrib id, insert new record to the table // this can happen if a user somehow makes a trxn from outside the normal workflow - // checks are ignored as they were completely offline + // Historically checks have been ignored as they are completely offline. + // T146295 has raised some questions about this. + // code change respects previous recognition of 'payment_method' as being a little bit magic, + // but also assumes that if you are setting utm_medium or utm_source in your import you intend them to be recorded. if ( !isset( $msg[ 'contribution_tracking_id' ] ) ) { - if ( array_key_exists( 'payment_method', $msg ) && strtoupper( $msg['payment_method'] ) != "CHECK" ) { + if ( + (!empty($msg['utm_medium']) || !empty($msg['utm_source'])) + || (array_key_exists('payment_method', $msg) && strtoupper($msg['payment_method']) != "CHECK") + ) { watchdog( 'wmf_civicrm', 'Contribution missing contribution_tracking_id', array(), WATCHDOG_DEBUG ); //@fixme: For the regular transactions, this has been moved to the staging function. This needs to happen in recurring also, and then it can be removed here. -- To view, visit https://gerrit.wikimedia.org/r/329647 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I4ead63974309f149f63323d9bac663761a78687e Gerrit-PatchSet: 3 Gerrit-Project: wikimedia/fundraising/crm Gerrit-Branch: master Gerrit-Owner: Eileen <emcnaugh...@wikimedia.org> Gerrit-Reviewer: Awight <awi...@wikimedia.org> Gerrit-Reviewer: Cdentinger <cdentin...@wikimedia.org> Gerrit-Reviewer: Ejegg <eeggles...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits