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