Merge pull request #21555 from eileenmcnaughton/money
[civicrm-core.git] / CRM / Upgrade / Incremental / php / FiveFortyThree.php
CommitLineData
1e9edcc0
C
1<?php
2/*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12/**
9f3b9e96
CW
13 * Upgrade logic for FiveFortyThree
14 */
1e9edcc0
C
15class CRM_Upgrade_Incremental_php_FiveFortyThree extends CRM_Upgrade_Incremental_Base {
16
17 /**
18 * Compute any messages which should be displayed beforeupgrade.
19 *
20 * Note: This function is called iteratively for each incremental upgrade step.
21 * There must be a concrete step (eg 'X.Y.Z.mysql.tpl' or 'upgrade_X_Y_Z()').
22 *
23 * @param string $preUpgradeMessage
24 * @param string $rev
25 * a version number, e.g. '4.4.alpha1', '4.4.beta3', '4.4.0'.
26 * @param null $currentVer
27 */
28 public function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL) {
29 // Example: Generate a pre-upgrade message.
c66497f0
EM
30 if ($rev === '5.43.alpha1' && !empty(CRM_Core_Component::getEnabledComponents()['CiviCase'])) {
31 $preUpgradeMessage .= '<p>' . ts('Minor changes have been made to how the tokens to render case.is_deleted, case.created_date and case.modified_date. See https://docs.civicrm.org/sysadmin/en/latest/upgrade/version-specific/ for more') . '</p>';
32 }
1e9edcc0
C
33 }
34
35 /**
36 * Compute any messages which should be displayed after upgrade.
37 *
38 * Note: This function is called iteratively for each incremental upgrade step.
39 * There must be a concrete step (eg 'X.Y.Z.mysql.tpl' or 'upgrade_X_Y_Z()').
40 *
41 * @param string $postUpgradeMessage
42 * alterable.
43 * @param string $rev
44 * an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs.
45 */
46 public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
47 // Example: Generate a post-upgrade message.
48 // if ($rev == '5.12.34') {
49 // $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'.");
50 // }
51 }
52
f210208f
SL
53 /**
54 * Upgrade function.
55 *
56 * @param string $rev
57 */
1f7cb15c 58 public function upgrade_5_43_alpha1(string $rev): void {
f210208f
SL
59 $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
60 $this->addTask('Fix DB Collation if needed on the relatonship cache table', 'fixRelationshipCacheTableCollation');
9f3b9e96 61 $this->addTask('Make mapping field foreign key cascade delete', 'alterMappingFK');
1f7cb15c
EM
62 $this->addTask('Replace legacy displayName smarty token in Online contribution workflow template',
63 'updateMessageToken', 'contribution_online_receipt', '$displayName', 'contact.display_name', $rev
64 );
65 $this->addTask('Replace legacy first_name smarty token in Online contribution workflow template',
66 'updateMessageToken', 'contribution_online_receipt', '$first_name', 'contact.first_name', $rev
67 );
68 $this->addTask('Replace legacy last_name smarty token in Online contribution workflow template',
69 'updateMessageToken', 'contribution_online_receipt', '$last_name', 'contact.last_name', $rev
70 );
eac0a5bf
EM
71 $this->addTask('Replace membership status token in action schedule',
72 'updateActionScheduleToken', 'membership.status', 'membership.status_id:label', $rev
73 );
74 $this->addTask('Replace membership type token in action schedule',
75 'updateActionScheduleToken', 'membership.type', 'membership.membership_type_id:label', $rev
76 );
8ff591cb
EM
77 $this->addTask('Replace duplicate event title token in event badges',
78 'updatePrintLabelToken', 'participant.event_title', 'event.title', $rev
79 );
80 $this->addTask('Replace duplicate event start date token in event badges',
81 'updatePrintLabelToken', 'participant.event_start_date', 'event.start_date', $rev
82 );
83 $this->addTask('Replace duplicate event end date token in event badges',
84 'updatePrintLabelToken', 'participant.event_end_date', 'event.end_date', $rev
85 );
b7472bd6
EM
86 $this->addTask('Update participant status id token in event badges',
87 'updatePrintLabelToken', 'participant.participant_status_id', 'participant.status_id', $rev
88 );
89 $this->addTask('Update participant role id token in event badges',
90 'updatePrintLabelToken', 'participant.participant_role_id', 'participant.role_id', $rev
91 );
92 $this->addTask('Update participant role label token in event badges',
93 'updatePrintLabelToken', 'participant.participant_role', 'participant.role_id:label', $rev
94 );
95 $this->addTask('Update participant register date token in event badges',
96 'updatePrintLabelToken', 'participant.participant_register_date', 'participant.register_date', $rev
97 );
98 $this->addTask('Update participant source token in event badges',
99 'updatePrintLabelToken', 'participant.participant_source', 'participant.source', $rev
100 );
101 $this->addTask('Update participant fee level token in event badges',
102 'updatePrintLabelToken', 'participant.participant_fee_level', 'participant.fee_level', $rev
103 );
104 $this->addTask('Update participant fee amount token in event badges',
105 'updatePrintLabelToken', 'participant.participant_fee_amount', 'participant.fee_amount', $rev
106 );
107 $this->addTask('Update participant registered by id token in event badges',
108 'updatePrintLabelToken', 'participant.participant_registered_by_id', 'participant.registered_by_id', $rev
109 );
110
f210208f 111 }
1e9edcc0 112
9f3b9e96
CW
113 /**
114 * @param \CRM_Queue_TaskContext $ctx
115 *
116 * @return bool
117 */
118 public static function alterMappingFK(CRM_Queue_TaskContext $ctx): bool {
119 CRM_Core_BAO_SchemaHandler::safeRemoveFK('civicrm_mapping_field', 'FK_civicrm_mapping_field_mapping_id');
120 CRM_Core_DAO::executeQuery('
121 ALTER TABLE civicrm_mapping_field
122 ADD CONSTRAINT `FK_civicrm_mapping_field_mapping_id`
123 FOREIGN KEY (`mapping_id`)
124 REFERENCES `civicrm_mapping`(`id`) ON DELETE CASCADE
125 ', [], TRUE, NULL, FALSE, FALSE);
126 return TRUE;
127 }
128
f210208f
SL
129 public static function fixRelationshipCacheTableCollation():bool {
130 $contactTableCollation = CRM_Core_BAO_SchemaHandler::getInUseCollation();
131 $dao = CRM_Core_DAO::executeQuery('SHOW TABLE STATUS LIKE \'civicrm_relationship_cache\'');
132 $dao->fetch();
133 $relationshipCacheCollation = $dao->Collation;
134 $characterSet = 'utf8';
135 if (stripos($contactTableCollation, 'utf8mb4') !== FALSE) {
136 $characterSet = 'utf8mb4';
137 }
138 if ($contactTableCollation !== $relationshipCacheCollation) {
9bf72461 139 CRM_Core_BAO_SchemaHandler::migrateUtf8mb4(($characterSet === 'utf8mb4' ? FALSE : TRUE), ['%civicrm_relationship_cache%']);
f210208f
SL
140 }
141 return TRUE;
142 }
1e9edcc0
C
143
144}