Eileen has uploaded a new change for review.

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

Change subject: Add script to fill missing appeal data
......................................................................

Add script to fill missing appeal data

This data was missed due to a patch that caused it to never validate in early 
Nov and
potentially  also due to not all desired campaigns being configured. The 
function itself could be rerun after enabling a new option and could 
potentially be called from a hook called when options are enabled.

Bug: T121284:
Change-Id: Ieebfdbf78f3837824bfc3e6e2b2c5ac37b02645a
---
M sites/all/modules/wmf_civicrm/wmf_civicrm.install
M sites/all/modules/wmf_civicrm/wmf_civicrm.module
2 files changed, 41 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikimedia/fundraising/crm 
refs/changes/85/259185/1

diff --git a/sites/all/modules/wmf_civicrm/wmf_civicrm.install 
b/sites/all/modules/wmf_civicrm/wmf_civicrm.install
index 47e6394..effbcfb 100644
--- a/sites/all/modules/wmf_civicrm/wmf_civicrm.install
+++ b/sites/all/modules/wmf_civicrm/wmf_civicrm.install
@@ -43,6 +43,7 @@
     wmf_civicrm_update_7061();
     wmf_civicrm_update_7062();
     wmf_civicrm_update_7063();
+    wmf_civicrm_update_7064();
 }
 
 /**
@@ -1504,3 +1505,12 @@
     ));
 }
 
+/**
+ * Add appeal data that has been missed.
+ *
+ * T121284
+ */
+function wmf_civicrm_update_7064() {
+    wmf_civicrm_fill_missing_appeal_data('20151001');
+}
+
diff --git a/sites/all/modules/wmf_civicrm/wmf_civicrm.module 
b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
index c5f2851..ba06626 100644
--- a/sites/all/modules/wmf_civicrm/wmf_civicrm.module
+++ b/sites/all/modules/wmf_civicrm/wmf_civicrm.module
@@ -2437,3 +2437,34 @@
     $options = civicrm_api3($entity, 'getoptions', array('field' => $field));
     return $options['values'];
 }
+
+/**
+ * Fills in the appear field with any data that might be missing from it.
+ * @param string $startDate
+ */
+function wmf_civicrm_fill_missing_appeal_data($startDate) {
+  civicrm_initialize();
+  $customGroup = civicrm_api3('CustomGroup', 'getsingle', array('name' => 
'Gift_Data'));
+  $optionGroupID = civicrm_api3('CustomField', 'getvalue', array(
+    'name' => wmf_civicrm_get_direct_mail_field_option_name(),
+    'return' => 'option_group_id',
+  ));
+  global $databases;
+  $drupal = $databases['default']['default']['database'];
+  CRM_Core_DAO::executeQuery("
+    UPDATE
+    {$customGroup['table_name']} v
+    LEFT JOIN {$drupal}.contribution_tracking ON v.entity_id = contribution_id
+    LEFT JOIN civicrm_contribution c ON c.id = contribution_id
+
+    SET v.appeal = utm_campaign
+
+    WHERE
+      ts > '{$startDate}' AND
+      c.id IS NOT NULL
+      AND v.appeal IS NULL
+      AND utm_campaign IN (
+        SELECT value COLLATE utf8_unicode_ci FROM civicrm_option_value ov 
WHERE ov.option_group_id= {$optionGroupID} AND is_active = 1
+      )
+  ");
+}

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ieebfdbf78f3837824bfc3e6e2b2c5ac37b02645a
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

Reply via email to