From 8d57c529618bd557f7f3427e626444e19bbdb7e2 Mon Sep 17 00:00:00 2001 From: vivekarora Date: Wed, 28 Aug 2013 15:32:02 +0530 Subject: [PATCH] CRM-13187 - migrate settings from domains table to word replacement table ---------------------------------------- * CRM-13187: hrui: Change breadcrumb from "CiviCRM" to "CiviHR" http://issues.civicrm.org/jira/browse/CRM-13187 --- CRM/Upgrade/Incremental/php/FourFour.php | 65 ++++++++++++++++++++---- 1 file changed, 55 insertions(+), 10 deletions(-) diff --git a/CRM/Upgrade/Incremental/php/FourFour.php b/CRM/Upgrade/Incremental/php/FourFour.php index 8ed782ddfe..3bbf99f983 100644 --- a/CRM/Upgrade/Incremental/php/FourFour.php +++ b/CRM/Upgrade/Incremental/php/FourFour.php @@ -177,18 +177,25 @@ WHERE source_contact_id IS NOT NULL"; $dao = CRM_Core_DAO::executeQuery($query); $query = " -CREATE TABLE IF NOT EXISTS 'civicrm_word_replacement' ( - 'id' int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Word replacement ID', - 'find_word' varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Word which need to be replaced', - 'replace_word' varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Word which will replace the word in find', - 'is_active' tinyint(4) DEFAULT NULL COMMENT 'Is this entry active?', - 'domain_id' int(10) unsigned DEFAULT NULL COMMENT 'FK to Domain ID. This is for Domain specific word replacement', - PRIMARY KEY ('id'), - UNIQUE KEY 'UI_find' ('find_word'), - KEY 'FK_civicrm_word_replacement_domain_id' ('domain_id') +CREATE TABLE IF NOT EXISTS civicrm_word_replacement ( + id int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Word replacement ID', + find_word varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Word which need to be replaced', + replace_word varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Word which will replace the word in find', + is_active tinyint(4) DEFAULT NULL COMMENT 'Is this entry active?', + domain_id int(10) unsigned DEFAULT NULL COMMENT 'FK to Domain ID. This is for Domain specific word replacement', + PRIMARY KEY (id), + UNIQUE KEY UI_find (find_word), + KEY FK_civicrm_word_replacement_domain_id (domain_id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=4"; $dao = CRM_Core_DAO::executeQuery($query); - + + // get word replacement create params + $wordReplacementCreateParams = self::getWordReplacementCreateParams(); + if(!empty($wordReplacementCreateParams)) { + foreach($wordReplacementCreateParams as $wordReplacementCreateParam) { + $result = civicrm_api('word_replacement', 'create', $wordReplacementCreateParam); + } + } return TRUE; } @@ -225,4 +232,42 @@ CREATE TABLE IF NOT EXISTS 'civicrm_word_replacement' ( ); $queue->createItem($task, array('weight' => -1)); } + + /* + * Function will retrun Word Replacement for word_replacement create API + */ + + static function getWordReplacementCreateParams() { + $wordReplacementCreateParams = array(); + $params = array( + 'version' => 3 + ); + // get all domains + $result = civicrm_api('domain', 'get', $params); + if (!empty($result["values"])) { + foreach ($result["values"] as $value) { + $params = array(); + $params["version"] = 3; + $params["is_active"] = true; + $params["domain_id"] = $value["id"]; + // unserialize word match string + $localeCustomArray = unserialize($value["locale_custom_strings"]); + if(!empty($localeCustomArray)) { + $wordMatchArray = array(); + foreach ($localeCustomArray as $localCustomData) { + $wordMatchArray = $localCustomData["enabled"]["wildcardMatch"]; + } + + if(!empty($wordMatchArray)) { + foreach ($wordMatchArray as $word=>$replace) { + $params["find_word"] = $word; + $params["replace_word"] = $replace; + $wordReplacementCreateParams[] = $params; + } + } + } + } + } + return $wordReplacementCreateParams; + } } -- 2.25.1