Merge pull request #2165 from davecivicrm/CRM-13890
[civicrm-core.git] / CRM / Upgrade / Incremental / php / FourFour.php
CommitLineData
a47a2f90 1<?php
2/*
3 +--------------------------------------------------------------------+
232624b1 4 | CiviCRM version 4.4 |
a47a2f90 5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License along with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
25*/
26
27/**
28 *
29 * @package CRM
30 * @copyright CiviCRM LLC (c) 2004-2013
31 * $Id$
32 *
33 */
34class CRM_Upgrade_Incremental_php_FourFour {
35 const BATCH_SIZE = 5000;
36
37 function verifyPreDBstate(&$errors) {
38 return TRUE;
39 }
40
41 /**
42 * Compute any messages which should be displayed beforeupgrade
43 *
44 * Note: This function is called iteratively for each upcoming
45 * revision to the database.
46 *
47 * @param $postUpgradeMessage string, alterable
48 * @param $rev string, a version number, e.g. '4.4.alpha1', '4.4.beta3', '4.4.0'
49 * @return void
50 */
51 function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL) {
52 }
53
54 /**
55 * Compute any messages which should be displayed after upgrade
56 *
57 * @param $postUpgradeMessage string, alterable
58 * @param $rev string, an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs
59 * @return void
60 */
61 function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
61320313 62 if ($rev == '4.4.1') {
634e1a1a
DL
63 $config = CRM_Core_Config::singleton();
64 if (!empty($config->useIDS)) {
61320313 65 $postUpgradeMessage .= '<br />' . ts("The setting to skip IDS check has been removed. Your site has this configured in civicrm.settings.php but it will no longer work. Instead, use the new permission 'skip IDS check' to bypass the IDS system.");
634e1a1a
DL
66 }
67 }
9e58e6ff 68 if ($rev == '4.4.3') {
09163e8a 69 $postUpgradeMessage .= '<br /><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></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).');
9e58e6ff 70 }
a47a2f90 71 }
72
73 function upgrade_4_4_alpha1($rev) {
634e1a1a 74 // task to process sql
d1401e86 75 $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.4.alpha1')), 'task_4_4_x_runSql', $rev);
a47a2f90 76
77 // Consolidate activity contacts CRM-12274.
d1401e86 78 $this->addTask('Consolidate activity contacts', 'activityContacts');
a47a2f90 79
80 return TRUE;
81 }
82
7ee2786a 83 function upgrade_4_4_beta1($rev) {
d1401e86 84 $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.4.beta1')), 'task_4_4_x_runSql', $rev);
7ee2786a 85
56d4e0ab 86 // add new 'data' column in civicrm_batch
87 $query = 'ALTER TABLE civicrm_batch ADD data LONGTEXT NULL COMMENT "cache entered data"';
d427e40e 88 CRM_Core_DAO::executeQuery($query, array(), TRUE, NULL, FALSE, FALSE);
56d4e0ab 89
7ee2786a 90 // check if batch entry data exists in civicrm_cache table
f1811020 91 $query = 'SELECT path, data FROM civicrm_cache WHERE group_name = "batch entry"';
7ee2786a 92 $dao = CRM_Core_DAO::executeQuery($query);
93 while ($dao->fetch()) {
94 // get batch id $batchId[2]
95 $batchId = explode('-', $dao->path);
96 $data = unserialize($dao->data);
97
98 // move the data to civicrm_batch table
99 CRM_Core_DAO::setFieldValue('CRM_Batch_DAO_Batch', $batchId[2], 'data', json_encode(array('values' => $data)));
100 }
101
102 // delete entries from civicrm_cache table
f1811020 103 $query = 'DELETE FROM civicrm_cache WHERE group_name = "batch entry"';
7ee2786a 104 CRM_Core_DAO::executeQuery($query);
ba457d64 105
d1401e86 106 $this->addTask('Migrate custom word-replacements', 'wordReplacements');
7ee2786a 107 }
108
6b12405a 109 function upgrade_4_4_1($rev) {
95c0a77c 110 $config = CRM_Core_Config::singleton();
6b12405a
RN
111 // CRM-13327 upgrade handling for the newly added name badges
112 $ogID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'name_badge', 'id', 'name');
113 $nameBadges = array_flip(array_values(CRM_Core_BAO_OptionValue::getOptionValuesAssocArrayFromName('name_badge')));
114 unset($nameBadges['Avery 5395']);
115 if (!empty($nameBadges)) {
116 $dimension = '{"paper-size":"a4","orientation":"portrait","font-name":"times","font-size":6,"font-style":"","NX":2,"NY":4,"metric":"mm","lMargin":6,"tMargin":19,"SpaceX":0,"SpaceY":0,"width":100,"height":65,"lPadding":0,"tPadding":0}';
117 $query = "UPDATE civicrm_option_value
118 SET value = '{$dimension}'
119 WHERE option_group_id = %1 AND name = 'Fattorini Name Badge 100x65'";
120
121 CRM_Core_DAO::executeQuery($query, array(1 => array($ogID, 'Integer')));
122 }
123 else {
124 $dimensions = array(
125 1 => '{"paper-size":"a4","orientation":"landscape","font-name":"times","font-size":6,"font-style":"","NX":2,"NY":1,"metric":"mm","lMargin":25,"tMargin":27,"SpaceX":0,"SpaceY":35,"width":106,"height":150,"lPadding":5,"tPadding":5}',
126 2 => '{"paper-size":"a4","orientation":"portrait","font-name":"times","font-size":6,"font-style":"","NX":2,"NY":4,"metric":"mm","lMargin":6,"tMargin":19,"SpaceX":0,"SpaceY":0,"width":100,"height":65,"lPadding":0,"tPadding":0}',
127 3 => '{"paper-size":"a4","orientation":"portrait","font-name":"times","font-size":6,"font-style":"","NX":2,"NY":2,"metric":"mm","lMargin":10,"tMargin":28,"SpaceX":0,"SpaceY":0,"width":96,"height":121,"lPadding":5,"tPadding":5}',
128 );
129 $insertStatements = array(
130 1 => "($ogID, %1, '{$dimensions[1]}', %1, NULL, 0, NULL, 2, NULL, 0, 0, 1, NULL, NULL)",
131 2 => "($ogID, %2, '{$dimensions[2]}', %2, NULL, 0, NULL, 3, NULL, 0, 0, 1, NULL, NULL)",
132 3 => "($ogID, %3, '{$dimensions[3]}', %3, NULL, 0, NULL, 4, NULL, 0, 0, 1, NULL, NULL)",
133 );
134
135 $queryParams = array(
136 1 => array('A6 Badge Portrait 150x106', 'String'),
137 2 => array('Fattorini Name Badge 100x65', 'String'),
138 3 => array('Hanging Badge 3-3/4" x 4-3"/4', 'String'),
139 );
3a88e331 140
6b12405a
RN
141 foreach ($insertStatements as $values) {
142 $query = 'INSERT INTO civicrm_option_value (`option_group_id`, `label`, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, `description`, `is_optgroup`, `is_reserved`, `is_active`, `component_id`, `visibility_id`) VALUES' . $values;
143 CRM_Core_DAO::executeQuery($query, $queryParams);
144 }
145 }
146
95c0a77c
CW
147 // CRM-12578 - Prior to this version a CSS file under drupal would disable core css
148 if (!empty($config->customCSSURL) && strpos($config->userFramework, 'Drupal') === 0) {
149 // The new setting doesn't exist yet - need to create it first
150 CRM_Core_BAO_Setting::updateSettingsFromMetaData();
151 CRM_Core_BAO_Setting::setItem('1', CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'disable_core_css');
152 }
153
fcab62b4
CW
154 // CRM-13701 - Fix $config->timeInputFormat
155 $sql = "
156 SELECT time_format
157 FROM civicrm_preferences_date
158 WHERE time_format IS NOT NULL
159 AND time_format <> ''
160 LIMIT 1
161 ";
162 $timeInputFormat = CRM_Core_DAO::singleValueQuery($sql);
163 if ($timeInputFormat && $timeInputFormat != $config->timeInputFormat) {
164 $params = array('timeInputFormat' => $timeInputFormat);
165 CRM_Core_BAO_ConfigSetting::add($params);
166 }
167
187e382a
PJ
168 // CRM-13698 - add 'Available' and 'No-show' activity statuses
169 $insertStatus = array();
170 $nsinc = $avinc = $inc = 0;
171 if (!CRM_Core_OptionGroup::getValue('activity_status', 'Available', 'name')) {
172 $insertStatus[] = "(%1, 'Available', %2, 'Available', NULL, 0, NULL, %3, 0, 0, 1, NULL, NULL)";
173 $avinc = $inc = 1;
174 }
5b8e40ab
CW
175 if (!CRM_Core_OptionGroup::getValue('activity_status', 'No_show', 'name')) {
176 $insertStatus[] = "(%1, 'No-show', %4, 'No_show', NULL, 0, NULL, %5, 0, 0, 1, NULL, NULL)";
187e382a
PJ
177 $nsinc = $inc + 1;
178 }
179 if (!empty($insertStatus)) {
180 $acOptionGroupID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'activity_status', 'id', 'name');
181 $maxVal = CRM_Core_DAO::singleValueQuery("SELECT MAX(ROUND(op.value)) FROM civicrm_option_value op WHERE op.option_group_id = $acOptionGroupID");
182 $maxWeight = CRM_Core_DAO::singleValueQuery("SELECT MAX(weight) FROM civicrm_option_value WHERE option_group_id = $acOptionGroupID");
183
184 $p[1] = array($acOptionGroupID, 'Integer');
185 if ($avinc) {
186 $p[2] = array($avinc+$maxVal, 'Integer');
187 $p[3] = array($avinc+$maxWeight, 'Integer');
188 }
189 if ($nsinc) {
190 $p[4] = array($nsinc+$maxVal, 'Integer');
191 $p[5] = array($nsinc+$maxWeight, 'Integer');
192 }
193 $insertStatus = implode(',', $insertStatus);
194
195 $sql = "
196INSERT INTO
197 civicrm_option_value (`option_group_id`, label, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, `is_optgroup`, `is_reserved`, `is_active`, `component_id`, `visibility_id`)
198VALUES {$insertStatus}";
199 CRM_Core_DAO::executeQuery($sql, $p);
200 }
201
6b12405a 202 $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => '4.4.1')), 'task_4_4_x_runSql', $rev);
44379fac 203 $this->addTask('Patch word-replacement schema', 'wordReplacements_patch', $rev);
6b12405a
RN
204 }
205
a47a2f90 206 /**
207 * Update activity contacts CRM-12274
208 *
209 * @return bool TRUE for success
210 */
211 static function activityContacts(CRM_Queue_TaskContext $ctx) {
212 $upgrade = new CRM_Upgrade_Form();
127ca309 213
e7e657f0 214 $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
b95507ab 215 $ovValue[] = $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
216 $ovValue[] = $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
217 $ovValue[] = $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
634e1a1a 218
9744c42c 219 $optionGroupID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'activity_contacts', 'id', 'name');
b95507ab 220 if (!empty($ovValue)) {
221 $ovValues = implode(', ', $ovValue);
222 $query = "
634e1a1a 223UPDATE civicrm_option_value
b95507ab 224SET is_reserved = 1
225WHERE option_group_id = {$optionGroupID} AND value IN ($ovValues)";
226
227 $dao = CRM_Core_DAO::executeQuery($query);
228 }
229
9744c42c 230 if (!$assigneeID) {
b95507ab 231 $assigneeID = 1;
9744c42c 232 $value[] = "({$optionGroupID}, 'Activity Assignees', 1, 'Activity Assignees', 1, 1, 1)";
233 }
234 if (!$sourceID) {
b95507ab 235 $sourceID = 2;
9744c42c 236 $value[] = "({$optionGroupID}, 'Activity Source', 2, 'Activity Source', 2, 1, 1)";
237 }
238 if (!$targetID) {
b95507ab 239 $targetID = 3;
9744c42c 240 $value[] = "({$optionGroupID}, 'Activity Targets', 3, 'Activity Targets', 3, 1, 1)";
241 }
242
243 if (!$assigneeID || !$sourceID || !$targetID ) {
634e1a1a 244 $insert = "
9744c42c 245INSERT INTO civicrm_option_value
246(option_group_id, label, value, name, weight, is_reserved, is_active)
247VALUES
248
249";
250 $values = implode(', ', $value);
251 $query = $insert . $values;
252 $dao = CRM_Core_DAO::executeQuery($query);
253 }
254
3a88e331
DL
255 // sometimes an user does not make a clean backup and the above table
256 // already exists, so lets delete this table - CRM-13665
187e382a 257 $query = "DROP TABLE IF EXISTS civicrm_activity_contact";
3a88e331 258 $dao = CRM_Core_DAO::executeQuery($query);
9744c42c 259
a47a2f90 260 $query = "
127ca309 261CREATE TABLE IF NOT EXISTS civicrm_activity_contact (
262 id int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Activity contact id',
263 activity_id int(10) unsigned NOT NULL COMMENT 'Foreign key to the activity for this record.',
264 contact_id int(10) unsigned NOT NULL COMMENT 'Foreign key to the contact for this record.',
265 record_type_id int(10) unsigned DEFAULT NULL COMMENT 'The record type id for this row',
266 PRIMARY KEY (id),
267 UNIQUE KEY UI_activity_contact (contact_id,activity_id,record_type_id),
268 KEY FK_civicrm_activity_contact_activity_id (activity_id)
a47a2f90 269) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
270";
271
272 $dao = CRM_Core_DAO::executeQuery($query);
634e1a1a 273
3a88e331 274
634e1a1a 275 $query = "
127ca309 276INSERT INTO civicrm_activity_contact (activity_id, contact_id, record_type_id)
277SELECT activity_id, target_contact_id, {$targetID} as record_type_id
a47a2f90 278FROM civicrm_activity_target";
279
280 $dao = CRM_Core_DAO::executeQuery($query);
281
634e1a1a 282 $query = "
127ca309 283INSERT INTO civicrm_activity_contact (activity_id, contact_id, record_type_id)
284SELECT activity_id, assignee_contact_id, {$assigneeID} as record_type_id
a47a2f90 285FROM civicrm_activity_assignment";
286 $dao = CRM_Core_DAO::executeQuery($query);
634e1a1a 287
a47a2f90 288 $query = "
127ca309 289 INSERT INTO civicrm_activity_contact (activity_id, contact_id, record_type_id)
290SELECT id, source_contact_id, {$sourceID} as record_type_id
634e1a1a 291FROM civicrm_activity
a47a2f90 292WHERE source_contact_id IS NOT NULL";
293
294 $dao = CRM_Core_DAO::executeQuery($query);
295
296 $query = "DROP TABLE civicrm_activity_target";
297 $dao = CRM_Core_DAO::executeQuery($query);
298
299 $query = "DROP TABLE civicrm_activity_assignment";
300 $dao = CRM_Core_DAO::executeQuery($query);
301
634e1a1a 302 $query = "ALTER TABLE civicrm_activity
a47a2f90 303 DROP FOREIGN KEY FK_civicrm_activity_source_contact_id";
634e1a1a 304
a47a2f90 305 $dao = CRM_Core_DAO::executeQuery($query);
306
307 $query = "ALTER TABLE civicrm_activity DROP COLUMN source_contact_id";
308 $dao = CRM_Core_DAO::executeQuery($query);
309
ba457d64
TO
310 return TRUE;
311 }
312
313 /**
314 * Migrate word-replacements from $config to civicrm_word_replacement
315 *
316 * @return bool TRUE for success
317 * @see http://issues.civicrm.org/jira/browse/CRM-13187
318 */
319 static function wordReplacements(CRM_Queue_TaskContext $ctx) {
320 $query = "
7c312eca
TO
321CREATE TABLE IF NOT EXISTS `civicrm_word_replacement` (
322 `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Word replacement ID',
02ffc0f2
TO
323 `find_word` varchar(255) COLLATE utf8_bin COMMENT 'Word which need to be replaced',
324 `replace_word` varchar(255) COLLATE utf8_bin COMMENT 'Word which will replace the word in find',
7c312eca
TO
325 `is_active` tinyint COMMENT 'Is this entry active?',
326 `match_type` enum('wildcardMatch', 'exactMatch') DEFAULT 'wildcardMatch',
327 `domain_id` int unsigned COMMENT 'FK to Domain ID. This is for Domain specific word replacement',
328 PRIMARY KEY ( `id` ),
44379fac 329 UNIQUE INDEX `UI_domain_find` (domain_id, find_word),
7c312eca
TO
330 CONSTRAINT FK_civicrm_word_replacement_domain_id FOREIGN KEY (`domain_id`) REFERENCES `civicrm_domain`(`id`)
331) ENGINE=InnoDB DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ;
332 ";
ba457d64
TO
333 $dao = CRM_Core_DAO::executeQuery($query);
334
daa14c0c 335 self::rebuildWordReplacementTable();
ba457d64 336 return TRUE;
a47a2f90 337 }
338
44379fac
TO
339 /**
340 * Fix misconfigured constraints created in 4.4.0. To distinguish the good
341 * and bad configurations, we change the constraint name from "UI_find"
342 * (the original name in 4.4.0) to "UI_domain_find" (the new name in
343 * 4.4.1).
344 *
345 * @return bool TRUE for success
346 * @see http://issues.civicrm.org/jira/browse/CRM-13655
347 */
348 static function wordReplacements_patch(CRM_Queue_TaskContext $ctx, $rev) {
349 if (CRM_Core_DAO::checkConstraintExists('civicrm_word_replacement', 'UI_find')) {
350 CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_word_replacement DROP FOREIGN KEY FK_civicrm_word_replacement_domain_id;");
351 CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_word_replacement DROP KEY FK_civicrm_word_replacement_domain_id;");
352 CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_word_replacement DROP KEY UI_find;");
353 CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_word_replacement MODIFY COLUMN `find_word` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT 'Word which need to be replaced';");
354 CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_word_replacement MODIFY COLUMN `replace_word` varchar(255) COLLATE utf8_bin DEFAULT NULL COMMENT 'Word which will replace the word in find';");
355 CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_word_replacement ADD CONSTRAINT UI_domain_find UNIQUE KEY `UI_domain_find` (`domain_id`,`find_word`);");
356 CRM_Core_DAO::executeQuery("ALTER TABLE civicrm_word_replacement ADD CONSTRAINT FK_civicrm_word_replacement_domain_id FOREIGN KEY (`domain_id`) REFERENCES `civicrm_domain` (`id`);");
357 }
358 return TRUE;
359 }
360
a47a2f90 361 /**
362 * (Queue Task Callback)
363 */
364 static function task_4_4_x_runSql(CRM_Queue_TaskContext $ctx, $rev) {
365 $upgrade = new CRM_Upgrade_Form();
366 $upgrade->processSQL($rev);
367
368 return TRUE;
369 }
370
371 /**
372 * Syntatic sugar for adding a task which (a) is in this class and (b) has
373 * a high priority.
374 *
375 * After passing the $funcName, you can also pass parameters that will go to
376 * the function. Note that all params must be serializable.
377 */
378 protected function addTask($title, $funcName) {
379 $queue = CRM_Queue_Service::singleton()->load(array(
380 'type' => 'Sql',
381 'name' => CRM_Upgrade_Form::QUEUE_NAME,
382 ));
383
384 $args = func_get_args();
385 $title = array_shift($args);
386 $funcName = array_shift($args);
387 $task = new CRM_Queue_Task(
388 array(get_class($this), $funcName),
389 $args,
390 $title
391 );
392 $queue->createItem($task, array('weight' => -1));
393 }
cbe56ea6
TO
394
395 /**
daa14c0c
TO
396 * Get all the word-replacements stored in config-arrays
397 * and convert them to params for the WordReplacement.create API.
398 *
0f65e834
TO
399 * Note: This function is duplicated in CRM_Core_BAO_WordReplacement and
400 * CRM_Upgrade_Incremental_php_FourFour to ensure that the incremental upgrade
401 * step behaves consistently even as the BAO evolves in future versions.
402 * However, if there's a bug in here prior to 4.4.0, we should apply the
403 * bugfix in both places.
404 *
63b71ea8 405 * @param bool $rebuildEach whether to perform rebuild after each individual API call
daa14c0c
TO
406 * @return array Each item is $params for WordReplacement.create
407 * @see CRM_Core_BAO_WordReplacement::convertConfigArraysToAPIParams
cbe56ea6 408 */
63b71ea8 409 static function getConfigArraysAsAPIParams($rebuildEach) {
cbe56ea6 410 $wordReplacementCreateParams = array();
cbe56ea6 411 // get all domains
daa14c0c
TO
412 $result = civicrm_api3('domain', 'get', array(
413 'return' => array('locale_custom_strings'),
414 ));
cbe56ea6
TO
415 if (!empty($result["values"])) {
416 foreach ($result["values"] as $value) {
417 $params = array();
cbe56ea6 418 $params["domain_id"] = $value["id"];
63b71ea8 419 $params["options"] = array('wp-rebuild' => $rebuildEach);
cbe56ea6
TO
420 // unserialize word match string
421 $localeCustomArray = unserialize($value["locale_custom_strings"]);
422 if (!empty($localeCustomArray)) {
423 $wordMatchArray = array();
7c312eca 424 // Traverse Language array
cbe56ea6 425 foreach ($localeCustomArray as $localCustomData) {
7c312eca
TO
426 // Traverse status array "enabled" "disabled"
427 foreach ($localCustomData as $status => $matchTypes) {
428 $params["is_active"] = ($status == "enabled")?TRUE:FALSE;
429 // Traverse Match Type array "wildcardMatch" "exactMatch"
430 foreach ($matchTypes as $matchType => $words) {
431 $params["match_type"] = $matchType;
432 foreach ($words as $word => $replace) {
433 $params["find_word"] = $word;
434 $params["replace_word"] = $replace;
435 $wordReplacementCreateParams[] = $params;
436 }
437 }
cbe56ea6
TO
438 }
439 }
440 }
441 }
442 }
443 return $wordReplacementCreateParams;
8d57c529 444 }
ba457d64 445
daa14c0c
TO
446 /**
447 * Get all the word-replacements stored in config-arrays
448 * and write them out as records in civicrm_word_replacement.
0f65e834
TO
449 *
450 * Note: This function is duplicated in CRM_Core_BAO_WordReplacement and
451 * CRM_Upgrade_Incremental_php_FourFour to ensure that the incremental upgrade
452 * step behaves consistently even as the BAO evolves in future versions.
453 * However, if there's a bug in here prior to 4.4.0, we should apply the
454 * bugfix in both places.
daa14c0c
TO
455 */
456 public static function rebuildWordReplacementTable() {
457 civicrm_api3('word_replacement', 'replace', array(
458 'options' => array('match' => array('domain_id', 'find_word')),
459 'values' => self::getConfigArraysAsAPIParams(FALSE),
460 ));
461 CRM_Core_BAO_WordReplacement::rebuild();
ba457d64 462 }
a47a2f90 463}