Ejegg has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/176851

Change subject: WIP update wmf_donor fields after merge
......................................................................

WIP update wmf_donor fields after merge

TODO:
* try to hide them from the merge list
* investigate why do_not_solicit is being clobbered

Change-Id: Ic7288f29bd061bf17274ab4fb4bc8d2105340b21
---
M sites/all/modules/wmf_civicrm/wmf_civicrm.module
1 file changed, 31 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm 
refs/changes/51/176851/1

diff --git a/sites/all/modules/wmf_civicrm/wmf_civicrm.module 
b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
index 24fce37..2ee2481 100644
--- a/sites/all/modules/wmf_civicrm/wmf_civicrm.module
+++ b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
@@ -1693,7 +1693,7 @@
 /**
  * Implementation of hook_civicrm_merge, adds our custom tables.
  */
-function wmf_civicrm_civicrm_merge( $type, &$refs ) {
+function wmf_civicrm_civicrm_merge( $type, &$refs, $mainId, $otherId, $tables 
) {
     switch ( $type ) {
     case 'cidRefs':
         $contact_types = array( "Contact" );
@@ -1713,6 +1713,36 @@
             $refs[ $dao->table_name ][] = 'entity_id';
         }
         break;
+       case 'sqls':
+               // After merging contribution data, update the wmf_donor columns
+               $refs[] = "INSERT INTO wmf_donor( entity_id, 
last_donation_date, lifetime_usd_total ) (
+                       SELECT contact_id, MAX(receive_date) AS 
last_donation_date, SUM(total_amount) AS lifetime_usd_total
+                       FROM civicrm_contribution
+                       WHERE contact_id = $mainId
+               ) ON DUPLICATE KEY UPDATE
+                       last_donation_date = VALUES(last_donation_date),
+                       lifetime_usd_total = VALUES(lifetime_usd_total)";
+               $refs[] = "UPDATE wmf_donor w
+               JOIN civicrm_contribution t
+                       ON t.contact_id = w.entity_id
+                       AND t.contact_id = $mainId
+                       AND t.receive_date = w.last_donation_date
+               JOIN wmf_contribution_extra x
+                       ON x.entity_id = t.id
+               SET w.last_donation_usd = t.total_amount,
+                       w.last_donation_amount = x.original_amount,
+                       w.last_donation_currency = x.original_currency";
+               for ( $year = WMF_MIN_ROLLUP_YEAR; $year <= 
WMF_MAX_ROLLUP_YEAR; $year++ ) {
+                       $next_year = $year + 1;
+                       $refs[] = "UPDATE wmf_donor w
+                       JOIN civicrm_contribution t
+                               ON t.contact_id = w.entity_id
+                               AND t.contact_id = $mainId
+                               AND t.receive_date >= '$year-07-01'
+                               AND t.receive_date < '$next_year-07-01'
+                       SET w.is_{$year}_donor = 1";
+               };
+               break;
     }
 }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/176851
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic7288f29bd061bf17274ab4fb4bc8d2105340b21
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/fundraising/crm
Gerrit-Branch: master
Gerrit-Owner: Ejegg <eeggles...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to