From 505cf9f9213aaeec72ff848e54dcb29abf1f107f Mon Sep 17 00:00:00 2001
From: Pratik Joshi <pratik.joshi@webaccess.co.in>
Date: Wed, 13 Mar 2013 15:25:50 +0530
Subject: [PATCH] CRM-12084 fix

---
 CRM/Upgrade/Incremental/php/FourThree.php | 28 +++++++++++++++++++++--
 sql/civicrm_generated.mysql               |  2 +-
 xml/version.xml                           |  2 +-
 3 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/CRM/Upgrade/Incremental/php/FourThree.php b/CRM/Upgrade/Incremental/php/FourThree.php
index 3804386449..61beb1133b 100644
--- a/CRM/Upgrade/Incremental/php/FourThree.php
+++ b/CRM/Upgrade/Incremental/php/FourThree.php
@@ -39,6 +39,31 @@ class CRM_Upgrade_Incremental_php_FourThree {
     return TRUE;
   }
 
+  /**
+   * Compute any messages which should be displayed beforeupgrade
+   *
+   * Note: This function is called iteratively for each upcoming
+   * revision to the database.
+   *
+   * @param $postUpgradeMessage string, alterable
+   * @param $rev string, a version number, e.g. '4.3.alpha1', '4.3.beta3', '4.3.0'
+   * @return void
+   */
+  function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL) {
+    if (version_compare($rev, '4.3.beta3') >= 0) {
+      //CRM-12084
+      //sql for checking orphaned contribution records
+      $sql = "SELECT COUNT(ct.id) FROM civicrm_contribution ct LEFT JOIN civicrm_contact c ON ct.contact_id = c.id WHERE c.id IS NULL";
+      $count = CRM_Core_DAO::singleValueQuery($sql, array(), TRUE, FALSE);
+
+      if ($count > 0) {
+        $error = ts("There is a data integrity issue with this CiviCRM database. It contains %1 contribution records which are linked to contact records that have been deleted. You will need to correct this manually before you can run the upgrade. Use the following MySQL query to identify the problem records: %2 These records will need to be deleted or linked to an existing contact record.", array(1 => $count, 2 => '<em>SELECT ct.* FROM civicrm_contribution ct LEFT JOIN civicrm_contact c ON ct.contact_id = c.id WHERE c.id IS NULL;</em>'));
+        CRM_Core_Error::fatal($error);
+        return FALSE;
+      }
+    }
+  }
+
   /**
    * Compute any messages which should be displayed after upgrade
    *
@@ -66,7 +91,7 @@ class CRM_Upgrade_Incremental_php_FourThree {
         $postUpgradeMessage .= '<br />' . ts("A new organization contact has been added as the default domain contact using the information from your Organization Address and Contact Info settings: '{$orgName}'.");
       }
       elseif ($context == 'merged') {
-        $postUpgradeMessage .= '<br />' . ts("The existing organization contact record for '{$orgName}' has marked as the default domain contact, and has been updated with information from your Organization Address and Contact Info settings.");
+        $postUpgradeMessage .= '<br />' . ts("The existing organization contact record for '{$orgName}' has been marked as the default domain contact, and has been updated with information from your Organization Address and Contact Info settings.");
       }
 
       $providerExists = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_sms_provider LIMIT 1");
@@ -98,7 +123,6 @@ WHERE    entity_value = '' OR entity_value IS NULL
     if ($rev == '4.3.beta2') {
       $postUpgradeMessage .= '<br />' . ts('Default versions of the following System Workflow Message Templates have been modified to handle new functionality: <ul><li>Events - Registration Confirmation and Receipt (on-line)</li><li>Events - Registration Confirmation and Receipt (off-line)</li><li>Pledges - Acknowledgement</li><li>Pledges - Payment Reminder</li><li>Contributions - Receipt (off-line)</li><li>Contributions - Receipt (on-line)</li><li>Memberships - Signup and Renewal Receipts (off-line)</li><li>Memberships - Receipt (on-line)</li><li>Personal Campaign Pages - Admin Notification</li></ul> 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).');
     }
-
   }
 
   function upgrade_4_3_alpha1($rev) {
diff --git a/sql/civicrm_generated.mysql b/sql/civicrm_generated.mysql
index 9d37c8f4d6..c01374e682 100644
--- a/sql/civicrm_generated.mysql
+++ b/sql/civicrm_generated.mysql
@@ -392,7 +392,7 @@ UNLOCK TABLES;
 
 LOCK TABLES `civicrm_domain` WRITE;
 /*!40000 ALTER TABLE `civicrm_domain` DISABLE KEYS */;
-INSERT INTO `civicrm_domain` (`id`, `name`, `description`, `config_backend`, `version`, `contact_id`, `locales`, `locale_custom_strings`) VALUES (1,'Default Domain Name',NULL,NULL,'4.3.beta2',1,NULL,NULL);
+INSERT INTO `civicrm_domain` (`id`, `name`, `description`, `config_backend`, `version`, `contact_id`, `locales`, `locale_custom_strings`) VALUES (1,'Default Domain Name',NULL,NULL,'4.3.beta3',1,NULL,NULL);
 /*!40000 ALTER TABLE `civicrm_domain` ENABLE KEYS */;
 UNLOCK TABLES;
 
diff --git a/xml/version.xml b/xml/version.xml
index d8881c7948..4ad474563e 100644
--- a/xml/version.xml
+++ b/xml/version.xml
@@ -1,4 +1,4 @@
 <?xml version="1.0" encoding="iso-8859-1" ?>
 <version>
-    <version_no>4.3.beta2</version_no>
+    <version_no>4.3.beta3</version_no>
 </version>
-- 
GitLab