Commit | Line | Data |
---|---|---|
29ba40ec 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 | /** | |
13 | * Upgrade logic for FiveThirtyOne */ | |
14 | class CRM_Upgrade_Incremental_php_FiveThirtyOne extends CRM_Upgrade_Incremental_Base { | |
15 | ||
16 | /** | |
17 | * Compute any messages which should be displayed beforeupgrade. | |
18 | * | |
19 | * Note: This function is called iteratively for each upcoming | |
20 | * revision to the database. | |
21 | * | |
22 | * @param string $preUpgradeMessage | |
23 | * @param string $rev | |
24 | * a version number, e.g. '4.4.alpha1', '4.4.beta3', '4.4.0'. | |
25 | * @param null $currentVer | |
26 | */ | |
27 | public function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL) { | |
28 | // Example: Generate a pre-upgrade message. | |
29 | // if ($rev == '5.12.34') { | |
30 | // $preUpgradeMessage .= '<p>' . ts('A new permission, "%1", has been added. This permission is now used to control access to the Manage Tags screen.', array(1 => ts('manage tags'))) . '</p>'; | |
31 | // } | |
32 | } | |
33 | ||
34 | /** | |
35 | * Compute any messages which should be displayed after upgrade. | |
36 | * | |
37 | * @param string $postUpgradeMessage | |
38 | * alterable. | |
39 | * @param string $rev | |
40 | * an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs. | |
41 | */ | |
42 | public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) { | |
43 | // Example: Generate a post-upgrade message. | |
44 | // if ($rev == '5.12.34') { | |
45 | // $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'."); | |
46 | // } | |
47 | } | |
48 | ||
49 | /* | |
50 | * Important! All upgrade functions MUST add a 'runSql' task. | |
51 | * Uncomment and use the following template for a new upgrade version | |
52 | * (change the x in the function name): | |
53 | */ | |
54 | ||
ae1baeec SL |
55 | /** |
56 | * Upgrade function. | |
57 | * | |
58 | * @param string $rev | |
59 | */ | |
60 | public function upgrade_5_31_alpha1($rev) { | |
35fd9d21 SL |
61 | $this->addTask('Expand internal civicrm group title field to be 255 in length', 'grouptitlefieldExpand'); |
62 | $this->addTask('Add in optional public title group table', 'addColumn', 'civicrm_group', 'frontend_title', "varchar(255) DEFAULT NULL COMMENT 'Alternative public title for this Group.'", TRUE, '5.31.alpha1', FALSE); | |
63 | $this->addTask('Add in optional public description group table', 'addColumn', 'civicrm_group', 'frontend_description', "text DEFAULT NULL COMMENT 'Alternative public description of the group.'", TRUE, '5.31.alpha1'); | |
68f481e6 | 64 | $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); |
355b9405 | 65 | $this->addTask('Remove Eway Single Currency Payment Processor type if not used or install the new extension for it', 'enableEwaySingleExtension'); |
d551d3d6 | 66 | $this->addTask('dev/core#1486 Remove FKs from ACL Cache tables', 'removeFKsFromACLCacheTables'); |
c14e4888 | 67 | $this->addTask('Activate core extension "Greenwich"', 'installGreenwich'); |
f945f0c4 I |
68 | $this->addTask('Add is_non_case_email_skipped column to civicrm_mail_settings', 'addColumn', |
69 | 'civicrm_mail_settings', 'is_non_case_email_skipped', "TINYINT DEFAULT 0 NOT NULL COMMENT 'Skip emails which do not have a Case ID or Case hash'"); | |
993a642c I |
70 | $this->addTask('Add is_contact_creation_disabled_if_no_match column to civicrm_mail_settings', 'addColumn', |
71 | 'civicrm_mail_settings', 'is_contact_creation_disabled_if_no_match', "TINYINT DEFAULT 0 NOT NULL COMMENT 'If this option is enabled, CiviCRM will not create new contacts when filing emails'"); | |
72 | } | |
73 | ||
e3c1ae9f TO |
74 | public function upgrade_5_31_beta2($rev) { |
75 | $this->addTask('Restore null-ity of "civicrm_group.title" field', 'groupTitleRestore'); | |
76 | $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); | |
77 | } | |
78 | ||
ae1baeec SL |
79 | public static function enableEwaySingleExtension(CRM_Queue_TaskContext $ctx) { |
80 | $eWAYPaymentProcessorType = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_payment_processor_type WHERE class_name = 'Payment_eWAY'"); | |
355b9405 SL |
81 | if ($eWAYPaymentProcessorType) { |
82 | $ewayPaymentProcessorCount = CRM_Core_DAO::singleValueQuery("SELECT count(id) FROM civicrm_payment_processor WHERE payment_processor_type_id = %1", [1 => [$eWAYPaymentProcessorType, 'Positive']]); | |
83 | if ($ewayPaymentProcessorCount) { | |
84 | $insert = CRM_Utils_SQL_Insert::into('civicrm_extension')->row([ | |
85 | 'type' => 'module', | |
86 | 'full_name' => 'ewaysingle', | |
87 | 'name' => 'eway Single currency extension', | |
88 | 'label' => 'eway Single currency extension', | |
89 | 'file' => 'ewaysingle', | |
90 | 'schema_version' => NULL, | |
91 | 'is_active' => 1, | |
92 | ]); | |
93 | CRM_Core_DAO::executeQuery($insert->usingReplace()->toSQL()); | |
94 | $managedEntity = CRM_Utils_SQL_Insert::into('civicrm_managed')->row([ | |
95 | 'name' => 'eWAY', | |
96 | 'module' => 'ewaysingle', | |
97 | 'entity_type' => 'PaymentProcessorType', | |
98 | 'entity_id' => $eWAYPaymentProcessorType, | |
99 | 'cleanup' => NULL, | |
100 | ]); | |
101 | CRM_Core_DAO::executeQuery($managedEntity->usingReplace()->toSQL()); | |
102 | } | |
103 | else { | |
104 | CRM_Core_DAO::executeQuery("DELETE FROM civicrm_payment_processor_type WHERE id = %1", [1 => [$eWAYPaymentProcessorType, 'Positive']]); | |
105 | } | |
89808b94 | 106 | } |
ae1baeec SL |
107 | return TRUE; |
108 | } | |
29ba40ec | 109 | |
d551d3d6 SL |
110 | public static function removeFKsFromACLCacheTables(CRM_Queue_TaskContext $ctx) { |
111 | CRM_Core_BAO_SchemaHandler::safeRemoveFK('civicrm_acl_contact_cache', 'FK_civicrm_acl_contact_cache_contact_id'); | |
112 | CRM_Core_BAO_SchemaHandler::safeRemoveFK('civicrm_acl_cache', 'FK_civicrm_acl_cache_contact_id'); | |
113 | CRM_Core_BAO_SchemaHandler::createIndexes(['civicrm_acl_cache' => ['contact_id']]); | |
114 | return TRUE; | |
115 | } | |
116 | ||
c14e4888 TO |
117 | /** |
118 | * Install greenwich extensions. | |
119 | * | |
120 | * This feature is restructured as a core extension - which is primarily a code cleanup step. | |
121 | * | |
122 | * @param \CRM_Queue_TaskContext $ctx | |
123 | * | |
124 | * @return bool | |
125 | * | |
126 | * @throws \CRM_Core_Exception | |
127 | */ | |
128 | public static function installGreenwich(CRM_Queue_TaskContext $ctx) { | |
129 | // Install via direct SQL manipulation. Note that: | |
130 | // (1) This extension has no activation logic. | |
131 | // (2) On new installs, the extension is activated purely via default SQL INSERT. | |
132 | // (3) Caches are flushed at the end of the upgrade. | |
133 | // ($) Over long term, upgrade steps are more reliable in SQL. API/BAO sometimes don't work mid-upgrade. | |
134 | $insert = CRM_Utils_SQL_Insert::into('civicrm_extension')->row([ | |
135 | 'type' => 'module', | |
136 | 'full_name' => 'greenwich', | |
137 | 'name' => 'Theme: Greenwich', | |
138 | 'label' => 'Theme: Greenwich', | |
139 | 'file' => 'greenwich', | |
140 | 'schema_version' => NULL, | |
141 | 'is_active' => 1, | |
142 | ]); | |
143 | CRM_Core_DAO::executeQuery($insert->usingReplace()->toSQL()); | |
144 | ||
145 | return TRUE; | |
146 | } | |
147 | ||
35fd9d21 SL |
148 | /** |
149 | * Expands the length of the civicrm_group.title field in the database to be 255. | |
150 | * | |
151 | * @param \CRM_Queue_TaskContext $ctx | |
152 | * | |
153 | * @return bool | |
154 | */ | |
155 | public static function grouptitlefieldExpand(CRM_Queue_TaskContext $ctx) { | |
156 | $locales = CRM_Core_I18n::getMultilingual(); | |
157 | $queries = []; | |
158 | if ($locales) { | |
159 | foreach ($locales as $locale) { | |
160 | $queries[] = "ALTER TABLE civicrm_group CHANGE `title_{$locale}` `title_{$locale}` varchar(255) NOT NULL COMMENT 'Name of Group.'"; | |
161 | } | |
162 | } | |
163 | else { | |
164 | $queries[] = "ALTER TABLE civicrm_group CHANGE `title` `title` varchar(255) NOT NULL COMMENT 'Name of Group.'"; | |
165 | } | |
166 | foreach ($queries as $query) { | |
167 | CRM_Core_DAO::executeQuery($query, [], TRUE, NULL, FALSE, FALSE); | |
168 | } | |
169 | return TRUE; | |
170 | } | |
171 | ||
e3c1ae9f TO |
172 | /** |
173 | * The prior task grouptitlefieldExpand went a bit too far in making the `title` NOT NULL. | |
174 | * | |
175 | * @link https://lab.civicrm.org/dev/translation/-/issues/58 | |
176 | * @param \CRM_Queue_TaskContext $ctx | |
177 | * @return bool | |
178 | */ | |
179 | public static function groupTitleRestore(CRM_Queue_TaskContext $ctx) { | |
180 | $locales = CRM_Core_I18n::getMultilingual(); | |
181 | $queries = []; | |
182 | if ($locales) { | |
183 | foreach ($locales as $locale) { | |
184 | $queries[] = "ALTER TABLE civicrm_group CHANGE `title_{$locale}` `title_{$locale}` varchar(255) DEFAULT NULL COMMENT 'Name of Group.'"; | |
185 | } | |
186 | } | |
187 | else { | |
188 | $queries[] = "ALTER TABLE civicrm_group CHANGE `title` `title` varchar(255) DEFAULT NULL COMMENT 'Name of Group.'"; | |
189 | } | |
190 | foreach ($queries as $query) { | |
191 | CRM_Core_DAO::executeQuery($query, [], TRUE, NULL, FALSE, FALSE); | |
192 | } | |
193 | return TRUE; | |
194 | } | |
195 | ||
29ba40ec | 196 | } |