Merge pull request #9792 from h-c-c/CRM-19945
[civicrm-core.git] / CRM / Upgrade / Incremental / php / FourSeven.php
CommitLineData
6cc25669
CW
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
0f03f337 6 | Copyright CiviCRM LLC (c) 2004-2017 |
6cc25669
CW
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/**
bf6a5362 28 * Upgrade logic for 4.7
6cc25669 29 */
bf6a5362 30class CRM_Upgrade_Incremental_php_FourSeven extends CRM_Upgrade_Incremental_Base {
6cc25669 31
f431d51f
J
32 /**
33 * Compute any messages which should be displayed beforeupgrade.
34 *
35 * Note: This function is called iteratively for each upcoming
36 * revision to the database.
37 *
3bdf1f3a 38 * @param string $preUpgradeMessage
f431d51f
J
39 * @param string $rev
40 * a version number, e.g. '4.4.alpha1', '4.4.beta3', '4.4.0'.
41 * @param null $currentVer
f431d51f
J
42 */
43 public function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL) {
44 if ($rev == '4.7.alpha1') {
f431d51f
J
45 // CRM-16478 Remove custom fatal error template path option
46 $config = CRM_Core_Config::singleton();
18b3bef6 47 if (!empty($config->fatalErrorTemplate) && $config->fatalErrorTemplate != 'CRM/common/fatal.tpl') {
f431d51f
J
48 $preUpgradeMessage .= '<p>' . ts('The custom fatal error template setting will be removed during the upgrade. You are currently using this custom template: %1 . Following the upgrade you will need to use the standard approach to overriding template files, as described in the documentation.', array(1 => $config->fatalErrorTemplate)) . '</p>';
49 }
f431d51f 50 }
a40fd1ac
CW
51 if ($rev == '4.7.alpha4') {
52 // CRM-17004 Warn of Moneris removal
87a33a95
CW
53 $count = 1;
54 // Query only works in 4.3+
55 if (version_compare($currentVer, "4.3.0") > 0) {
56 $count = CRM_Core_DAO::singleValueQuery("SELECT COUNT(id) FROM civicrm_payment_processor WHERE payment_processor_type_id IN (SELECT id FROM civicrm_payment_processor_type WHERE name = 'Moneris')");
57 }
58 if ($count && !function_exists('moneris_civicrm_managed')) {
a40fd1ac
CW
59 $preUpgradeMessage .= '<p>' . ts('The %1 payment processor is no longer bundled with CiviCRM. After upgrading you will need to install the extension to continue using it.', array(1 => 'Moneris')) . '</p>';
60 }
61 }
f431d51f
J
62 }
63
6cc25669
CW
64 /**
65 * Compute any messages which should be displayed after upgrade.
66 *
67 * @param string $postUpgradeMessage
68 * alterable.
69 * @param string $rev
70 * an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs.
6cc25669
CW
71 */
72 public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
6dbe2c23
CW
73 if ($rev == '4.7.alpha1') {
74 $config = CRM_Core_Config::singleton();
bf6a5362 75 // FIXME: Performing an upgrade step during postUpgrade message phase is probably bad
6dbe2c23
CW
76 $editor_id = self::updateWysiwyg();
77 $msg = NULL;
78 $ext_href = 'href="' . CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1') . '"';
79 $dsp_href = 'href="' . CRM_Utils_System::url('civicrm/admin/setting/preferences/display', 'reset=1') . '"';
80 $blog_href = 'href="https://civicrm.org/blogs/colemanw/big-changes-wysiwyg-editing-47"';
81 switch ($editor_id) {
82 // TinyMCE
83 case 1:
84 $msg = ts('Your configured editor "TinyMCE" is no longer part of the main CiviCRM download. To continue using it, visit the <a %1>Manage Extensions</a> page to download and install the TinyMCE extension.', array(1 => $ext_href));
85 break;
86
87 // Drupal/Joomla editor
88 case 3:
89 case 4:
90 $msg = ts('CiviCRM no longer integrates with the "%1 Default Editor." Your wysiwyg setting has been reset to the built-in CKEditor. <a %2>Learn more...</a>', array(1 => $config->userFramework, 2 => $blog_href));
91 break;
92 }
93 if ($msg) {
94 $postUpgradeMessage .= '<p>' . $msg . '</p>';
95 }
96 $postUpgradeMessage .= '<p>' . ts('CiviCRM now includes the easy-to-use CKEditor Configurator. To customize the features and display of your wysiwyg editor, visit the <a %1>Display Preferences</a> page. <a %2>Learn more...</a>', array(1 => $dsp_href, 2 => $blog_href)) . '</p>';
dd55005c 97
98 $postUpgradeMessage .= '<br /><br />' . ts('Default version of the following System Workflow Message Templates have been modified: <ul><li>Personal Campaign Pages - Owner 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).');
f431d51f
J
99
100 $postUpgradeMessage .= '<p>' . ts('The custom fatal error template setting has been removed.') . '</p>';
6dbe2c23 101 }
a742ee50
TO
102 //if ($rev == '4.7.11') {
103 // $postUpgradeMessage .= '<br /><br />' . ts("WARNING: For increased security, profile submissions embedded in remote sites are no longer allowed to create or edit data by default. If you need to allow users to submit profiles from external sites, you can restore this at Administer > System Settings > Misc (Undelete, PDFs, Limits, Logging, Captcha, etc.) > 'Accept profile submissions from external sites'");
104 //}
11769bd1 105 if ($rev == '4.7.11') {
9867e465 106 $postUpgradeMessage .= '<br /><br />' . ts("By default, CiviCRM now disables the ability to import directly from SQL. To use this feature, you must explicitly grant permission 'import SQL datasource'.");
11769bd1 107 }
c7c54ade
CW
108 if ($rev == '4.7.14') {
109 $ck_href = 'href="' . CRM_Utils_System::url('civicrm/admin/ckeditor') . '"';
110 $postUpgradeMessage .= '<p>' . ts('CiviMail no longer forces CKEditor to add html/head/body tags to email content because some sites place these in the message header/footer. This was added in 4.7.5 and is now disabled by default.')
111 . '<br />' . ts('You can re-enable it by visitng the <a %1>CKEditor Config</a> screen and setting "fullPage = true" under the Advanced Options of the CiviMail preset.', array(1 => $ck_href))
112 . '</p>';
113 }
6cc25669
CW
114 }
115
6cc25669
CW
116 /**
117 * Upgrade function.
118 *
119 * @param string $rev
120 */
121 public function upgrade_4_7_alpha1($rev) {
b604d7ec 122 $this->addTask('Migrate \'on behalf of\' information to module_data', 'migrateOnBehalfOfInfo');
bf6a5362 123 $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
f806379b 124 $this->addTask(ts('Migrate Settings to %1', array(1 => $rev)), 'migrateSettings', $rev);
b604d7ec 125 $this->addTask('Add Getting Started dashlet', 'addGettingStartedDashlet', $rev);
a40fd1ac
CW
126 }
127
128 /**
129 * Upgrade function.
130 *
131 * @param string $rev
132 */
133 public function upgrade_4_7_alpha4($rev) {
134 $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
058b8a5e 135 $this->addTask(ts('Remove %1', array(1 => 'Moneris')), 'removePaymentProcessorType', 'Moneris');
b2222b9f 136 $this->addTask('Update Smart Groups', 'fixContactTypeInSmartGroups');
6cc25669
CW
137 }
138
0094ac08
CW
139 /**
140 * Upgrade function.
141 *
142 * @param string $rev
143 */
144 public function upgrade_4_7_beta2($rev) {
145 $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
146 $this->addTask('Delete unused file', 'deleteVersionCheckCacheFile');
147 }
148
fb1f3850
DRJ
149 /**
150 * Upgrade function.
151 *
152 * @param string $rev
153 */
902e557f 154 public function upgrade_4_7_beta6($rev) {
13599400 155 $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
fb1f3850 156 $this->addTask('Disable flexible jobs extension', 'disableFlexibleJobsExtension');
20d5377e 157 $this->addTask('Add Index to financial_trxn trxn_id field', 'addIndexFinancialTrxnTrxnID');
fb1f3850
DRJ
158 }
159
8ca47f5c 160 /**
161 * Upgrade function.
162 *
163 * @param string $rev
164 */
165 public function upgrade_4_7_1($rev) {
2af0b023 166 $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
8ca47f5c 167 $this->addTask('Add Index to civicrm_contribution creditnote_id field', 'addIndexContributionCreditNoteID');
168 }
169
2179c899 170 /**
171 * Upgrade function.
172 *
173 * @param string $rev
174 */
175 public function upgrade_4_7_2($rev) {
2af0b023 176 $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
2179c899 177 $this->addTask('Fix Index on civicrm_financial_item combined entity_id + entity_table', 'addCombinedIndexFinancialItemEntityIDEntityType');
1f395432 178 $this->addTask('enable financial account relationships for chargeback & refund', 'addRefundAndChargeBackAccountsIfNotExist');
3fe26f4c 179 $this->addTask('Add Index to civicrm_contribution.source', 'addIndexContributionSource');
2179c899 180 }
181
fd28b6a0 182 /**
183 * Upgrade function.
184 *
185 * @param string $rev
186 */
187 public function upgrade_4_7_3($rev) {
2af0b023 188 $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
fd28b6a0 189 $this->addTask('Add Index to civicrm_contribution.total_amount', 'addIndexContributionAmount');
190 }
191
6eb752fa 192 /**
193 * Upgrade function.
194 *
195 * @param string $rev
196 */
197 public function upgrade_4_7_4($rev) {
2af0b023 198 $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
6eb752fa 199 $this->addTask('Add Contact Deleted by Merge Activity Type', 'addDeletedByMergeActivityType');
200 }
201
2cbdd085
J
202 /**
203 * Upgrade function.
204 *
205 * @param string $rev
206 */
6a2d3987 207 public function upgrade_4_7_7($rev) {
2cbdd085 208 $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
6a2d3987
J
209 // https://issues.civicrm.org/jira/browse/CRM-18006
210 if (CRM_Core_DAO::checkTableExists('civicrm_install_canary')) {
211 CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_install_canary ENGINE=InnoDB');
212 }
2cbdd085
J
213 }
214
2af0b023
CW
215 /**
216 * Upgrade function.
217 *
218 * @param string $rev
219 */
6a2d3987 220 public function upgrade_4_7_8($rev) {
2af0b023 221 $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
6a2d3987 222 $this->addTask('Upgrade mailing foreign key constraints', 'upgradeMailingFKs');
065ffec9
TO
223 }
224
da1ecd73
SL
225 /**
226 * Upgrade function.
227 *
228 * @param string $rev
229 */
e8a4535e 230 public function upgrade_4_7_10($rev) {
da1ecd73 231 $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
b5095b43
CW
232 $this->addTask('Upgrade Add Help Pre and Post Fields to price value table', 'addHelpPreAndHelpPostFieldsPriceFieldValue');
233 $this->addTask('Alter index and type for image URL', 'alterIndexAndTypeForImageURL');
da1ecd73
SL
234 }
235
00c27b41
CW
236 /**
237 * Upgrade function.
238 *
239 * @param string $rev
240 */
241 public function upgrade_4_7_11($rev) {
242 $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
243 $this->addTask('Dashboard schema updates', 'dashboardSchemaUpdate');
b5095b43 244 $this->addTask('Fill in setting "remote_profile_submissions"', 'migrateRemoteSubmissionsSetting');
00c27b41
CW
245 }
246
7c61320c
SL
247 /**
248 * Upgrade function.
249 *
250 * @param string $rev
251 */
252 public function upgrade_4_7_12($rev) {
253 $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
b5095b43 254 $this->addTask('Add Data Type column to civicrm_option_group', 'addDataTypeColumnToOptionGroupTable');
7c61320c 255 }
cb5962bd
SL
256 /**
257 * Upgrade function.
258 *
259 * @param string $rev
260 */
261 public function upgrade_4_7_13($rev) {
262 $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
6846f088
CW
263 $this->addTask('CRM-19372 - Add column to allow for payment processors to set what card types are accepted', 'addColumn',
264 'civicrm_payment_processor', 'accepted_credit_cards', "text DEFAULT NULL COMMENT 'array of accepted credit card types'");
cb5962bd
SL
265 }
266
7ad5ae6a
CW
267 /**
268 * Upgrade function.
269 *
270 * @param string $rev
271 */
272 public function upgrade_4_7_14($rev) {
273 $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
274 $this->addTask('Add WYSIWYG Editor Presets', 'addWysiwygPresets');
275 }
7c61320c 276
b412f764
CW
277 /**
278 * Upgrade function.
279 *
280 * @param string $rev
281 */
282 public function upgrade_4_7_15($rev) {
6846f088
CW
283 $this->addTask('CRM-19626 - Add min_amount column to civicrm_price_set', 'addColumn',
284 'civicrm_price_set', 'min_amount', "INT(10) UNSIGNED DEFAULT '0' COMMENT 'Minimum Amount required for this set.'");
b412f764
CW
285 $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
286 }
287
703875d8
TO
288 /**
289 * Upgrade function.
290 *
291 * @param string $rev
292 */
293 public function upgrade_4_7_16($rev) {
73c5338d
CW
294 $this->addTask('CRM-19723 - Add icon column to civicrm_option_value', 'addColumn',
295 'civicrm_option_value', 'icon', "varchar(255) COMMENT 'crm-i icon class' DEFAULT NULL");
296 $this->addTask('CRM-19769 - Add color column to civicrm_tag', 'addColumn',
297 'civicrm_tag', 'color', "varchar(255) COMMENT 'Hex color value e.g. #ffffff' DEFAULT NULL");
298 $this->addTask('CRM-19779 - Add color column to civicrm_option_value', 'addColumn',
299 'civicrm_option_value', 'color', "varchar(255) COMMENT 'Hex color value e.g. #ffffff' DEFAULT NULL");
703875d8 300 $this->addTask('Add new CiviMail fields', 'addMailingTemplateType');
cd063b10
CW
301 $this->addTask('CRM-19770 - Add is_star column to civicrm_activity', 'addColumn',
302 'civicrm_activity', 'is_star', "tinyint DEFAULT '0' COMMENT 'Activity marked as favorite.'");
73c5338d 303 $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
703875d8
TO
304 }
305
2af0b023 306 /*
2cbdbcef 307 * Important! All upgrade functions MUST add a 'runSql' task.
2af0b023
CW
308 * Uncomment and use the following template for a new upgrade version
309 * (change the x in the function name):
310 */
311
312 // /**
313 // * Upgrade function.
314 // *
315 // * @param string $rev
316 // */
317 // public function upgrade_4_7_x($rev) {
318 // $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
319 // // Additional tasks here...
b5095b43
CW
320 // // Note: do not use ts() in the addTask description because it adds unnecessary strings to transifex.
321 // // The above is an exception because 'Upgrade DB to %1: SQL' is generic & reusable.
2af0b023
CW
322 // }
323
6cc25669
CW
324 /**
325 * CRM-16354
326 *
6dbe2c23 327 * @return int
6cc25669 328 */
6dbe2c23 329 public static function updateWysiwyg() {
aaffa79f 330 $editorID = Civi::settings()->get('editor_id');
6dbe2c23
CW
331 // Previously a numeric value indicated one of 4 wysiwyg editors shipped in core, and no value indicated 'Textarea'
332 // Now the options are "Textarea", "CKEditor", and the rest have been dropped from core.
333 $newEditor = $editorID ? "CKEditor" : "Textarea";
08ef4ddd 334 Civi::settings()->set('editor_id', $newEditor);
6cc25669 335
6dbe2c23 336 return $editorID;
6cc25669
CW
337 }
338
f806379b
TO
339 /**
340 * Migrate any last remaining options from `civicrm_domain.config_backend` to `civicrm_setting`.
341 * Cleanup setting schema.
342 *
343 * @param CRM_Queue_TaskContext $ctx
344 * @return bool
345 */
5c9edd99 346 public static function migrateSettings(CRM_Queue_TaskContext $ctx) {
4cc9e637
TO
347 // Tip: If there are problems with adding the new uniqueness index, try inspecting:
348 // SELECT name, domain_id, contact_id, count(*) AS dupes FROM civicrm_setting cs GROUP BY name, domain_id, contact_id HAVING dupes > 1;
349
350 // Nav records are expendable. https://forum.civicrm.org/index.php?topic=36933.0
351 CRM_Core_DAO::executeQuery('DELETE FROM civicrm_setting WHERE contact_id IS NOT NULL AND name = "navigation"');
3ddd2901 352
726e6261
SL
353 CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_setting DROP INDEX index_group_name');
354 CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_setting DROP COLUMN group_name');
355
3ddd2901
SL
356 // Handle Strange activity_tab_filter settings.
357 CRM_Core_DAO::executeQuery('CREATE TABLE civicrm_activity_setting LIKE civicrm_setting');
726e6261 358 CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_activity_setting ADD UNIQUE INDEX index_domain_contact_name (domain_id, contact_id, name)');
3ddd2901 359 CRM_Core_DAO::executeQuery('INSERT INTO civicrm_activity_setting (name, contact_id, domain_id, value)
726e6261 360 SELECT DISTINCT name, contact_id, domain_id, value
3ddd2901
SL
361 FROM civicrm_setting
362 WHERE name = "activity_tab_filter"
363 AND value is not NULL');
ee4d8422 364 CRM_Core_DAO::executeQuery('DELETE FROM civicrm_setting WHERE name = "activity_tab_filter"');
4cc9e637 365
e6a2c901 366 $date = CRM_Utils_Time::getTime('Y-m-d H:i:s');
f806379b 367 CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_setting ADD UNIQUE INDEX index_domain_contact_name (domain_id, contact_id, name)');
e6a2c901
SL
368 CRM_Core_DAO::executeQuery("INSERT INTO civicrm_setting (name, contact_id, domain_id, value, is_domain, created_id, created_date)
369 SELECT name, contact_id, domain_id, value, 0, contact_id,'$date'
3ddd2901 370 FROM civicrm_activity_setting
e6a2c901
SL
371 WHERE name = 'activity_tab_filter'
372 AND value is not NULL"
d09d52ce 373 );
3ddd2901 374 CRM_Core_DAO::executeQuery('DROP TABLE civicrm_activity_setting');
f806379b
TO
375
376 $domainDao = CRM_Core_DAO::executeQuery('SELECT id, config_backend FROM civicrm_domain');
377 while ($domainDao->fetch()) {
378 $settings = CRM_Upgrade_Incremental_php_FourSeven::convertBackendToSettings($domainDao->id, $domainDao->config_backend);
379 CRM_Core_Error::debug_var('convertBackendToSettings', array(
380 'domainId' => $domainDao->id,
381 'backend' => $domainDao->config_backend,
382 'settings' => $settings,
383 ));
384
385 foreach ($settings as $name => $value) {
386 $rowParams = array(
387 1 => array($domainDao->id, 'Positive'),
388 2 => array($name, 'String'),
389 3 => array(serialize($value), 'String'),
390 );
391 $settingId = CRM_Core_DAO::singleValueQuery(
392 'SELECT id FROM civicrm_setting WHERE domain_id = %1 AND name = %2',
393 $rowParams);
394 if (!$settingId) {
395 CRM_Core_DAO::executeQuery(
396 'INSERT INTO civicrm_setting (domain_id, name, value, is_domain) VALUES (%1,%2,%3,1)',
397 $rowParams);
398 }
399 }
400 }
401
9e726168 402 CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_domain DROP COLUMN config_backend');
f806379b
TO
403
404 return TRUE;
405 }
406
407 /**
408 * Take a config_backend blob and produce an equivalent list of settings.
409 *
410 * @param int $domainId
411 * Domain ID.
412 * @param string $config_backend
413 * Serialized blob.
414 * @return array
415 */
416 public static function convertBackendToSettings($domainId, $config_backend) {
417 if (!$config_backend) {
418 return array();
419 }
420
421 $backend = unserialize($config_backend);
422 if (!$backend) {
423 return array();
424 }
425
426 $mappings = \CRM_Core_Config_MagicMerge::getPropertyMap();
427 $settings = array();
428 foreach ($backend as $propertyName => $propertyValue) {
429 if (isset($mappings[$propertyName][0]) && preg_match('/^setting/', $mappings[$propertyName][0])) {
430 // $mapping format: $propertyName => Array(0 => $type, 1 => $setting|NULL).
431 $settingName = isset($mappings[$propertyName][1]) ? $mappings[$propertyName][1] : $propertyName;
432 $settings[$settingName] = $propertyValue;
433 }
434 }
435
436 return $settings;
437 }
438
0a95c936 439 /**
440 * Add Getting Started dashlet to dashboard
441 *
442 * @param \CRM_Queue_TaskContext $ctx
443 *
444 * @return bool
445 */
5c9edd99 446 public static function addGettingStartedDashlet(CRM_Queue_TaskContext $ctx) {
9c4a04f2 447 $sql = "SELECT count(*) FROM civicrm_dashboard WHERE name='getting-started'";
e1674273 448 $res = CRM_Core_DAO::singleValueQuery($sql);
449 $domainId = CRM_Core_Config::domainID();
450 if ($res <= 0) {
451 $sql = "INSERT INTO `civicrm_dashboard`
a8b704c5 452 ( `domain_id`, `name`, `label`, `url`, `permission`, `permission_operator`, `column_no`, `is_minimized`, `is_active`, `weight`, `fullscreen_url`, `is_fullscreen`, `is_reserved`) VALUES ( {$domainId}, 'getting-started', 'Getting Started', 'civicrm/dashlet/getting-started?reset=1&snippet=5', 'access CiviCRM', NULL, 0, 0, 1, 0, 'civicrm/dashlet/getting-started?reset=1&snippet=5&context=dashletFullscreen', 1, 1)";
e1674273 453 CRM_Core_DAO::executeQuery($sql);
454 // Add default position for Getting Started Dashlet ( left column)
455 $sql = "INSERT INTO `civicrm_dashboard_contact` (dashboard_id, contact_id, column_no, is_active)
456SELECT (SELECT MAX(id) FROM `civicrm_dashboard`), contact_id, 0, IF (SUM(is_active) > 0, 1, 0)
429da6a1 457FROM `civicrm_dashboard_contact` JOIN `civicrm_contact` WHERE civicrm_dashboard_contact.contact_id = civicrm_contact.id GROUP BY contact_id";
e1674273 458 CRM_Core_DAO::executeQuery($sql);
459 }
0a95c936 460 return TRUE;
e1674273 461 }
4175ee03 462
6b1e1a2c 463 /**
464 * Migrate on-behalf information to uf_join.module_data as on-behalf columns will be dropped
465 * on DB upgrade
466 *
467 * @param CRM_Queue_TaskContext $ctx
468 *
469 * @return bool
470 * TRUE for success
471 */
472 public static function migrateOnBehalfOfInfo(CRM_Queue_TaskContext $ctx) {
d3e92c88 473 $domain = new CRM_Core_DAO_Domain();
474 $domain->find(TRUE);
6b1e1a2c 475
d3e92c88 476 // fetch onBehalf entry in UFJoin table
6b1e1a2c 477 $ufGroupDAO = new CRM_Core_DAO_UFJoin();
478 $ufGroupDAO->module = 'OnBehalf';
479 $ufGroupDAO->find(TRUE);
480
f635ab77 481 $forOrgColums = array('is_for_organization');
d3e92c88 482 if ($domain->locales) {
483 $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales);
484 foreach ($locales as $locale) {
485 $forOrgColums[] = "for_organization_{$locale}";
486 }
487 }
488 else {
489 $forOrgColums[] = "for_organization";
490 }
491
492 $query = "
493 SELECT " . implode(", ", $forOrgColums) . ", uj.id as join_id, uj.uf_group_id as uf_group_id
494 FROM civicrm_contribution_page cp
495 INNER JOIN civicrm_uf_join uj ON uj.entity_id = cp.id AND uj.module = 'OnBehalf'";
496 $dao = CRM_Core_DAO::executeQuery($query, array(), TRUE, NULL, FALSE, FALSE);
6b1e1a2c 497
498 if ($dao->N) {
6b1e1a2c 499 while ($dao->fetch()) {
500 $onBehalfParams['on_behalf'] = array('is_for_organization' => $dao->is_for_organization);
501 if ($domain->locales) {
6b1e1a2c 502 foreach ($locales as $locale) {
503 $for_organization = "for_organization_{$locale}";
504 $onBehalfParams['on_behalf'] += array(
505 $locale => array(
506 'for_organization' => $dao->$for_organization,
507 ),
508 );
509 }
510 }
511 else {
512 $onBehalfParams['on_behalf'] += array(
513 'default' => array(
514 'for_organization' => $dao->for_organization,
515 ),
516 );
517 }
518 $ufJoinParam = array(
519 'id' => $dao->join_id,
520 'module' => 'on_behalf',
d3e92c88 521 'uf_group_id' => $dao->uf_group_id,
6b1e1a2c 522 'module_data' => json_encode($onBehalfParams),
523 );
524 CRM_Core_BAO_UFJoin::create($ufJoinParam);
525 }
526 }
527
528 return TRUE;
9e42a501
TO
529 }
530
531 /**
532 * v4.7.11 adds a new setting "remote_profile_submissions". This is
533 * long-standing feature that existing sites may be using; however, it's
534 * a bit prone to abuse. For new sites, the default is to disable it
535 * (since that is more secure). For existing sites, the default is to
536 * enable it (since that is more compatible).
537 *
538 * @param \CRM_Queue_TaskContext $ctx
539 *
540 * @return bool
541 */
5c9edd99 542 public static function migrateRemoteSubmissionsSetting(CRM_Queue_TaskContext $ctx) {
9e42a501
TO
543 $domains = CRM_Core_DAO::executeQuery("SELECT DISTINCT d.id FROM civicrm_domain d LEFT JOIN civicrm_setting s ON d.id=s.domain_id AND s.name = 'remote_profile_submissions' WHERE s.id IS NULL");
544 while ($domains->fetch()) {
545 CRM_Core_DAO::executeQuery(
546 "INSERT INTO civicrm_setting (`name`, `value`, `domain_id`, `is_domain`, `contact_id`, `component_id`, `created_date`, `created_id`)
547 VALUES (%2, %3, %4, %5, NULL, NULL, %6, NULL)",
548 array(
549 2 => array('remote_profile_submissions', 'String'),
550 3 => array('s:1:"1";', 'String'),
551 4 => array($domains->id, 'Integer'),
552 5 => array(1, 'Integer'),
553 6 => array(date('Y-m-d H:i:s'), 'String'),
554 )
555 );
556 }
557 return TRUE;
6b1e1a2c 558 }
cb804cd9 559
b2222b9f
CW
560 /**
561 * CRM-11782 - Get rid of VALUE_SEPARATOR character in saved search form values
562 *
563 * @param \CRM_Queue_TaskContext $ctx
564 *
565 * @return bool
566 */
5c9edd99 567 public static function fixContactTypeInSmartGroups(CRM_Queue_TaskContext $ctx) {
b2222b9f
CW
568 $sep = CRM_Core_DAO::VALUE_SEPARATOR;
569 $dao = CRM_Core_DAO::executeQuery("SELECT id, form_values FROM civicrm_saved_search WHERE form_values LIKE '%$sep%'");
570 while ($dao->fetch()) {
571 $formValues = unserialize($dao->form_values);
572 if (isset($formValues['contact_type']) && is_array($formValues['contact_type'])) {
573 $newVals = array();
574 foreach ($formValues['contact_type'] as $key => $val) {
575 $newVals[str_replace($sep, '__', $key)] = is_string($val) ? str_replace($sep, '__', $val) : $val;
576 }
577 $formValues['contact_type'] = $newVals;
578 }
579 CRM_Core_DAO::executeQuery("UPDATE civicrm_saved_search SET form_values = %1 WHERE id = {$dao->id}", array(1 => array(serialize($formValues), 'String')));
580 }
581
582 return TRUE;
583 }
584
0094ac08
CW
585 /**
586 * CRM-17637 - Ths file location has been moved; delete the old one
587 *
588 * @param \CRM_Queue_TaskContext $ctx
589 *
590 * @return bool
591 */
5c9edd99 592 public static function deleteVersionCheckCacheFile(CRM_Queue_TaskContext $ctx) {
0094ac08
CW
593 $config = CRM_Core_Config::singleton();
594 $cacheFile = $config->uploadDir . 'version-info-cache.json';
595 if (file_exists($cacheFile)) {
596 unlink($cacheFile);
597 }
598 return TRUE;
599 }
600
fb1f3850
DRJ
601 /**
602 * CRM-17669 and CRM-17686, make scheduled jobs more flexible, disable the 4.6 extension if installed
603 *
604 * @param \CRM_Queue_TaskContext $ctx
605 *
606 * @return bool
607 */
5c9edd99 608 public static function disableFlexibleJobsExtension(CRM_Queue_TaskContext $ctx) {
d357221c
DRJ
609 try {
610 civicrm_api3('Extension', 'disable', array('key' => 'com.klangsoft.flexiblejobs'));
611 }
612 catch (CiviCRM_API3_Exception $e) {
613 // just ignore if the extension isn't installed
614 }
fb1f3850
DRJ
615
616 return TRUE;
617 }
618
20d5377e 619 /**
620 * CRM-17752 add index to civicrm_financial_trxn.trxn_id (deliberately non-unique).
621 *
622 * @param \CRM_Queue_TaskContext $ctx
623 *
624 * @return bool
625 */
5c9edd99 626 public static function addIndexFinancialTrxnTrxnID(CRM_Queue_TaskContext $ctx) {
20d5377e 627 $tables = array('civicrm_financial_trxn' => array('trxn_id'));
628 CRM_Core_BAO_SchemaHandler::createIndexes($tables);
629 return TRUE;
630 }
631
8ca47f5c 632 /**
633 * CRM-17882 Add index to civicrm_contribution.credit_note_id.
634 *
635 * @param \CRM_Queue_TaskContext $ctx
636 *
637 * @return bool
638 */
5c9edd99 639 public static function addIndexContributionCreditNoteID(CRM_Queue_TaskContext $ctx) {
8ca47f5c 640 $tables = array('civicrm_contribution' => array('creditnote_id'));
641 CRM_Core_BAO_SchemaHandler::createIndexes($tables);
642 return TRUE;
643 }
644
2179c899 645 /**
646 * CRM-17775 Add correct index for table civicrm_financial_item.
647 *
648 * Note that the entity ID should always precede the entity_table as
649 * it is more unique. This is better for performance and does not cause fallback
650 * to no index if table it omitted.
651 *
652 * @return bool
653 */
5c9edd99 654 public static function addCombinedIndexFinancialItemEntityIDEntityType() {
2179c899 655 CRM_Core_BAO_SchemaHandler::dropIndexIfExists('civicrm_financial_item', 'UI_id');
656 CRM_Core_BAO_SchemaHandler::dropIndexIfExists('civicrm_financial_item', 'IX_Entity');
657 CRM_Core_BAO_SchemaHandler::createIndexes(array(
658 'civicrm_financial_item' => array(array('entity_id', 'entity_table')),
659 ));
660 return TRUE;
661 }
662
1f395432 663 /**
664 * CRM-17951 Add accounts option values for refund and chargeback.
665 *
666 * Add Chargeback contribution status and Chargeback and Contra account relationships,
667 * checking first if one exists.
668 */
5c9edd99 669 public static function addRefundAndChargeBackAccountsIfNotExist() {
1f395432 670 // First we enable and edit the record for Credit contra - this exists but is disabled for most sites.
671 // Using the ensure function (below) will not enabled a disabled option (by design).
672 CRM_Core_DAO::executeQuery("UPDATE civicrm_option_value v
673 INNER JOIN civicrm_option_group g on v.option_group_id=g.id and g.name='account_relationship'
674 SET v.is_active=1, v.label='Credit/Contra Revenue Account is', v.name='Credit/Contra Revenue Account is', v.description='Credit/Contra Revenue Account is'
675 WHERE v.name = 'Credit/Contra Account is';");
676
677 CRM_Core_BAO_OptionValue::ensureOptionValueExists(array(
678 'option_group_id' => 'account_relationship',
4a907feb
EM
679 'name' => 'Chargeback Account is',
680 'label' => ts('Chargeback Account is'),
1f395432 681 'is_active' => TRUE,
682 'component_id' => 'CiviContribute',
683 ));
684
685 CRM_Core_BAO_OptionValue::ensureOptionValueExists(array(
686 'option_group_id' => 'contribution_status',
687 'name' => 'Chargeback',
688 'label' => ts('Chargeback'),
689 'is_active' => TRUE,
690 'component_id' => 'CiviContribute',
691 ));
692 return TRUE;
693 }
694
3fe26f4c 695 /**
696 * CRM-17999 Add index to civicrm_contribution.source.
697 *
698 * @param \CRM_Queue_TaskContext $ctx
699 *
700 * @return bool
701 */
5c9edd99 702 public static function addIndexContributionSource(CRM_Queue_TaskContext $ctx) {
3fe26f4c 703 CRM_Core_BAO_SchemaHandler::createIndexes(array('civicrm_contribution' => array('source')));
704 return TRUE;
705 }
706
fd28b6a0 707 /**
708 * CRM-18124 Add index to civicrm_contribution.total_amount.
709 *
710 * Note that I made this a combined index with receive_date because the issue included
711 * both criteria and they seemed likely to be used in conjunction to me in other cases.
712 *
713 * @param \CRM_Queue_TaskContext $ctx
714 *
715 * @return bool
716 */
5c9edd99 717 public static function addIndexContributionAmount(CRM_Queue_TaskContext $ctx) {
fd28b6a0 718 CRM_Core_BAO_SchemaHandler::createIndexes(array(
719 'civicrm_contribution' => array(array('total_amount', 'receive_date')),
720 ));
721 return TRUE;
722 }
723
6eb752fa 724 /**
725 * CRM-18124 Add index to civicrm_contribution.total_amount.
726 *
727 * Note that I made this a combined index with receive_date because the issue included
728 * both criteria and they seemed likely to be used in conjunction to me in other cases.
729 *
730 * @param \CRM_Queue_TaskContext $ctx
731 *
732 * @return bool
733 */
5c9edd99 734 public static function addDeletedByMergeActivityType(CRM_Queue_TaskContext $ctx) {
6eb752fa 735 CRM_Core_BAO_OptionValue::ensureOptionValueExists(array(
736 'option_group_id' => 'activity_type',
737 'name' => 'Contact Deleted by Merge',
738 'label' => ts('Contact Deleted by Merge'),
739 'description' => ts('Contact was merged into another contact'),
740 'is_active' => TRUE,
e14e412b 741 'filter' => 1,
6eb752fa 742 ));
743 return TRUE;
744 }
745
da1ecd73
SL
746 /**
747 * CRM-12252 Add Help Pre and Help Post Fields for Price Field Value Table.
748 *
749 * @param \CRM_Queue_TaskContext $ctx
750 *
751 * @return bool
752 */
5c9edd99 753 public static function addHelpPreAndHelpPostFieldsPriceFieldValue(CRM_Queue_TaskContext $ctx) {
da1ecd73
SL
754 $domain = new CRM_Core_DAO_Domain();
755 $domain->find(TRUE);
756 if ($domain->locales) {
757 $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales);
758 foreach ($locales as $locale) {
01ee8ba6 759 if (!CRM_Core_BAO_SchemaHandler::checkIfFieldExists("civicrm_price_field_value", "help_pre_{$locale}")) {
3dc870a2
SL
760 CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_price_field_value`
761 ADD COLUMN `help_pre_{$locale}` text COLLATE utf8_unicode_ci COMMENT 'Price field option pre help text.'", array(), TRUE, NULL, FALSE, FALSE);
da1ecd73 762 }
01ee8ba6 763 if (!CRM_Core_BAO_SchemaHandler::checkIfFieldExists("civicrm_price_field_value", "help_post_{$locale}")) {
3dc870a2
SL
764 CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_price_field_value`
765 ADD COLUMN `help_post_{$locale}` text COLLATE utf8_unicode_ci COMMENT 'Price field option post help text.'", array(), TRUE, NULL, FALSE, FALSE);
da1ecd73
SL
766 }
767 }
01ee8ba6 768 CRM_Core_I18n_Schema::rebuildMultilingualSchema($locales, NULL);
da1ecd73
SL
769 }
770 else {
771 if (!CRM_Core_BAO_SchemaHandler::checkIfFieldExists('civicrm_price_field_value', 'help_pre')) {
3dc870a2
SL
772 CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_price_field_value`
773 ADD COLUMN `help_pre` text COLLATE utf8_unicode_ci COMMENT 'Price field option pre help text.'");
da1ecd73
SL
774 }
775 if (!CRM_Core_BAO_SchemaHandler::checkIfFieldExists('civicrm_price_field_value', 'help_post')) {
3dc870a2
SL
776 CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_price_field_value`
777 ADD COLUMN `help_post` text COLLATE utf8_unicode_ci COMMENT 'Price field option post help text.'");
da1ecd73
SL
778 }
779 }
780 return TRUE;
781 }
782
2cbdd085
J
783 /**
784 * CRM-18345 Don't delete mailing data on email/phone deletion
785 * Implemented here in CRM-18526
786 *
787 * @param \CRM_Queue_TaskContext $ctx
788 *
789 * @return bool
790 */
5c9edd99 791 public static function upgradeMailingFKs(CRM_Queue_TaskContext $ctx) {
2cbdd085
J
792
793 // Safely drop the foreign keys
169475b7
SL
794 CRM_Core_BAO_SchemaHandler::safeRemoveFK('civicrm_mailing_event_queue', 'FK_civicrm_mailing_event_queue_email_id');
795 CRM_Core_BAO_SchemaHandler::safeRemoveFK('civicrm_mailing_event_queue', 'FK_civicrm_mailing_event_queue_phone_id');
796 CRM_Core_BAO_SchemaHandler::safeRemoveFK('civicrm_mailing_recipients', 'FK_civicrm_mailing_recipients_email_id');
797 CRM_Core_BAO_SchemaHandler::safeRemoveFK('civicrm_mailing_recipients', 'FK_civicrm_mailing_recipients_phone_id');
2cbdd085
J
798
799 // Set up the new foreign keys
800 CRM_Core_DAO::executeQuery("SET FOREIGN_KEY_CHECKS = 0;");
801
802 CRM_Core_DAO::executeQuery("
803 ALTER TABLE `civicrm_mailing_event_queue`
804 ADD CONSTRAINT `FK_civicrm_mailing_event_queue_email_id`
805 FOREIGN KEY (`email_id`)
806 REFERENCES `civicrm_email`(`id`)
807 ON DELETE SET NULL
808 ON UPDATE RESTRICT;
809 ");
810
811 CRM_Core_DAO::executeQuery("
812 ALTER TABLE `civicrm_mailing_event_queue`
813 ADD CONSTRAINT `FK_civicrm_mailing_event_queue_phone_id`
814 FOREIGN KEY (`phone_id`)
815 REFERENCES `civicrm_phone`(`id`)
816 ON DELETE SET NULL
817 ON UPDATE RESTRICT;
818 ");
819
820 CRM_Core_DAO::executeQuery("
821 ALTER TABLE `civicrm_mailing_recipients`
822 ADD CONSTRAINT `FK_civicrm_mailing_recipients_email_id`
823 FOREIGN KEY (`email_id`)
824 REFERENCES `civicrm_email`(`id`)
825 ON DELETE SET NULL
826 ON UPDATE RESTRICT;
827 ");
828
829 CRM_Core_DAO::executeQuery("
830 ALTER TABLE `civicrm_mailing_recipients`
831 ADD CONSTRAINT `FK_civicrm_mailing_recipients_phone_id`
832 FOREIGN KEY (`phone_id`)
833 REFERENCES `civicrm_phone`(`id`)
834 ON DELETE SET NULL
835 ON UPDATE RESTRICT;
836 ");
837
838 CRM_Core_DAO::executeQuery("SET FOREIGN_KEY_CHECKS = 1;");
839
840 return TRUE;
841 }
842
00c27b41
CW
843 /**
844 * CRM-17663 - Dashboard schema changes
845 *
846 * @param \CRM_Queue_TaskContext $ctx
847 *
848 * @return bool
849 */
5c9edd99 850 public static function dashboardSchemaUpdate(CRM_Queue_TaskContext $ctx) {
00c27b41
CW
851 if (!CRM_Core_BAO_SchemaHandler::checkIfIndexExists('civicrm_dashboard_contact', 'index_dashboard_id_contact_id')) {
852 // Delete any stray duplicate rows and add unique index to prevent new dupes and enable INSERT/UPDATE combo query
853 CRM_Core_DAO::executeQuery('DELETE c1 FROM civicrm_dashboard_contact c1, civicrm_dashboard_contact c2 WHERE c1.contact_id = c2.contact_id AND c1.dashboard_id = c2.dashboard_id AND c1.id > c2.id');
854 CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_dashboard_contact ADD UNIQUE INDEX index_dashboard_id_contact_id (dashboard_id, contact_id);');
855 }
87568e34
SL
856 $domain = new CRM_Core_DAO_Domain();
857 $domain->find(TRUE);
242055d3
CW
858 CRM_Core_BAO_SchemaHandler::dropColumn('civicrm_dashboard_contact', 'content');
859 CRM_Core_BAO_SchemaHandler::dropColumn('civicrm_dashboard_contact', 'is_minimized');
860 CRM_Core_BAO_SchemaHandler::dropColumn('civicrm_dashboard_contact', 'is_fullscreen');
861 CRM_Core_BAO_SchemaHandler::dropColumn('civicrm_dashboard_contact', 'created_date');
862 CRM_Core_BAO_SchemaHandler::dropColumn('civicrm_dashboard', 'is_fullscreen');
863 CRM_Core_BAO_SchemaHandler::dropColumn('civicrm_dashboard', 'is_minimized');
864 CRM_Core_BAO_SchemaHandler::dropColumn('civicrm_dashboard', 'column_no');
865 CRM_Core_BAO_SchemaHandler::dropColumn('civicrm_dashboard', 'weight');
866
867 CRM_Core_DAO::executeQuery('UPDATE civicrm_dashboard SET url = REPLACE(url, "&snippet=5", ""), fullscreen_url = REPLACE(fullscreen_url, "&snippet=5", "")');
a8f56d71
CW
868
869 if (!CRM_Core_BAO_SchemaHandler::checkIfFieldExists('civicrm_dashboard', 'cache_minutes')) {
8c3f9072
SL
870 CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_dashboard ADD COLUMN cache_minutes int unsigned NOT NULL DEFAULT 60 COMMENT "Number of minutes to cache dashlet content in browser localStorage."',
871 array(), TRUE, NULL, FALSE, FALSE);
872 }
873 if ($domain->locales) {
874 $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales);
875 CRM_Core_I18n_Schema::rebuildMultilingualSchema($locales, NULL);
a8f56d71
CW
876 }
877
878 CRM_Core_DAO::executeQuery('UPDATE civicrm_dashboard SET cache_minutes = 1440 WHERE name = "blog"');
879 CRM_Core_DAO::executeQuery('UPDATE civicrm_dashboard SET cache_minutes = 7200 WHERE name IN ("activity","getting-started")');
242055d3 880 return TRUE;
00c27b41
CW
881 }
882
8e2e96a5 883 /**
884 * CRM-19100 - Alter Index and Type for Image URL
885 * @return bool
886 */
887 public static function alterIndexAndTypeForImageURL() {
98daafd5 888 $length = array();
889 CRM_Core_BAO_SchemaHandler::dropIndexIfExists('civicrm_contact', 'index_image_url');
8e2e96a5 890 CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_contact` CHANGE `image_URL` `image_URL` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL COMMENT 'optional URL for preferred image (photo, logo, etc.) to display for this contact.'");
98daafd5 891
892 $length['civicrm_contact']['image_URL'] = 128;
893 CRM_Core_BAO_SchemaHandler::createIndexes(array('civicrm_contact' => array('image_URL')), 'index', $length);
8e2e96a5 894
895 return TRUE;
896 }
897
bc854509 898 /**
899 * Add mailing template type.
900 *
901 * @return bool
902 */
703875d8
TO
903 public static function addMailingTemplateType() {
904 if (!CRM_Core_DAO::checkFieldExists('civicrm_mailing', 'template_type', FALSE)) {
905 CRM_Core_DAO::executeQuery('
906 ALTER TABLE civicrm_mailing
907 ADD COLUMN `template_type` varchar(64) NOT NULL DEFAULT \'traditional\' COMMENT \'The language/processing system used for email templates.\',
908 ADD COLUMN `template_options` longtext COMMENT \'Advanced options used by the email templating system. (JSON encoded)\'
909 ');
910 }
911 return TRUE;
912 }
913
d0e7e124
SL
914 /**
915 * CRM-18651 Add DataType column to Option Group Table
916 * @return bool
917 */
918 public static function addDataTypeColumnToOptionGroupTable() {
7c61320c 919 if (!CRM_Core_BAO_SchemaHandler::checkIfFieldExists('civicrm_option_group', 'data_type')) {
a37e4e6c
SL
920 CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_option_group` ADD COLUMN `data_type` varchar(128) COLLATE utf8_unicode_ci DEFAULT NULL comment 'Data Type of Option Group.'",
921 array(), TRUE, NULL, FALSE, FALSE);
922 }
923 $domain = new CRM_Core_DAO_Domain();
924 $domain->find(TRUE);
925 if ($domain->locales) {
926 $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales);
927 CRM_Core_I18n_Schema::rebuildMultilingualSchema($locales, NULL);
d0e7e124 928 }
a37e4e6c 929
d0e7e124
SL
930 CRM_Core_DAO::executeQuery("UPDATE `civicrm_option_group` SET `data_type` = 'Integer'
931 WHERE name IN ('activity_type', 'gender', 'payment_instrument', 'participant_role', 'event_type')");
932 return TRUE;
933 }
934
7ad5ae6a
CW
935 /**
936 * CRM-19372 Add field to store accepted credit credit cards for a payment processor.
937 * @return bool
938 */
939 public static function addWysiwygPresets() {
940 CRM_Core_BAO_OptionGroup::ensureOptionGroupExists(array(
941 'name' => 'wysiwyg_presets',
942 'title' => ts('WYSIWYG Editor Presets'),
943 'is_reserved' => 1,
944 ));
945 $values = array(
946 'default' => array('label' => ts('Default'), 'is_default' => 1),
947 'civimail' => array('label' => ts('CiviMail'), 'component_id' => 'CiviMail'),
948 'civievent' => array('label' => ts('CiviEvent'), 'component_id' => 'CiviEvent'),
949 );
950 foreach ($values as $name => $value) {
34273b2a 951 CRM_Core_BAO_OptionValue::ensureOptionValueExists($value + array(
7ad5ae6a
CW
952 'name' => $name,
953 'option_group_id' => 'wysiwyg_presets',
954 ));
955 }
956 $fileName = Civi::paths()->getPath('[civicrm.files]/persist/crm-ckeditor-config.js');
99316116 957 // Ensure the config file contains the allowedContent setting
7ad5ae6a
CW
958 if (file_exists($fileName)) {
959 $config = file_get_contents($fileName);
960 $pos = strrpos($config, '};');
961 $setting = "\n\tconfig.allowedContent = true;\n";
962 $config = substr_replace($config, $setting, $pos, 0);
963 unlink($fileName);
949a87e8
CW
964 $newFileName = Civi::paths()->getPath('[civicrm.files]/persist/crm-ckeditor-default.js');
965 file_put_contents($newFileName, $config);
7ad5ae6a 966 }
7ad5ae6a
CW
967 return TRUE;
968 }
969
6cc25669 970}