From 6b1e1a2cd6c31938140f7ee60e641b02095c2e7b Mon Sep 17 00:00:00 2001 From: monishdeb Date: Tue, 21 Jul 2015 12:00:15 +0530 Subject: [PATCH] Handle upgrade logic --- CRM/Contribute/Form/Contribution/Confirm.php | 1 - CRM/Upgrade/Incremental/php/FourSeven.php | 56 +++++++++++++++++++ .../Incremental/sql/4.7.alpha1.mysql.tpl | 11 +++- 3 files changed, 66 insertions(+), 2 deletions(-) diff --git a/CRM/Contribute/Form/Contribution/Confirm.php b/CRM/Contribute/Form/Contribution/Confirm.php index a148a96e6d..3d031f0080 100644 --- a/CRM/Contribute/Form/Contribution/Confirm.php +++ b/CRM/Contribute/Form/Contribution/Confirm.php @@ -467,7 +467,6 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr } $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE); $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE); - CRM_Core_Error::debug( '$params', $params ); if (!empty($params['onbehalf_profile_id'])) { diff --git a/CRM/Upgrade/Incremental/php/FourSeven.php b/CRM/Upgrade/Incremental/php/FourSeven.php index 0c043289a5..710854ac16 100644 --- a/CRM/Upgrade/Incremental/php/FourSeven.php +++ b/CRM/Upgrade/Incremental/php/FourSeven.php @@ -102,6 +102,8 @@ class CRM_Upgrade_Incremental_php_FourSeven extends CRM_Upgrade_Incremental_Base public function upgrade_4_7_alpha1($rev) { $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev); $this->addTask(ts('Add Getting Started dashlet to %1: SQL', array(1 => $rev)), 'addGettingStartedDashlet', $rev); + $this->addTask(ts('Migrate \'on behalf of\' information to module_data'), 'migrateOnBehalfOfInfo'); + $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'task_4_7_x_runSql', $rev); } /** @@ -143,4 +145,58 @@ FROM `civicrm_dashboard_contact` WHERE 1 GROUP BY contact_id"; return TRUE; } + /** + * Migrate on-behalf information to uf_join.module_data as on-behalf columns will be dropped + * on DB upgrade + * + * @param CRM_Queue_TaskContext $ctx + * + * @return bool + * TRUE for success + */ + public static function migrateOnBehalfOfInfo(CRM_Queue_TaskContext $ctx) { + + $ufGroupDAO = new CRM_Core_DAO_UFJoin(); + $ufGroupDAO->module = 'OnBehalf'; + $ufGroupDAO->find(TRUE); + + $query = "SELECT cp.*, uj.id as join_id + FROM civicrm_contribution_page cp + INNER JOIN civicrm_uf_join uj ON uj.entity_id = cp.id AND uj.module = 'OnBehalf'"; + $dao = CRM_Core_DAO::executeQuery($query); + + if ($dao->N) { + $domain = new CRM_Core_DAO_Domain(); + $domain->find(TRUE); + while ($dao->fetch()) { + $onBehalfParams['on_behalf'] = array('is_for_organization' => $dao->is_for_organization); + if ($domain->locales) { + $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales); + foreach ($locales as $locale) { + $for_organization = "for_organization_{$locale}"; + $onBehalfParams['on_behalf'] += array( + $locale => array( + 'for_organization' => $dao->$for_organization, + ), + ); + } + } + else { + $onBehalfParams['on_behalf'] += array( + 'default' => array( + 'for_organization' => $dao->for_organization, + ), + ); + } + $ufJoinParam = array( + 'id' => $dao->join_id, + 'module' => 'on_behalf', + 'module_data' => json_encode($onBehalfParams), + ); + CRM_Core_BAO_UFJoin::create($ufJoinParam); + } + } + + return TRUE; + } } diff --git a/CRM/Upgrade/Incremental/sql/4.7.alpha1.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.7.alpha1.mysql.tpl index 6e83b5981e..0797764857 100644 --- a/CRM/Upgrade/Incremental/sql/4.7.alpha1.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/4.7.alpha1.mysql.tpl @@ -88,7 +88,6 @@ CREATE TABLE IF NOT EXISTS `civicrm_status_pref` ( -- CRM-17005 UPDATE civicrm_country SET name = 'PALESTINIAN TERRITORY' WHERE name = 'PALESTINIAN TERRITORY, OCCUPIED'; - -- CRM-17145 update Activity detail data type ALTER TABLE `civicrm_activity` CHANGE `details` `details` LONGTEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT 'Details about the activity (agenda, notes, etc).'; @@ -166,3 +165,13 @@ INSERT INTO (@option_group_id_date_filter, '{ts escape="sql"}Next Quarter{/ts}', 'next.quarter', 'next.quarter', NULL, NULL, NULL,57, NULL, 0, 0, 1, NULL, NULL), (@option_group_id_date_filter, '{ts escape="sql"}Next Fiscal Year{/ts}', 'next.fiscal_year', 'next.fiscal_year', NULL, NULL, NULL,58, NULL, 0, 0, 1, NULL, NULL), (@option_group_id_date_filter, '{ts escape="sql"}Next Year{/ts}', 'next.year', 'next.year', NULL, NULL, NULL,59, NULL, 0, 0, 1, NULL, NULL); + +-- CRM-16873 +{if $multilingual} + {foreach from=$locales item=loc} + ALTER TABLE civicrm_contribution_page DROP for_organization_{$loc}; + {/foreach} +{else} + ALTER TABLE civicrm_contribution_page DROP for_organization; +{/if} +ALTER TABLE civicrm_contribution_page DROP is_for_organization; -- 2.25.1