From d2e8983dcf5b41f3acd47f7326239aa1c6dcdfd2 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Tue, 2 Jul 2013 16:30:22 +0530 Subject: [PATCH] -- worked on CRM-12156 ---------------------------------------- * CRM-12156: Cannot permanently delete a contact for whom a contribution has been created http://issues.civicrm.org/jira/browse/CRM-12156 --- CRM/Upgrade/Incremental/php/FourThree.php | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/CRM/Upgrade/Incremental/php/FourThree.php b/CRM/Upgrade/Incremental/php/FourThree.php index 8dd9dcfe8e..4b31d2bd27 100644 --- a/CRM/Upgrade/Incremental/php/FourThree.php +++ b/CRM/Upgrade/Incremental/php/FourThree.php @@ -299,6 +299,31 @@ ADD COLUMN premiums_nothankyou_label varchar(255) COLLATE utf8_unicode_ci DEFA function upgrade_4_3_4($rev) { $this->addTask(ts('Upgrade DB to 4.3.4: SQL'), 'task_4_3_x_runSql', $rev); } + + function upgrade_4_3_5($rev) { + // CRM-12156 + $config = CRM_Core_Config::singleton(); + $dbname = DB::parseDSN($config->dsn); + $sql = "SELECT DELETE_RULE +FROM information_schema.REFERENTIAL_CONSTRAINTS +WHERE CONSTRAINT_NAME = 'FK_civicrm_financial_item_contact_id' +AND CONSTRAINT_SCHEMA = %1"; + $params = array(1 => array($dbname['database'], 'String')); + $onDelete = CRM_Core_DAO::singleValueQuery($sql, $params, TRUE, FALSE); + + if ($onDelete != 'CASCADE') { + $query = "ALTER TABLE `civicrm_financial_item` +DROP FOREIGN KEY FK_civicrm_financial_item_contact_id, +DROP INDEX FK_civicrm_financial_item_contact_id;"; + CRM_Core_DAO::executeQuery($query, array(), TRUE, NULL, FALSE, FALSE); + $query = " +ALTER TABLE `civicrm_financial_item` +ADD CONSTRAINT `FK_civicrm_financial_item_contact_id` FOREIGN KEY (`contact_id`) REFERENCES `civicrm_contact` (`id`) ON DELETE CASCADE; +"; + CRM_Core_DAO::executeQuery($query, array(), TRUE, NULL, FALSE, FALSE); + } + $this->addTask(ts('Upgrade DB to 4.3.5: SQL'), 'task_4_3_x_runSql', $rev); + } //CRM-11636 function assignFinancialTypeToPriceRecords() { -- 2.25.1