3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
28 * Upgrade logic for 4.7
30 class CRM_Upgrade_Incremental_php_FourSeven
extends CRM_Upgrade_Incremental_Base
{
33 * Compute any messages which should be displayed beforeupgrade.
35 * Note: This function is called iteratively for each upcoming
36 * revision to the database.
38 * @param string $preUpgradeMessage
40 * a version number, e.g. '4.4.alpha1', '4.4.beta3', '4.4.0'.
41 * @param null $currentVer
43 public function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL) {
44 if ($rev == '4.7.alpha1') {
45 // CRM-16478 Remove custom fatal error template path option
46 $config = CRM_Core_Config
::singleton();
47 if (!empty($config->fatalErrorTemplate
) && $config->fatalErrorTemplate
!= 'CRM/common/fatal.tpl') {
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.', [1 => $config->fatalErrorTemplate
]) . '</p>';
51 if ($rev == '4.7.alpha4') {
52 // CRM-17004 Warn of Moneris removal
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')");
58 if ($count && !function_exists('moneris_civicrm_managed')) {
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.', [1 => 'Moneris']) . '</p>';
62 if ($rev == '4.7.13') {
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', [1 => 'manage tags']) . '</p>';
65 if ($rev == '4.7.22') {
66 // Based on support inquiries for 4.7.21, show message during 4.7.22.
67 // For affected users, this issue prevents loading the regular status screen.
68 if (!$this->checkImageUploadDir()) {
69 $preUpgradeMessage .= '<p>' . ts('There appears to be an inconsistency in the configuration of "Image Upload URL" and "Image Upload Directory".') . '</p>'
71 . ts('Further advice will be displayed at the end of the upgrade.')
75 if ($rev == '4.7.27') {
77 1 => 'Close accounting batches created by user',
78 2 => 'Close all accounting batches',
79 3 => 'Reopen accounting batches created by user',
80 4 => 'Reopen all accounting batches',
81 5 => 'https://wiki.civicrm.org/confluence/display/CRMDOC/Default+Permissions+and+Roles',
83 $preUpgradeMessage .= '<p>' . ts('A new set of batch permissions has been added called "%1", "%2", "%3" and "%4". These permissions are now used to control access to the Accounting Batches tasks. If your users need to be able to Reopen or Close batches you may need to give them additional permissions. <a href=%5>Read more</a>', $params) . '</p>';
85 if ($rev == '4.7.32') {
86 $preUpgradeMessage .= '<p>' . ts('A new %1 permission has been added. It is not granted by default. If you use SMS, you may wish to review your permissions.', [1 => 'send SMS']) . '</p>';
91 * Compute any messages which should be displayed after upgrade.
93 * @param string $postUpgradeMessage
96 * an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs.
98 public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
99 if ($rev == '4.7.alpha1') {
100 $config = CRM_Core_Config
::singleton();
101 // FIXME: Performing an upgrade step during postUpgrade message phase is probably bad
102 $editor_id = self
::updateWysiwyg();
104 $ext_href = 'href="' . CRM_Utils_System
::url('civicrm/admin/extensions', 'reset=1') . '"';
105 $dsp_href = 'href="' . CRM_Utils_System
::url('civicrm/admin/setting/preferences/display', 'reset=1') . '"';
106 $blog_href = 'href="https://civicrm.org/blogs/colemanw/big-changes-wysiwyg-editing-47"';
107 switch ($editor_id) {
110 $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.', [1 => $ext_href]);
113 // Drupal/Joomla editor
116 $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>', [1 => $config->userFramework
, 2 => $blog_href]);
120 $postUpgradeMessage .= '<p>' . $msg . '</p>';
122 $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>', [1 => $dsp_href, 2 => $blog_href]) . '</p>';
124 $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).');
126 $postUpgradeMessage .= '<p>' . ts('The custom fatal error template setting has been removed.') . '</p>';
128 //if ($rev == '4.7.11') {
129 // $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'");
131 if ($rev == '4.7.11') {
132 $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'.");
134 if ($rev == '4.7.14') {
135 $ck_href = 'href="' . CRM_Utils_System
::url('civicrm/admin/ckeditor') . '"';
136 $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.')
137 . '<br />' . ts('You can re-enable it by visiting the <a %1>CKEditor Config</a> screen and setting "fullPage = true" under the Advanced Options of the CiviMail preset.', [1 => $ck_href])
140 if ($rev == '4.7.19') {
141 $postUpgradeMessage .= '<br /><br />' . ts('Default version of the following System Workflow Message Templates have been modified: <ul><li>Additional Payment Receipt or Refund Notification</li><li>Contribution Invoice</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).');
142 $check = CRM_Core_DAO
::singleValueQuery("SELECT count(id) FROM civicrm_domain");
143 $smsCheck = CRM_Core_DAO
::singleValueQuery("SELECT count(id) FROM civicrm_sms_provider");
144 if ($check > 1 && (bool) $smsCheck) {
145 $postUpgradeMessage .= '<p>civicrm_sms_provider ' . ts('has now had a domain id column added. As there is more than 1 domains in this install you need to manually set the domain id for the providers in this install') . '</p>';
148 if ($rev == '4.7.22') {
149 // Based on support inquiries for 4.7.21, show message during 4.7.22.
150 // For affected users, this issue prevents loading the regular status screen.
151 if (!$this->checkImageUploadDir()) {
152 $config = CRM_Core_Config
::singleton();
153 $postUpgradeMessage .=
154 '<h3>' . ts('Warning') . '</h3>'
155 . '<p>' . ts('There appears to be an inconsistency in the configuration of "Image Upload URL" and "Image Upload Directory".') . '</p>'
156 . sprintf("<ul><li><b>imageUploadDir</b>: <code>%s</code></li><li><b>imageUploadURL</b>: <code>%s</code></li></ul>", htmlentities($config->imageUploadDir
), htmlentities($config->imageUploadURL
))
158 . ts('You may need to check that: <ul><li>(a) the path and URL match,</li><li> (b) the httpd/htaccess policy allows requests for files inside this folder,</li><li>and (c) the web domain matches the normal web domain.</ul>')
161 . ts('(Note: Although files should be readable, it is best if they are not listable or browseable.)')
164 . ts('If this remains unresolved, then some important screens may fail to load.')
168 if ($rev == '4.7.23') {
169 $postUpgradeMessage .= '<br /><br />' . ts('Default version of the following System Workflow Message Templates have been modified: <ul><li>Contribution Invoice</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).');
178 public function upgrade_4_7_alpha1($rev) {
179 $this->addTask('Drop action scheudle mapping foreign key', 'dropActionScheudleMappingForeignKey');
180 $this->addTask('Migrate \'on behalf of\' information to module_data', 'migrateOnBehalfOfInfo');
181 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
182 $this->addTask(ts('Migrate Settings to %1', [1 => $rev]), 'migrateSettings', $rev);
183 $this->addTask('Add Getting Started dashlet', 'addGettingStartedDashlet', $rev);
191 public function upgrade_4_7_alpha4($rev) {
192 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
193 $this->addTask(ts('Remove %1', [1 => 'Moneris']), 'removePaymentProcessorType', 'Moneris');
194 $this->addTask('Update Smart Groups', 'fixContactTypeInSmartGroups');
202 public function upgrade_4_7_beta2($rev) {
203 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
204 $this->addTask('Delete unused file', 'deleteVersionCheckCacheFile');
212 public function upgrade_4_7_beta6($rev) {
213 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
214 $this->addTask('Disable flexible jobs extension', 'disableFlexibleJobsExtension');
215 $this->addTask('Add Index to financial_trxn trxn_id field', 'addIndexFinancialTrxnTrxnID');
223 public function upgrade_4_7_1($rev) {
224 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
225 $this->addTask('Add Index to civicrm_contribution creditnote_id field', 'addIndexContributionCreditNoteID');
233 public function upgrade_4_7_2($rev) {
234 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
235 $this->addTask('Fix Index on civicrm_financial_item combined entity_id + entity_table', 'addCombinedIndexFinancialItemEntityIDEntityType');
236 $this->addTask('enable financial account relationships for chargeback & refund', 'addRefundAndChargeBackAccountsIfNotExist');
237 $this->addTask('Add Index to civicrm_contribution.source', 'addIndexContributionSource');
245 public function upgrade_4_7_3($rev) {
246 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
247 $this->addTask('Add Index to civicrm_contribution.total_amount', 'addIndexContributionAmount');
255 public function upgrade_4_7_4($rev) {
256 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
257 $this->addTask('Add Contact Deleted by Merge Activity Type', 'addDeletedByMergeActivityType');
265 public function upgrade_4_7_7($rev) {
266 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
267 // https://issues.civicrm.org/jira/browse/CRM-18006
268 if (CRM_Core_DAO
::checkTableExists('civicrm_install_canary')) {
269 CRM_Core_DAO
::executeQuery('ALTER TABLE civicrm_install_canary ENGINE=InnoDB');
278 public function upgrade_4_7_8($rev) {
279 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
280 $this->addTask('Upgrade mailing foreign key constraints', 'upgradeMailingFKs');
288 public function upgrade_4_7_10($rev) {
289 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
290 $this->addTask('Upgrade Add Help Pre and Post Fields to price value table', 'addHelpPreAndHelpPostFieldsPriceFieldValue');
291 $this->addTask('Alter index and type for image URL', 'alterIndexAndTypeForImageURL');
299 public function upgrade_4_7_11($rev) {
300 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
301 $this->addTask('Dashboard schema updates', 'dashboardSchemaUpdate');
302 $this->addTask('Fill in setting "remote_profile_submissions"', 'migrateRemoteSubmissionsSetting');
310 public function upgrade_4_7_12($rev) {
311 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
312 $this->addTask('Add Data Type column to civicrm_option_group', 'addDataTypeColumnToOptionGroupTable');
320 public function upgrade_4_7_13($rev) {
321 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
322 $this->addTask('CRM-19372 - Add column to allow for payment processors to set what card types are accepted', 'addColumn',
323 'civicrm_payment_processor', 'accepted_credit_cards', "text DEFAULT NULL COMMENT 'array of accepted credit card types'");
331 public function upgrade_4_7_14($rev) {
332 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
333 $this->addTask('Add WYSIWYG Editor Presets', 'addWysiwygPresets');
341 public function upgrade_4_7_15($rev) {
342 $this->addTask('CRM-19626 - Add min_amount column to civicrm_price_set', 'addColumn',
343 'civicrm_price_set', 'min_amount', "INT(10) UNSIGNED DEFAULT '0' COMMENT 'Minimum Amount required for this set.'");
344 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
352 public function upgrade_4_7_16($rev) {
353 $this->addTask('CRM-19723 - Add icon column to civicrm_option_value', 'addColumn',
354 'civicrm_option_value', 'icon', "varchar(255) COMMENT 'crm-i icon class' DEFAULT NULL");
355 $this->addTask('CRM-19769 - Add color column to civicrm_tag', 'addColumn',
356 'civicrm_tag', 'color', "varchar(255) COMMENT 'Hex color value e.g. #ffffff' DEFAULT NULL");
357 $this->addTask('CRM-19779 - Add color column to civicrm_option_value', 'addColumn',
358 'civicrm_option_value', 'color', "varchar(255) COMMENT 'Hex color value e.g. #ffffff' DEFAULT NULL");
359 $this->addTask('Add new CiviMail fields', 'addMailingTemplateType');
360 $this->addTask('CRM-19770 - Add is_star column to civicrm_activity', 'addColumn',
361 'civicrm_activity', 'is_star', "tinyint DEFAULT '0' COMMENT 'Activity marked as favorite.'");
362 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
370 public function upgrade_4_7_18($rev) {
371 $this->addTask('Update Kenyan Provinces', 'updateKenyanProvinces');
372 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
380 public function upgrade_4_7_19($rev) {
381 if (CRM_Core_BAO_SchemaHandler
::checkIfFieldExists('civicrm_financial_account', 'opening_balance')) {
382 $query = "SELECT id FROM civicrm_financial_account WHERE opening_balance <> 0 OR current_period_opening_balance <> 0";
383 $result = CRM_Core_DAO
::executeQuery($query);
385 $this->addTask('Drop Column current_period_opening_balance From civicrm_financial_account table.', 'dropColumn', 'civicrm_financial_account', 'current_period_opening_balance');
386 $this->addTask('Drop Column opening_balance From civicrm_financial_account table.', 'dropColumn', 'civicrm_financial_account', 'opening_balance');
389 $this->addTask('CRM-19961 - Add domain_id column to civicrm_sms_provider', 'addColumn',
390 'civicrm_sms_provider', 'domain_id', "int(10) unsigned COMMENT 'Which Domain is this sms provier for'");
391 $this->addTask('CRM-19961 - Populate domain id table and perhaps add foreign key', 'populateSMSProviderDomainId');
392 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
393 $this->addTask('CRM-16633 - Add "Change Case Subject" activity', 'addChangeCaseSubjectActivityType');
394 $this->addTask('Add is_public column to civicrm_custom_group', 'addColumn',
395 'civicrm_custom_group', 'is_public', "boolean DEFAULT '1' COMMENT 'Is this property public?'");
403 public function upgrade_4_7_20($rev) {
404 $this->addtask('Fix Schema on civicrm_action_schedule', 'fixSchemaOnCiviCRMActionSchedule');
405 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
406 $this->addTask('Add activity_status column to civicrm_mail_settings', 'addColumn',
407 'civicrm_mail_settings', 'activity_status', "varchar (255) DEFAULT NULL COMMENT 'Name of status to use when creating email to activity.'");
415 public function upgrade_4_7_23($rev) {
416 $this->addTask('CRM-20387 - Add invoice_number column to civicrm_contribution', 'addColumn',
417 'civicrm_contribution', 'invoice_number', "varchar(255) COMMENT 'Human readable invoice number' DEFAULT NULL");
418 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
426 public function upgrade_4_7_25($rev) {
427 $this->addTask("CRM-20927 - Add column to 'civicrm_menu' for additional metadata", 'addColumn',
428 'civicrm_menu', 'module_data', "text COMMENT 'All other menu metadata not stored in other fields'");
429 $this->addTask('CRM-21052 - Determine activity revision policy', 'pickActivityRevisionPolicy');
430 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
431 $this->addTask('Add cancel button text column to civicrm_uf_group', 'addColumn',
432 'civicrm_uf_group', 'cancel_button_text', "varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Custom Text to display on the cancel button when used in create or edit mode'", TRUE);
433 $this->addTask('Add Submit button text column to civicrm_uf_group', 'addColumn',
434 'civicrm_uf_group', 'submit_button_text', "varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL COMMENT 'Custom Text to display on the submit button on profile edit/create screens'", TRUE);
436 $this->addTask('CRM-20958 - Add created_date to civicrm_activity', 'addColumn',
437 'civicrm_activity', 'created_date', "timestamp NULL DEFAULT NULL COMMENT 'When was the activity was created.'");
438 $this->addTask('CRM-20958 - Add modified_date to civicrm_activity', 'addColumn',
439 'civicrm_activity', 'modified_date', "timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'When was the activity (or closely related entity) was created or modified or deleted.'");
440 $this->addTask('CRM-20958 - Add created_date to civicrm_case', 'addColumn',
441 'civicrm_case', 'created_date', "timestamp NULL DEFAULT NULL COMMENT 'When was the case was created.'");
442 $this->addTask('CRM-20958 - Add modified_date to civicrm_case', 'addColumn',
443 'civicrm_case', 'modified_date', "timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'When was the case (or closely related entity) was created or modified or deleted.'");
451 public function upgrade_4_7_27($rev) {
452 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
453 $this->addTask('CRM-20892 Change created_date to default to NULL', 'civiMailingCreatedDateNull');
454 $this->addTask('CRM-21234 Missing subdivisions of Tajikistan', 'tajikistanMissingSubdivisions');
455 $this->addTask('CRM-20892 - Add modified_date to civicrm_mailing', 'addColumn',
456 'civicrm_mailing', 'modified_date', "timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'When the mailing (or closely related entity) was created or modified or deleted.'");
457 $this->addTask('CRM-21195 - Add icon field to civicrm_navigation', 'addColumn',
458 'civicrm_navigation', 'icon', "varchar(255) NULL DEFAULT NULL COMMENT 'CSS class name for an icon'");
459 $this->addTask('CRM-12167 - Add visibility column to civicrm_price_field_value', 'addColumn',
460 'civicrm_price_field_value', 'visibility_id', 'int(10) unsigned DEFAULT 1 COMMENT "Implicit FK to civicrm_option_group with name = \'visibility\'"');
461 $this->addTask('Remove broken Contribution_logging reports', 'removeContributionLoggingReports');
469 public function upgrade_4_7_28($rev) {
470 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
471 $this->addTask('CRM-20572: Fix date fields in save search criteria of Contrib Sybunt custom search ', 'fixDateFieldsInSmartGroups');
472 // CRM-20868 : Update invoice_numbers (in batch) with value in [invoice prefix][contribution id] format
473 if ($invoicePrefix = CRM_Contribute_BAO_Contribution
::checkContributeSettings('invoice_prefix', TRUE)) {
474 list($minId, $maxId) = CRM_Core_DAO
::executeQuery("SELECT coalesce(min(id),0), coalesce(max(id),0)
475 FROM civicrm_contribution ")->getDatabaseResult()->fetchRow();
476 for ($startId = $minId; $startId <= $maxId; $startId +
= self
::BATCH_SIZE
) {
477 $endId = $startId + self
::BATCH_SIZE
- 1;
478 $title = ts("Upgrade DB to %1: Update Contribution Invoice number (%2 => %3)", [
483 $this->addTask($title, 'updateContributionInvoiceNumber', $startId, $endId, $invoicePrefix);
494 public function upgrade_4_7_31($rev) {
495 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
496 $this->addTask('CRM-21225: Add display title field to civicrm_uf_group', 'addColumn', 'civicrm_uf_group', 'frontend_title',
497 "VARCHAR(64) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL COMMENT 'Profile Form Public title'", TRUE);
498 $this->addTask('Rebuild Multilingual Schema', 'rebuildMultilingalSchema');
506 public function upgrade_4_7_32($rev) {
507 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
509 $this->addTask('CRM-21733: Add status_override_end_date field to civicrm_membership table', 'addColumn', 'civicrm_membership', 'status_override_end_date',
510 "date DEFAULT NULL COMMENT 'The end date of membership status override if (Override until selected date) override type is selected.'");
514 * Important! All upgrade functions MUST add a 'runSql' task.
515 * Uncomment and use the following template for a new upgrade version
516 * (change the x in the function name):
520 // * Upgrade function.
522 // * @param string $rev
524 // public function upgrade_4_7_x($rev) {
525 // $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev);
526 // // Additional tasks here...
527 // // Note: do not use ts() in the addTask description because it adds unnecessary strings to transifex.
528 // // The above is an exception because 'Upgrade DB to %1: SQL' is generic & reusable.
536 public static function updateWysiwyg() {
537 $editorID = Civi
::settings()->get('editor_id');
538 // Previously a numeric value indicated one of 4 wysiwyg editors shipped in core, and no value indicated 'Textarea'
539 // Now the options are "Textarea", "CKEditor", and the rest have been dropped from core.
540 $newEditor = $editorID ?
"CKEditor" : "Textarea";
541 Civi
::settings()->set('editor_id', $newEditor);
547 * Migrate any last remaining options from `civicrm_domain.config_backend` to `civicrm_setting`.
548 * Cleanup setting schema.
550 * @param CRM_Queue_TaskContext $ctx
553 public static function migrateSettings(CRM_Queue_TaskContext
$ctx) {
554 // Tip: If there are problems with adding the new uniqueness index, try inspecting:
555 // SELECT name, domain_id, contact_id, count(*) AS dupes FROM civicrm_setting cs GROUP BY name, domain_id, contact_id HAVING dupes > 1;
557 // Nav records are expendable. https://forum.civicrm.org/index.php?topic=36933.0
558 CRM_Core_DAO
::executeQuery('DELETE FROM civicrm_setting WHERE contact_id IS NOT NULL AND name = "navigation"');
560 CRM_Core_DAO
::executeQuery('ALTER TABLE civicrm_setting DROP INDEX index_group_name');
561 CRM_Core_DAO
::executeQuery('ALTER TABLE civicrm_setting DROP COLUMN group_name');
563 // Handle Strange activity_tab_filter settings.
564 CRM_Core_DAO
::executeQuery('CREATE TABLE civicrm_activity_setting LIKE civicrm_setting');
565 CRM_Core_DAO
::executeQuery('ALTER TABLE civicrm_activity_setting ADD UNIQUE INDEX index_domain_contact_name (domain_id, contact_id, name)');
566 CRM_Core_DAO
::executeQuery('INSERT INTO civicrm_activity_setting (name, contact_id, domain_id, value)
567 SELECT DISTINCT name, contact_id, domain_id, value
569 WHERE name = "activity_tab_filter"
570 AND value is not NULL');
571 CRM_Core_DAO
::executeQuery('DELETE FROM civicrm_setting WHERE name = "activity_tab_filter"');
573 $date = CRM_Utils_Time
::getTime('Y-m-d H:i:s');
574 CRM_Core_DAO
::executeQuery('ALTER TABLE civicrm_setting ADD UNIQUE INDEX index_domain_contact_name (domain_id, contact_id, name)');
575 CRM_Core_DAO
::executeQuery("INSERT INTO civicrm_setting (name, contact_id, domain_id, value, is_domain, created_id, created_date)
576 SELECT name, contact_id, domain_id, value, 0, contact_id,'$date'
577 FROM civicrm_activity_setting
578 WHERE name = 'activity_tab_filter'
579 AND value is not NULL"
581 CRM_Core_DAO
::executeQuery('DROP TABLE civicrm_activity_setting');
583 $domainDao = CRM_Core_DAO
::executeQuery('SELECT id, config_backend FROM civicrm_domain');
584 while ($domainDao->fetch()) {
585 $settings = CRM_Upgrade_Incremental_php_FourSeven
::convertBackendToSettings($domainDao->id
, $domainDao->config_backend
);
586 CRM_Core_Error
::debug_var('convertBackendToSettings', [
587 'domainId' => $domainDao->id
,
588 'backend' => $domainDao->config_backend
,
589 'settings' => $settings,
592 foreach ($settings as $name => $value) {
594 1 => [$domainDao->id
, 'Positive'],
595 2 => [$name, 'String'],
596 3 => [serialize($value), 'String'],
598 $settingId = CRM_Core_DAO
::singleValueQuery(
599 'SELECT id FROM civicrm_setting WHERE domain_id = %1 AND name = %2',
602 CRM_Core_DAO
::executeQuery(
603 'INSERT INTO civicrm_setting (domain_id, name, value, is_domain) VALUES (%1,%2,%3,1)',
609 CRM_Core_DAO
::executeQuery('ALTER TABLE civicrm_domain DROP COLUMN config_backend');
615 * Take a config_backend blob and produce an equivalent list of settings.
617 * @param int $domainId
619 * @param string $config_backend
623 public static function convertBackendToSettings($domainId, $config_backend) {
624 if (!$config_backend) {
628 $backend = unserialize($config_backend);
633 $mappings = \CRM_Core_Config_MagicMerge
::getPropertyMap();
635 foreach ($backend as $propertyName => $propertyValue) {
636 if (isset($mappings[$propertyName][0]) && preg_match('/^setting/', $mappings[$propertyName][0])) {
637 // $mapping format: $propertyName => Array(0 => $type, 1 => $setting|NULL).
638 $settingName = isset($mappings[$propertyName][1]) ?
$mappings[$propertyName][1] : $propertyName;
639 $settings[$settingName] = $propertyValue;
647 * Update Invoice number for all completed contribution.
649 * @param \CRM_Queue_TaskContext $ctx
650 * @param int $startID
652 * @param string $invoicePrefix
656 public static function updateContributionInvoiceNumber(CRM_Queue_TaskContext
$ctx, $startID, $endID, $invoicePrefix) {
657 CRM_Core_DAO
::executeQuery("
658 UPDATE `civicrm_contribution` SET `invoice_number` = CONCAT(%1, `id`)
659 WHERE `id` >= %2 AND `id` <= %3 AND `invoice_number` IS NOT NULL",
661 1 => [$invoicePrefix, 'String'],
662 2 => [$startID, 'Integer'],
663 3 => [$endID, 'Integer'],
671 * Add Getting Started dashlet to dashboard
673 * @param \CRM_Queue_TaskContext $ctx
677 public static function addGettingStartedDashlet(CRM_Queue_TaskContext
$ctx) {
678 $sql = "SELECT count(*) FROM civicrm_dashboard WHERE name='getting-started'";
679 $res = CRM_Core_DAO
::singleValueQuery($sql);
680 $domainId = CRM_Core_Config
::domainID();
682 $sql = "INSERT INTO `civicrm_dashboard`
683 ( `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)";
684 CRM_Core_DAO
::executeQuery($sql);
685 // Add default position for Getting Started Dashlet ( left column)
686 $sql = "INSERT INTO `civicrm_dashboard_contact` (dashboard_id, contact_id, column_no, is_active)
687 SELECT (SELECT MAX(id) FROM `civicrm_dashboard`), contact_id, 0, IF (SUM(is_active) > 0, 1, 0)
688 FROM `civicrm_dashboard_contact` JOIN `civicrm_contact` WHERE civicrm_dashboard_contact.contact_id = civicrm_contact.id GROUP BY contact_id";
689 CRM_Core_DAO
::executeQuery($sql);
695 * Migrate on-behalf information to uf_join.module_data as on-behalf columns will be dropped
698 * @param CRM_Queue_TaskContext $ctx
703 public static function migrateOnBehalfOfInfo(CRM_Queue_TaskContext
$ctx) {
704 $domain = new CRM_Core_DAO_Domain();
707 // fetch onBehalf entry in UFJoin table
708 $ufGroupDAO = new CRM_Core_DAO_UFJoin();
709 $ufGroupDAO->module
= 'OnBehalf';
710 $ufGroupDAO->find(TRUE);
712 $forOrgColums = ['is_for_organization'];
713 if ($domain->locales
) {
714 $locales = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $domain->locales
);
715 foreach ($locales as $locale) {
716 $forOrgColums[] = "for_organization_{$locale}";
720 $forOrgColums[] = "for_organization";
724 SELECT " . implode(", ", $forOrgColums) . ", uj.id as join_id, uj.uf_group_id as uf_group_id
725 FROM civicrm_contribution_page cp
726 INNER JOIN civicrm_uf_join uj ON uj.entity_id = cp.id AND uj.module = 'OnBehalf'";
727 $dao = CRM_Core_DAO
::executeQuery($query, [], TRUE, NULL, FALSE, FALSE);
730 while ($dao->fetch()) {
731 $onBehalfParams['on_behalf'] = ['is_for_organization' => $dao->is_for_organization
];
732 if ($domain->locales
) {
733 foreach ($locales as $locale) {
734 $for_organization = "for_organization_{$locale}";
735 $onBehalfParams['on_behalf'] +
= [
737 'for_organization' => $dao->$for_organization,
743 $onBehalfParams['on_behalf'] +
= [
745 'for_organization' => $dao->for_organization
,
750 'id' => $dao->join_id
,
751 'module' => 'on_behalf',
752 'uf_group_id' => $dao->uf_group_id
,
753 'module_data' => json_encode($onBehalfParams),
755 CRM_Core_BAO_UFJoin
::create($ufJoinParam);
763 * v4.7.11 adds a new setting "remote_profile_submissions". This is
764 * long-standing feature that existing sites may be using; however, it's
765 * a bit prone to abuse. For new sites, the default is to disable it
766 * (since that is more secure). For existing sites, the default is to
767 * enable it (since that is more compatible).
769 * @param \CRM_Queue_TaskContext $ctx
773 public static function migrateRemoteSubmissionsSetting(CRM_Queue_TaskContext
$ctx) {
774 $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");
775 while ($domains->fetch()) {
776 CRM_Core_DAO
::executeQuery(
777 "INSERT INTO civicrm_setting (`name`, `value`, `domain_id`, `is_domain`, `contact_id`, `component_id`, `created_date`, `created_id`)
778 VALUES (%2, %3, %4, %5, NULL, NULL, %6, NULL)",
780 2 => ['remote_profile_submissions', 'String'],
781 3 => ['s:1:"1";', 'String'],
782 4 => [$domains->id
, 'Integer'],
784 6 => [date('Y-m-d H:i:s'), 'String'],
792 * CRM-11782 - Get rid of VALUE_SEPARATOR character in saved search form values
794 * @param \CRM_Queue_TaskContext $ctx
798 public static function fixContactTypeInSmartGroups(CRM_Queue_TaskContext
$ctx) {
799 $sep = CRM_Core_DAO
::VALUE_SEPARATOR
;
800 $dao = CRM_Core_DAO
::executeQuery("SELECT id, form_values FROM civicrm_saved_search WHERE form_values LIKE '%$sep%'");
801 while ($dao->fetch()) {
802 $formValues = unserialize($dao->form_values
);
803 if (isset($formValues['contact_type']) && is_array($formValues['contact_type'])) {
805 foreach ($formValues['contact_type'] as $key => $val) {
806 $newVals[str_replace($sep, '__', $key)] = is_string($val) ?
str_replace($sep, '__', $val) : $val;
808 $formValues['contact_type'] = $newVals;
810 CRM_Core_DAO
::executeQuery("UPDATE civicrm_saved_search SET form_values = %1 WHERE id = {$dao->id}", [1 => [serialize($formValues), 'String']]);
817 * CRM-17637 - Ths file location has been moved; delete the old one
819 * @param \CRM_Queue_TaskContext $ctx
823 public static function deleteVersionCheckCacheFile(CRM_Queue_TaskContext
$ctx) {
824 $config = CRM_Core_Config
::singleton();
825 $cacheFile = $config->uploadDir
. 'version-info-cache.json';
826 if (file_exists($cacheFile)) {
833 * CRM-17669 and CRM-17686, make scheduled jobs more flexible, disable the 4.6 extension if installed
835 * @param \CRM_Queue_TaskContext $ctx
839 public static function disableFlexibleJobsExtension(CRM_Queue_TaskContext
$ctx) {
841 civicrm_api3('Extension', 'disable', ['key' => 'com.klangsoft.flexiblejobs']);
843 catch (CiviCRM_API3_Exception
$e) {
844 // just ignore if the extension isn't installed
851 * CRM-17752 add index to civicrm_financial_trxn.trxn_id (deliberately non-unique).
853 * @param \CRM_Queue_TaskContext $ctx
857 public static function addIndexFinancialTrxnTrxnID(CRM_Queue_TaskContext
$ctx) {
858 $tables = ['civicrm_financial_trxn' => ['trxn_id']];
859 CRM_Core_BAO_SchemaHandler
::createIndexes($tables);
864 * CRM-17882 Add index to civicrm_contribution.credit_note_id.
866 * @param \CRM_Queue_TaskContext $ctx
870 public static function addIndexContributionCreditNoteID(CRM_Queue_TaskContext
$ctx) {
871 $tables = ['civicrm_contribution' => ['creditnote_id']];
872 CRM_Core_BAO_SchemaHandler
::createIndexes($tables);
877 * CRM-17775 Add correct index for table civicrm_financial_item.
879 * Note that the entity ID should always precede the entity_table as
880 * it is more unique. This is better for performance and does not cause fallback
881 * to no index if table it omitted.
885 public static function addCombinedIndexFinancialItemEntityIDEntityType() {
886 CRM_Core_BAO_SchemaHandler
::dropIndexIfExists('civicrm_financial_item', 'UI_id');
887 CRM_Core_BAO_SchemaHandler
::dropIndexIfExists('civicrm_financial_item', 'IX_Entity');
888 CRM_Core_BAO_SchemaHandler
::createIndexes([
889 'civicrm_financial_item' => [['entity_id', 'entity_table']],
895 * CRM-17951 Add accounts option values for refund and chargeback.
897 * Add Chargeback contribution status and Chargeback and Contra account relationships,
898 * checking first if one exists.
900 public static function addRefundAndChargeBackAccountsIfNotExist() {
901 // First we enable and edit the record for Credit contra - this exists but is disabled for most sites.
902 // Using the ensure function (below) will not enabled a disabled option (by design).
903 CRM_Core_DAO
::executeQuery("UPDATE civicrm_option_value v
904 INNER JOIN civicrm_option_group g on v.option_group_id=g.id and g.name='account_relationship'
905 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'
906 WHERE v.name = 'Credit/Contra Account is';");
908 CRM_Core_BAO_OptionValue
::ensureOptionValueExists([
909 'option_group_id' => 'account_relationship',
910 'name' => 'Chargeback Account is',
911 'label' => ts('Chargeback Account is'),
913 'component_id' => 'CiviContribute',
916 CRM_Core_BAO_OptionValue
::ensureOptionValueExists([
917 'option_group_id' => 'contribution_status',
918 'name' => 'Chargeback',
919 'label' => ts('Chargeback'),
921 'component_id' => 'CiviContribute',
927 * CRM-17999 Add index to civicrm_contribution.source.
929 * @param \CRM_Queue_TaskContext $ctx
933 public static function addIndexContributionSource(CRM_Queue_TaskContext
$ctx) {
934 CRM_Core_BAO_SchemaHandler
::createIndexes(['civicrm_contribution' => ['source']]);
939 * CRM-18124 Add index to civicrm_contribution.total_amount.
941 * Note that I made this a combined index with receive_date because the issue included
942 * both criteria and they seemed likely to be used in conjunction to me in other cases.
944 * @param \CRM_Queue_TaskContext $ctx
948 public static function addIndexContributionAmount(CRM_Queue_TaskContext
$ctx) {
949 CRM_Core_BAO_SchemaHandler
::createIndexes([
950 'civicrm_contribution' => [['total_amount', 'receive_date']],
956 * CRM-18124 Add index to civicrm_contribution.total_amount.
958 * Note that I made this a combined index with receive_date because the issue included
959 * both criteria and they seemed likely to be used in conjunction to me in other cases.
961 * @param \CRM_Queue_TaskContext $ctx
965 public static function addDeletedByMergeActivityType(CRM_Queue_TaskContext
$ctx) {
966 CRM_Core_BAO_OptionValue
::ensureOptionValueExists([
967 'option_group_id' => 'activity_type',
968 'name' => 'Contact Deleted by Merge',
969 'label' => ts('Contact Deleted by Merge'),
970 'description' => ts('Contact was merged into another contact'),
978 * CRM-12252 Add Help Pre and Help Post Fields for Price Field Value Table.
980 * @param \CRM_Queue_TaskContext $ctx
984 public static function addHelpPreAndHelpPostFieldsPriceFieldValue(CRM_Queue_TaskContext
$ctx) {
985 $domain = new CRM_Core_DAO_Domain();
987 if ($domain->locales
) {
988 $locales = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $domain->locales
);
989 foreach ($locales as $locale) {
990 if (!CRM_Core_BAO_SchemaHandler
::checkIfFieldExists("civicrm_price_field_value", "help_pre_{$locale}")) {
991 CRM_Core_DAO
::executeQuery("ALTER TABLE `civicrm_price_field_value`
992 ADD COLUMN `help_pre_{$locale}` text COLLATE utf8_unicode_ci COMMENT 'Price field option pre help text.'", [], TRUE, NULL, FALSE, FALSE);
994 if (!CRM_Core_BAO_SchemaHandler
::checkIfFieldExists("civicrm_price_field_value", "help_post_{$locale}")) {
995 CRM_Core_DAO
::executeQuery("ALTER TABLE `civicrm_price_field_value`
996 ADD COLUMN `help_post_{$locale}` text COLLATE utf8_unicode_ci COMMENT 'Price field option post help text.'", [], TRUE, NULL, FALSE, FALSE);
999 CRM_Core_I18n_Schema
::rebuildMultilingualSchema($locales, NULL, TRUE);
1002 if (!CRM_Core_BAO_SchemaHandler
::checkIfFieldExists('civicrm_price_field_value', 'help_pre')) {
1003 CRM_Core_DAO
::executeQuery("ALTER TABLE `civicrm_price_field_value`
1004 ADD COLUMN `help_pre` text COLLATE utf8_unicode_ci COMMENT 'Price field option pre help text.'");
1006 if (!CRM_Core_BAO_SchemaHandler
::checkIfFieldExists('civicrm_price_field_value', 'help_post')) {
1007 CRM_Core_DAO
::executeQuery("ALTER TABLE `civicrm_price_field_value`
1008 ADD COLUMN `help_post` text COLLATE utf8_unicode_ci COMMENT 'Price field option post help text.'");
1015 * CRM-18464 Check if Foreign key exists and also drop any index of same name accidentially created.
1017 * @param \CRM_Queue_TaskContext $ctx
1021 public static function dropActionScheudleMappingForeignKey(CRM_Queue_TaskContext
$ctx) {
1022 CRM_Core_BAO_SchemaHandler
::safeRemoveFK('civicrm_action_schedule', 'FK_civicrm_action_schedule_mapping_id');
1027 * CRM-18345 Don't delete mailing data on email/phone deletion
1028 * Implemented here in CRM-18526
1030 * @param \CRM_Queue_TaskContext $ctx
1034 public static function upgradeMailingFKs(CRM_Queue_TaskContext
$ctx) {
1036 // Safely drop the foreign keys
1037 CRM_Core_BAO_SchemaHandler
::safeRemoveFK('civicrm_mailing_event_queue', 'FK_civicrm_mailing_event_queue_email_id');
1038 CRM_Core_BAO_SchemaHandler
::safeRemoveFK('civicrm_mailing_event_queue', 'FK_civicrm_mailing_event_queue_phone_id');
1039 CRM_Core_BAO_SchemaHandler
::safeRemoveFK('civicrm_mailing_recipients', 'FK_civicrm_mailing_recipients_email_id');
1040 CRM_Core_BAO_SchemaHandler
::safeRemoveFK('civicrm_mailing_recipients', 'FK_civicrm_mailing_recipients_phone_id');
1042 // Set up the new foreign keys
1043 CRM_Core_DAO
::executeQuery("SET FOREIGN_KEY_CHECKS = 0;");
1045 CRM_Core_DAO
::executeQuery("
1046 ALTER TABLE `civicrm_mailing_event_queue`
1047 ADD CONSTRAINT `FK_civicrm_mailing_event_queue_email_id`
1048 FOREIGN KEY (`email_id`)
1049 REFERENCES `civicrm_email`(`id`)
1054 CRM_Core_DAO
::executeQuery("
1055 ALTER TABLE `civicrm_mailing_event_queue`
1056 ADD CONSTRAINT `FK_civicrm_mailing_event_queue_phone_id`
1057 FOREIGN KEY (`phone_id`)
1058 REFERENCES `civicrm_phone`(`id`)
1063 CRM_Core_DAO
::executeQuery("
1064 ALTER TABLE `civicrm_mailing_recipients`
1065 ADD CONSTRAINT `FK_civicrm_mailing_recipients_email_id`
1066 FOREIGN KEY (`email_id`)
1067 REFERENCES `civicrm_email`(`id`)
1072 CRM_Core_DAO
::executeQuery("
1073 ALTER TABLE `civicrm_mailing_recipients`
1074 ADD CONSTRAINT `FK_civicrm_mailing_recipients_phone_id`
1075 FOREIGN KEY (`phone_id`)
1076 REFERENCES `civicrm_phone`(`id`)
1081 CRM_Core_DAO
::executeQuery("SET FOREIGN_KEY_CHECKS = 1;");
1087 * CRM-17663 - Dashboard schema changes
1089 * @param \CRM_Queue_TaskContext $ctx
1093 public static function dashboardSchemaUpdate(CRM_Queue_TaskContext
$ctx) {
1094 if (!CRM_Core_BAO_SchemaHandler
::checkIfIndexExists('civicrm_dashboard_contact', 'index_dashboard_id_contact_id')) {
1095 // Delete any stray duplicate rows and add unique index to prevent new dupes and enable INSERT/UPDATE combo query
1096 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');
1097 CRM_Core_DAO
::executeQuery('ALTER TABLE civicrm_dashboard_contact ADD UNIQUE INDEX index_dashboard_id_contact_id (dashboard_id, contact_id);');
1099 $domain = new CRM_Core_DAO_Domain();
1100 $domain->find(TRUE);
1101 CRM_Core_BAO_SchemaHandler
::dropColumn('civicrm_dashboard_contact', 'content', FALSE, TRUE);
1102 CRM_Core_BAO_SchemaHandler
::dropColumn('civicrm_dashboard_contact', 'is_minimized', FALSE, TRUE);
1103 CRM_Core_BAO_SchemaHandler
::dropColumn('civicrm_dashboard_contact', 'is_fullscreen', FALSE, TRUE);
1104 CRM_Core_BAO_SchemaHandler
::dropColumn('civicrm_dashboard_contact', 'created_date', FALSE, TRUE);
1105 CRM_Core_BAO_SchemaHandler
::dropColumn('civicrm_dashboard', 'is_fullscreen', FALSE, TRUE);
1106 CRM_Core_BAO_SchemaHandler
::dropColumn('civicrm_dashboard', 'is_minimized', FALSE, TRUE);
1107 CRM_Core_BAO_SchemaHandler
::dropColumn('civicrm_dashboard', 'column_no', FALSE, TRUE);
1108 CRM_Core_BAO_SchemaHandler
::dropColumn('civicrm_dashboard', 'weight', FALSE, TRUE);
1110 CRM_Core_DAO
::executeQuery('UPDATE civicrm_dashboard SET url = REPLACE(url, "&snippet=5", ""), fullscreen_url = REPLACE(fullscreen_url, "&snippet=5", "")');
1112 if (!CRM_Core_BAO_SchemaHandler
::checkIfFieldExists('civicrm_dashboard', 'cache_minutes')) {
1113 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."',
1114 [], TRUE, NULL, FALSE, FALSE);
1116 if ($domain->locales
) {
1117 $locales = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $domain->locales
);
1118 CRM_Core_I18n_Schema
::rebuildMultilingualSchema($locales, NULL, TRUE);
1121 CRM_Core_DAO
::executeQuery('UPDATE civicrm_dashboard SET cache_minutes = 1440 WHERE name = "blog"');
1122 CRM_Core_DAO
::executeQuery('UPDATE civicrm_dashboard SET cache_minutes = 7200 WHERE name IN ("activity","getting-started")');
1127 * CRM-19100 - Alter Index and Type for Image URL
1130 public static function alterIndexAndTypeForImageURL() {
1132 CRM_Core_BAO_SchemaHandler
::dropIndexIfExists('civicrm_contact', 'index_image_url');
1133 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.'");
1135 $length['civicrm_contact']['image_URL'] = 128;
1136 CRM_Core_BAO_SchemaHandler
::createIndexes(['civicrm_contact' => ['image_URL']], 'index', $length);
1142 * Add mailing template type.
1146 public static function addMailingTemplateType() {
1147 if (!CRM_Core_BAO_SchemaHandler
::checkIfFieldExists('civicrm_mailing', 'template_type', FALSE)) {
1148 CRM_Core_DAO
::executeQuery('
1149 ALTER TABLE civicrm_mailing
1150 ADD COLUMN `template_type` varchar(64) NOT NULL DEFAULT \'traditional\' COMMENT \'The language/processing system used for email templates.\',
1151 ADD COLUMN `template_options` longtext COMMENT \'Advanced options used by the email templating system. (JSON encoded)\'
1158 * CRM-18651 Add DataType column to Option Group Table
1161 public static function addDataTypeColumnToOptionGroupTable() {
1162 if (!CRM_Core_BAO_SchemaHandler
::checkIfFieldExists('civicrm_option_group', 'data_type')) {
1163 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.'",
1164 [], TRUE, NULL, FALSE, FALSE);
1166 $domain = new CRM_Core_DAO_Domain();
1167 $domain->find(TRUE);
1168 if ($domain->locales
) {
1169 $locales = explode(CRM_Core_DAO
::VALUE_SEPARATOR
, $domain->locales
);
1170 CRM_Core_I18n_Schema
::rebuildMultilingualSchema($locales, NULL, TRUE);
1173 CRM_Core_DAO
::executeQuery("UPDATE `civicrm_option_group` SET `data_type` = 'Integer'
1174 WHERE name IN ('activity_type', 'gender', 'payment_instrument', 'participant_role', 'event_type')");
1179 * CRM-19372 Add field to store accepted credit credit cards for a payment processor.
1182 public static function addWysiwygPresets() {
1183 CRM_Core_BAO_OptionGroup
::ensureOptionGroupExists([
1184 'name' => 'wysiwyg_presets',
1185 'title' => ts('WYSIWYG Editor Presets'),
1189 'default' => ['label' => ts('Default'), 'is_default' => 1],
1190 'civimail' => ['label' => ts('CiviMail'), 'component_id' => 'CiviMail'],
1191 'civievent' => ['label' => ts('CiviEvent'), 'component_id' => 'CiviEvent'],
1193 foreach ($values as $name => $value) {
1194 CRM_Core_BAO_OptionValue
::ensureOptionValueExists($value +
[
1196 'option_group_id' => 'wysiwyg_presets',
1199 $fileName = Civi
::paths()->getPath('[civicrm.files]/persist/crm-ckeditor-config.js');
1200 // Ensure the config file contains the allowedContent setting
1201 if (file_exists($fileName)) {
1202 $config = file_get_contents($fileName);
1203 $pos = strrpos($config, '};');
1204 $setting = "\n\tconfig.allowedContent = true;\n";
1205 $config = substr_replace($config, $setting, $pos, 0);
1207 $newFileName = Civi
::paths()->getPath('[civicrm.files]/persist/crm-ckeditor-default.js');
1208 file_put_contents($newFileName, $config);
1214 * Update Kenyan Provinces to reflect changes per CRM-20062
1216 * @param \CRM_Queue_TaskContext $ctx
1218 public static function updateKenyanProvinces(CRM_Queue_TaskContext
$ctx) {
1219 $kenyaCountryID = CRM_Core_DAO
::singleValueQuery('SELECT max(id) from civicrm_country where iso_code = "KE"');
1221 'Nairobi Municipality',
1223 'North-Eastern Kaskazini Mashariki',
1225 'Western Magharibi',
1227 self
::deprecateStateProvinces($kenyaCountryID, $oldProvinces);
1232 * Deprecate provinces that no longer exist.
1234 * @param int $countryID
1235 * @param array $provinces
1237 public static function deprecateStateProvinces($countryID, $provinces) {
1238 foreach ($provinces as $province) {
1239 $existingStateID = CRM_Core_DAO
::singleValueQuery("
1240 SELECT id FROM civicrm_state_province
1241 WHERE country_id = %1
1244 [1 => [$countryID, 'Int'], 2 => [$province, 'String']]);
1246 if (!$existingStateID) {
1249 if (!CRM_Core_DAO
::singleValueQuery("
1250 SELECT count(*) FROM civicrm_address
1251 WHERE state_province_id = %1
1252 ", [1 => [$existingStateID, 'Int']])
1254 CRM_Core_DAO
::executeQuery("DELETE FROM civicrm_state_province WHERE id = %1", [1 => [$existingStateID, 'Int']]);
1257 $params = ['1' => [ts("Former - $province"), 'String']];
1258 CRM_Core_DAO
::executeQuery("
1259 UPDATE civicrm_state_province SET name = %1 WHERE id = $existingStateID
1267 * Poputate newly added domain id column and add foriegn key onto table.
1269 public static function populateSMSProviderDomainId() {
1270 $count = CRM_Core_DAO
::singleValueQuery("SELECT count(id) FROM civicrm_domain");
1272 CRM_Core_DAO
::executeQuery("UPDATE civicrm_sms_provider SET domain_id = (SELECT id FROM civicrm_domain)");
1274 if (!parent
::checkFKExists('civicrm_sms_provider', 'FK_civicrm_sms_provider_domain_id')) {
1275 CRM_Core_DAO
::executeQuery("SET FOREIGN_KEY_CHECKS = 0;");
1276 CRM_Core_DAO
::executeQuery("ALTER TABLE `civicrm_sms_provider`
1277 ADD CONSTRAINT FK_civicrm_sms_provider_domain_id
1278 FOREIGN KEY (`domain_id`) REFERENCES `civicrm_domain`(`id`)
1279 ON DELETE SET NULL");
1281 CRM_Core_DAO
::executeQuery("SET FOREIGN_KEY_CHECKS = 1;");
1287 * CRM-16633 - Add activity type for Change Case Status
1289 * @param \CRM_Queue_TaskContext $ctx
1293 public static function addChangeCaseSubjectActivityType(CRM_Queue_TaskContext
$ctx) {
1294 CRM_Core_BAO_OptionValue
::ensureOptionValueExists([
1295 'option_group_id' => 'activity_type',
1296 'name' => 'Change Case Subject',
1297 'label' => ts('Change Case Subject'),
1298 'is_active' => TRUE,
1299 'component_id' => 'CiviCase',
1300 'icon' => 'fa-pencil-square-o',
1306 * CRM-19986 fix schema differnces in civicrm_action_schedule
1308 public static function fixSchemaOnCiviCRMActionSchedule() {
1309 if (!parent
::checkFKExists('civicrm_action_schedule', 'FK_civicrm_action_schedule_sms_template_id')) {
1310 CRM_Core_DAO
::executeQuery("ALTER TABLE `civicrm_action_schedule`
1311 ADD CONSTRAINT FK_civicrm_action_schedule_sms_template_id
1312 FOREIGN KEY (`sms_template_id`) REFERENCES `civicrm_msg_template`(`id`)
1313 ON DELETE SET NULL");
1315 CRM_Core_DAO
::executeQuery("ALTER TABLE `civicrm_action_schedule`
1316 CHANGE `mapping_id` `mapping_id` varchar(64) COLLATE
1317 utf8_unicode_ci DEFAULT NULL COMMENT 'Name/ID of the mapping to use on this table'");
1321 public static function pickActivityRevisionPolicy(CRM_Queue_TaskContext
$ctx) {
1322 // CRM-21052 - If site is using activity revisions, continue doing so. Otherwise, switch out.
1323 $count = CRM_Core_DAO
::singleValueQuery('SELECT count(*) FROM civicrm_activity WHERE is_current_revision = 0 OR original_id IS NOT NULL');
1324 Civi
::settings()->set('civicaseActivityRevisions', $count > 0);
1329 * Add in missing Tajikistan Subdivisions
1331 * @param \CRM_Queue_TaskContext $ctx
1335 public static function tajikistanMissingSubdivisions(CRM_Queue_TaskContext
$ctx) {
1336 $sql = 'INSERT INTO civicrm_state_province (id, country_id, abbreviation, name) VALUES';
1338 if (!CRM_Core_DAO
::singleValueQuery("Select id FROM civicrm_state_province WHERE country_id = 1209 AND name = 'Dushanbe'")) {
1339 $updates[] = '(NULL, 1209, "DU", "Dushanbe")';
1341 if (!CRM_Core_DAO
::singleValueQuery("Select id FROM civicrm_state_province WHERE country_id = 1209 AND name = 'Nohiyahoi Tobei JumhurĂ'")) {
1342 $updates[] = '(NULL, 1209, "RA", "Nohiyahoi Tobei JumhurĂ")';
1344 if (!empty($updates)) {
1345 CRM_Core_DAO
::executeQuery($sql . implode(', ', $updates));
1351 * Remove the contribution logging reports which have been broken for a very long time.
1353 * @param \CRM_Queue_TaskContext $ctx
1357 public static function removeContributionLoggingReports(CRM_Queue_TaskContext
$ctx) {
1358 if (class_exists('CRM_Report_Form_Contribute_LoggingDetail') ||
class_exists('CRM_Report_Form_Contribute_LoggingSummary')) {
1359 // Perhaps the site has overridden these classes. The core ones are broken but they
1360 // may have functional ones.
1363 $options = civicrm_api3('OptionValue', 'get', ['option_group_id' => 'report_template', 'options' => ['limit' => 0]]);
1364 foreach ($options['values'] as $option) {
1365 if ($option['name'] === 'CRM_Report_Form_Contribute_LoggingDetail' ||
$option['name'] === 'CRM_Report_Form_Contribute_LoggingSummary') {
1366 $instances = civicrm_api3('ReportInstance', 'get', ['report_id' => $option['value']]);
1367 if ($instances['count']) {
1368 foreach ($instances['values'] as $instance) {
1369 if ($instance['navigation_id']) {
1370 civicrm_api3('Navigation', 'delete', ['id' => $instance['navigation_id']]);
1372 civicrm_api3('ReportInstance', 'delete', ['id' => $instance['id']]);
1375 civicrm_api3('OptionValue', 'delete', ['id' => $option['id']]);
1384 protected function checkImageUploadDir() {
1385 $config = CRM_Core_Config
::singleton();
1386 $check = new CRM_Utils_Check_Component_Security();
1387 return $config->imageUploadDir
&& $config->imageUploadURL
&& $check->isDirAccessible($config->imageUploadDir
, $config->imageUploadURL
);
1391 * CRM-20572 - Format date fields in Contrib Sybunt custom search's saved criteria.
1393 * @param \CRM_Queue_TaskContext $ctx
1397 public static function fixDateFieldsInSmartGroups(CRM_Queue_TaskContext
$ctx) {
1398 $dao = CRM_Core_DAO
::executeQuery("SELECT id, form_values FROM civicrm_saved_search WHERE form_values LIKE '%CRM_Contact_Form_Search_Custom_ContribSYBNT%'");
1399 while ($dao->fetch()) {
1400 $formValues = unserialize($dao->form_values
);
1401 CRM_Contact_Form_Search_Custom_ContribSYBNT
::formatSavedSearchFields($formValues);
1402 CRM_Core_DAO
::executeQuery("UPDATE civicrm_saved_search SET form_values = %1 WHERE id = {$dao->id}", [1 => [serialize($formValues), 'String']]);
1408 * CRM-20892 Convert default of created_date in civicrm_mailing table to NULL
1411 public static function civiMailingCreatedDateNull(CRM_Queue_TaskContext
$ctx) {
1412 $dataType = 'timestamp';
1413 if (CRM_Utils_Check_Component_Timestamps
::isFieldType('civicrm_mailing', 'created_date', 'datetime')) {
1414 $dataType = 'datetime';
1416 CRM_Core_DAO
::executeQuery("ALTER TABLE civicrm_mailing CHANGE created_date created_date {$dataType} NULL DEFAULT NULL COMMENT 'Date and time this mailing was created.'");