From e3a96c9bb8ffa6badd94a711dda4accef0368437 Mon Sep 17 00:00:00 2001 From: Dave Greenberg Date: Tue, 26 Mar 2013 22:07:43 -0700 Subject: [PATCH] CRM-12155 Moved check for orphaned financial records to postUpdateMessage since there is apparently no harm in leaving them in the DB and the queries to clean them up are complex.` --- CRM/Upgrade/Incremental/php/FourThree.php | 87 ++++++++++++----------- xml/version.xml | 2 +- 2 files changed, 46 insertions(+), 43 deletions(-) diff --git a/CRM/Upgrade/Incremental/php/FourThree.php b/CRM/Upgrade/Incremental/php/FourThree.php index b6d5d09b71..bfbff245b5 100644 --- a/CRM/Upgrade/Incremental/php/FourThree.php +++ b/CRM/Upgrade/Incremental/php/FourThree.php @@ -73,48 +73,6 @@ class CRM_Upgrade_Incremental_php_FourThree { CRM_Core_Error::fatal('Please reset the Drupal cache (Administer => Site Configuration => Performance => Clear cached data))'); } } - // CRM-12155 - if ($rev == '4.3.beta5') { - $query = "SELECT ceft.id FROM `civicrm_financial_trxn` cft -LEFT JOIN civicrm_entity_financial_trxn ceft -ON ceft.financial_trxn_id = cft.id AND ceft.entity_table = 'civicrm_contribution' -LEFT JOIN civicrm_contribution cc ON cc.id = ceft.entity_id AND ceft.entity_table = 'civicrm_contribution' -WHERE cc.id IS NULL"; - - $dao = CRM_Core_DAO::executeQuery($query); - $isOrphanData = TRUE; - if (!$dao->N) { - $query = "SELECT cli.id FROM civicrm_line_item cli -LEFT JOIN civicrm_contribution cc ON cli.entity_id = cc.id AND cli.entity_table = 'civicrm_contribution' -LEFT JOIN civicrm_participant cp ON cli.entity_id = cp.id AND cli.entity_table = 'civicrm_participant' -WHERE CASE WHEN cli.entity_table = 'civicrm_contribution' -THEN cc.id IS NULL -ELSE cp.id IS NULL -END"; - $dao = CRM_Core_DAO::executeQuery($query); - if (!$dao->N) { - $revPattern = '/^((\d{1,2})\.\d{1,2})\.(\d{1,2}|\w{4,7})?$/i'; - preg_match($revPattern, $currentVer, $version); - if ($version[1] >= 4.3) { - $query = "SELECT cfi.id FROM civicrm_financial_item cfi -LEFT JOIN civicrm_entity_financial_trxn ceft ON ceft.entity_table = 'civicrm_financial_item' and cfi.id = ceft.entity_id -WHERE ceft.entity_id IS NULL;"; - $dao = CRM_Core_DAO::executeQuery($query); - if (!$dao->N) { - $isOrphanData = FALSE; - } - } - else { - $isOrphanData = FALSE; - } - } - } - - if ($isOrphanData) { - $preUpgradeMessage = "
" . ts('Your database contains orphaned financial records related to deleted contributions. Refer to this wiki page for instructions on repairing your database so that you can run the upgrade successfully. - ', array( 1 => 'http://wiki.civicrm.org/confluence/display/CRMDOC43/Database+repair+for+4.3+upgrades')) . ""; - } - } } /** @@ -176,6 +134,51 @@ WHERE entity_value = '' OR entity_value IS NULL if ($rev == '4.3.beta2') { $postUpgradeMessage .= '
' . ts('Default versions of the following System Workflow Message Templates have been modified to handle new functionality: If you have modified these templates, please review the new default versions and implement updates as needed to your copies (Administer > Communications > Message Templates > System Workflow Messages).'); } + + if ($rev == '4.3.beta5') { + $postUpgradeMessage .= '
' . ts("If you are interested in trying out the new Accounting Integration features, please review user permissions and assign the new 'manual batch' permissions as appropriate."); + + // CRM-12155 + $query = "SELECT ceft.id FROM `civicrm_financial_trxn` cft +LEFT JOIN civicrm_entity_financial_trxn ceft +ON ceft.financial_trxn_id = cft.id AND ceft.entity_table = 'civicrm_contribution' +LEFT JOIN civicrm_contribution cc ON cc.id = ceft.entity_id AND ceft.entity_table = 'civicrm_contribution' +WHERE cc.id IS NULL"; + + $dao = CRM_Core_DAO::executeQuery($query); + $isOrphanData = TRUE; + if (!$dao->N) { + $query = "SELECT cli.id FROM civicrm_line_item cli +LEFT JOIN civicrm_contribution cc ON cli.entity_id = cc.id AND cli.entity_table = 'civicrm_contribution' +LEFT JOIN civicrm_participant cp ON cli.entity_id = cp.id AND cli.entity_table = 'civicrm_participant' +WHERE CASE WHEN cli.entity_table = 'civicrm_contribution' +THEN cc.id IS NULL +ELSE cp.id IS NULL +END"; + $dao = CRM_Core_DAO::executeQuery($query); + if (!$dao->N) { + $revPattern = '/^((\d{1,2})\.\d{1,2})\.(\d{1,2}|\w{4,7})?$/i'; + preg_match($revPattern, $currentVer, $version); + if ($version[1] >= 4.3) { + $query = "SELECT cfi.id FROM civicrm_financial_item cfi +LEFT JOIN civicrm_entity_financial_trxn ceft ON ceft.entity_table = 'civicrm_financial_item' and cfi.id = ceft.entity_id +WHERE ceft.entity_id IS NULL;"; + $dao = CRM_Core_DAO::executeQuery($query); + if (!$dao->N) { + $isOrphanData = FALSE; + } + } + else { + $isOrphanData = FALSE; + } + } + } + + if ($isOrphanData) { + $postUpgradeMessage .= "
" . ts('Your database contains extraneous financial records related to deleted contacts and contributions. These records should not affect the site and will not appear in reports, search results or exports. However you may wish to clean them up. Refer to this wiki page for details. + ', array( 1 => 'http://wiki.civicrm.org/confluence/display/CRMDOC/Clean+up+extraneous+financial+data+-+4.3+upgrades')) . ""; + } + } } function upgrade_4_3_alpha1($rev) { diff --git a/xml/version.xml b/xml/version.xml index 28cde99d76..eb05600951 100644 --- a/xml/version.xml +++ b/xml/version.xml @@ -1,4 +1,4 @@ - 4.3.beta4 + 4.3.beta5 -- 2.25.1