Eileen has uploaded a new change for review.

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

Change subject: Minor data tidy up spotted during refund spot-checking.
......................................................................

Minor data tidy up spotted during refund spot-checking.

A very small number of records are missing financial_type or account data. This 
adds that to those records
I just chose the type 'Cash' which seemed common without too much thought as so 
few records are affected.

Also delete a small number of orphan line item rows

Bug: T122946
Change-Id: I31d48238acba8d1db94b0e3b334a8cb1e930b033
---
M sites/all/modules/wmf_civicrm/wmf_civicrm.install
1 file changed, 59 insertions(+), 0 deletions(-)


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

diff --git a/sites/all/modules/wmf_civicrm/wmf_civicrm.install 
b/sites/all/modules/wmf_civicrm/wmf_civicrm.install
index 9451539..d7cea85 100644
--- a/sites/all/modules/wmf_civicrm/wmf_civicrm.install
+++ b/sites/all/modules/wmf_civicrm/wmf_civicrm.install
@@ -1758,3 +1758,62 @@
     }
   }
 }
+
+/**
+ * Fix financial item records with null financial_account.
+ *
+ * Incredibly we have only 4 of these in our database & Elliott picked up this 
problem through spot
+ * checks!.
+ *
+ * Reference contact is civicrm/contact/view?reset=1&cid=11346599 - before 
this update
+ * one of the contact's transactions does not display financial details when 
expanded in the UI.
+ *
+ *  [civicrm]> SELECT count(*) FROM civicrm_financial_item WHERE 
financial_account_id IS NULL;
+ * +----------+
+ * | count(*) |
+ * +----------+
+ * |        4 |
+ * +----------+
+ *
+ * These relate to line items with no financial_type_id of which we have 74.
+ *
+ * SELECT count(*) FROM civicrm_line_item li LEFT JOIN civicrm_contribution c 
ON c.id = li.contribution_id WHERE li.financial_type_id IS NULL;
+ * +----------+
+ * | count(*) |
+ * +----------+
+ * |       74 |
+ * +----------+
+ *
+ * Of those 74 rows 70 are orphans - ie line items with no contributions. It 
appears the contributions
+ * were deleted at some point in the past.
+ *
+ * This relates to T122946 & is a follow up fix.
+ */
+function wmf_civicrm_update_7150() {
+  civicrm_initialize();
+  $cashFinancialTypeID = civicrm_api3('FinancialType', 'getvalue', array(
+    'return' => 'id',
+    'name' => 'Cash',
+  ));
+
+  $cashFinancialAccountID = civicrm_api3('FinancialAccount', 'getvalue', array(
+    'return' => 'id',
+    'name' => 'Cash',
+  ));
+  // Deletes 70 orphan entries - a bit slow but I couldn't bring myself to 
take out the join & just filter
+  // on contribution_id IS NOT NULL as it felt less safe. Takes 1-2 minutes
+  CRM_Core_DAO::executeQuery("
+    DELETE li
+    FROM civicrm_line_item li
+    LEFT JOIN civicrm_contribution c ON li.entity_id = c.id
+    AND li.entity_table = 'civicrm_contribution'
+    WHERE c.id IS NULL
+  ");
+  // Updates 4 records.
+  CRM_Core_DAO::executeQuery("UPDATE civicrm_contribution SET 
financial_type_id = $cashFinancialTypeID WHERE financial_type_id IS NULL");
+  // Updates 4 records.
+  CRM_Core_DAO::executeQuery("UPDATE civicrm_line_item SET financial_type_id = 
$cashFinancialTypeID WHERE financial_type_id IS NULL");
+  // Updates 4 records.
+  CRM_Core_DAO::executeQuery("UPDATE civicrm_financial_item SET 
financial_account_id = $cashFinancialAccountID WHERE financial_account_id IS 
NULL");
+
+}

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

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