Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | * $Id$ |
17 | * | |
18 | */ | |
19 | ||
20 | /** | |
49368097 | 21 | * This class contains generic upgrade logic which runs regardless of version. |
6a488035 | 22 | */ |
49368097 | 23 | class CRM_Upgrade_Incremental_General { |
d0c1e96f TO |
24 | |
25 | /** | |
26 | * The recommended PHP version. | |
f955c30c AH |
27 | * |
28 | * The point release will be dropped in recommendations unless it's .1 or | |
29 | * higher. | |
d0c1e96f | 30 | */ |
f955c30c | 31 | const RECOMMENDED_PHP_VER = '7.3.0'; |
d89ec50a SL |
32 | |
33 | /** | |
f955c30c AH |
34 | * The minimum recommended PHP version. |
35 | * | |
36 | * A site running an earlier version will be told to upgrade. | |
d89ec50a | 37 | */ |
f955c30c | 38 | const MIN_RECOMMENDED_PHP_VER = '7.2.0'; |
d0c1e96f TO |
39 | |
40 | /** | |
41 | * The minimum PHP version required to install Civi. | |
42 | * | |
43 | * @see install/index.php | |
44 | */ | |
f955c30c | 45 | const MIN_INSTALL_PHP_VER = '7.1.0'; |
d0c1e96f | 46 | |
965596b4 SL |
47 | /** |
48 | * The minimum recommended MySQL/MariaDB version. | |
49 | * | |
50 | * A site running an earlier version will be told to upgrade. | |
51 | */ | |
52 | const MIN_RECOMMENDED_MYSQL_VER = '5.7'; | |
53 | ||
54 | /** | |
55 | * The minimum MySQL/MariaDB version required to install Civi. | |
56 | * | |
57 | * @see install/index.php | |
58 | */ | |
487813ab | 59 | const MIN_INSTALL_MYSQL_VER = '5.6.5'; |
965596b4 | 60 | |
f7738e49 SL |
61 | /** |
62 | * The minimum MySQL/MariaDB version required to install Civi. | |
63 | * | |
64 | * @see install/index.php | |
65 | */ | |
66 | const NEW_MIN_INSTALL_MYSQL_VER = '5.6.5'; | |
67 | ||
6a488035 | 68 | /** |
fe482240 | 69 | * Compute any messages which should be displayed before upgrade. |
6a488035 | 70 | * |
5a4f6742 CW |
71 | * @param string $preUpgradeMessage |
72 | * alterable. | |
77b97be7 EM |
73 | * @param $currentVer |
74 | * @param $latestVer | |
6a488035 | 75 | */ |
00be9182 | 76 | public static function setPreUpgradeMessage(&$preUpgradeMessage, $currentVer, $latestVer) { |
d89ec50a | 77 | $dateFormat = Civi::Settings()->get('dateformatshortdate'); |
57ec4649 TO |
78 | $phpversion = phpversion(); |
79 | if (version_compare($phpversion, self::MIN_RECOMMENDED_PHP_VER) < 0) { | |
d89ec50a | 80 | $preUpgradeMessage .= '<p>'; |
57ec4649 | 81 | $preUpgradeMessage .= ts('This system uses PHP v%4. You may proceed with the upgrade, and CiviCRM v%1 will continue working normally. However, future releases will require PHP v%2. We recommend PHP v%3.', [ |
3655bea4 | 82 | 1 => $latestVer, |
57ec4649 TO |
83 | 2 => self::MIN_RECOMMENDED_PHP_VER . '+', |
84 | 3 => preg_replace(';^(\d+\.\d+(?:\.[1-9]\d*)?).*$;', '\1', self::RECOMMENDED_PHP_VER) . '+', | |
85 | 4 => $phpversion, | |
be2fb01f | 86 | ]); |
d89ec50a | 87 | $preUpgradeMessage .= '</p>'; |
0632a523 | 88 | } |
f7738e49 SL |
89 | if (version_compare(CRM_Utils_SQL::getDatabaseVersion(), self::MIN_RECOMMENDED_MYSQL_VER) < 0 && version_compare(CRM_Utils_SQL::getDatabaseVersion(), self::NEW_MIN_INSTALL_MYSQL_VER) >= 0) { |
90 | $preUpgradeMessage .= '<p>'; | |
57ec4649 | 91 | $preUpgradeMessage .= ts('This system uses MySQL/MariaDB v%4. You may proceed with the upgrade, and CiviCRM v%1 will continue working normally. However, future releases will require MySQL v%2 or MariaDB v%3.', [ |
f7738e49 | 92 | 1 => $latestVer, |
57ec4649 TO |
93 | 2 => self::MIN_RECOMMENDED_MYSQL_VER . '+', |
94 | 3 => '10.1' . '+', | |
95 | 4 => CRM_Utils_SQL::getDatabaseVersion(), | |
f7738e49 SL |
96 | ]); |
97 | $preUpgradeMessage .= '</p>'; | |
98 | } | |
99 | if (version_compare(CRM_Utils_SQL::getDatabaseVersion(), self::NEW_MIN_INSTALL_MYSQL_VER) < 0) { | |
100 | $preUpgradeMessage .= '<p>'; | |
57ec4649 | 101 | $preUpgradeMessage .= ts('This system uses MySQL/MariaDB v%6. You may proceed with the upgrade, and CiviCRM v%1 will continue working normally. However, CiviCRM v%5 will require MySQL v%2. We recommend MySQL v%3 or MariaDB v%4.', [ |
f7738e49 | 102 | 1 => $latestVer, |
57ec4649 TO |
103 | 2 => self::NEW_MIN_INSTALL_MYSQL_VER . '+', |
104 | 3 => self::MIN_RECOMMENDED_MYSQL_VER . '+', | |
105 | 4 => '10.1' . '+', | |
106 | 5 => '5.28' . '+', | |
107 | 6 => CRM_Utils_SQL::getDatabaseVersion(), | |
f7738e49 SL |
108 | ]); |
109 | $preUpgradeMessage .= '</p>'; | |
110 | } | |
0632a523 | 111 | |
7abafcbc TO |
112 | // http://issues.civicrm.org/jira/browse/CRM-13572 |
113 | // Depending on how the code was upgraded, some sites may still have copies of old | |
114 | // source files left behind. This is often a forgivable offense, but it's quite | |
115 | // dangerous for CIVI-SA-2013-001. | |
fde21984 TO |
116 | global $civicrm_root; |
117 | $ofcFile = "$civicrm_root/packages/OpenFlashChart/php-ofc-library/ofc_upload_image.php"; | |
118 | if (file_exists($ofcFile)) { | |
7abafcbc | 119 | if (@unlink($ofcFile)) { |
be2fb01f | 120 | $preUpgradeMessage .= '<br />' . ts('This system included an outdated, insecure script (%1). The file was automatically deleted.', [ |
3655bea4 SL |
121 | 1 => $ofcFile, |
122 | ]); | |
0db6c3e1 TO |
123 | } |
124 | else { | |
be2fb01f | 125 | $preUpgradeMessage .= '<br />' . ts('This system includes an outdated, insecure script (%1). Please delete it.', [ |
3655bea4 SL |
126 | 1 => $ofcFile, |
127 | ]); | |
7abafcbc | 128 | } |
fde21984 | 129 | } |
f3103b87 | 130 | |
84fb7424 | 131 | if (Civi::settings()->get('enable_innodb_fts')) { |
f3103b87 TO |
132 | // The FTS indexing feature dynamically manipulates the schema which could |
133 | // cause conflicts with other layers that manipulate the schema. The | |
134 | // simplest thing is to turn it off and back on. | |
135 | ||
136 | // It may not always be necessary to do this -- but I doubt we're going to test | |
137 | // systematically in future releases. When it is necessary, one could probably | |
138 | // ignore the matter and simply run CRM_Core_InnoDBIndexer::fixSchemaDifferences | |
139 | // after the upgrade. But that's speculative. For now, we'll leave this | |
140 | // advanced feature in the hands of the sysadmin. | |
ee705313 | 141 | $preUpgradeMessage .= '<br />' . ts('This database uses InnoDB Full Text Search for optimized searching. The upgrade procedure has not been tested with this feature. You should disable (and later re-enable) the feature by navigating to "Administer => Customize Data and Screens => Search Preferences".'); |
f3103b87 | 142 | } |
5c3f5819 SL |
143 | |
144 | $ftAclSetting = Civi::settings()->get('acl_financial_type'); | |
be2fb01f | 145 | $financialAclExtension = civicrm_api3('extension', 'get', ['key' => 'biz.jmaconsulting.financialaclreport']); |
5c3f5819 | 146 | if ($ftAclSetting && (($financialAclExtension['count'] == 1 && $financialAclExtension['status'] != 'Installed') || $financialAclExtension['count'] !== 1)) { |
be2fb01f | 147 | $preUpgradeMessage .= '<br />' . ts('CiviCRM will in the future require the extension %1 for CiviCRM Reports to work correctly with the Financial Type ACLs. The extension can be downloaded <a href="%2">here</a>', [ |
5c3f5819 SL |
148 | 1 => 'biz.jmaconsulting.financialaclreport', |
149 | 2 => 'https://github.com/JMAConsulting/biz.jmaconsulting.financialaclreport', | |
be2fb01f | 150 | ]); |
5c3f5819 | 151 | } |
6a488035 TO |
152 | } |
153 | ||
fe83c251 | 154 | /** |
155 | * Perform any message template updates. 5.0+. | |
156 | * @param $message | |
157 | * @param $version | |
158 | */ | |
159 | public static function updateMessageTemplate(&$message, $version) { | |
160 | if (version_compare($version, 5.0, '<')) { | |
161 | return; | |
162 | } | |
163 | $messageObj = new CRM_Upgrade_Incremental_MessageTemplates($version); | |
164 | $messages = $messageObj->getUpgradeMessages(); | |
165 | if (empty($messages)) { | |
166 | return; | |
167 | } | |
7d39079e TO |
168 | $messagesHtml = array_map(function($k, $v) { |
169 | return sprintf("<li><em>%s</em> - %s</li>", htmlentities($k), htmlentities($v)); | |
170 | }, array_keys($messages), $messages); | |
171 | ||
be2fb01f | 172 | $message .= '<br />' . ts("The default copies of the message templates listed below will be updated to handle new features or correct a problem. Your installation has customized versions of these message templates, and you will need to apply the updates manually after running this upgrade. <a href='%1' style='color:white; text-decoration:underline; font-weight:bold;' target='_blank'>Click here</a> for detailed instructions. %2", [ |
6a0dab94 | 173 | 1 => 'https://docs.civicrm.org/user/en/latest/email/message-templates/#modifying-system-workflow-message-templates', |
3655bea4 SL |
174 | 2 => '<ul>' . implode('', $messagesHtml) . '</ul>', |
175 | ]); | |
fe83c251 | 176 | |
177 | $messageObj->updateTemplates(); | |
178 | } | |
179 | ||
624e56fa | 180 | /** |
624e56fa EM |
181 | * @param $message |
182 | * @param $latestVer | |
183 | * @param $currentVer | |
184 | */ | |
49368097 | 185 | public static function checkMessageTemplate(&$message, $latestVer, $currentVer) { |
fe83c251 | 186 | if (version_compare($currentVer, 5.0, '>')) { |
187 | return; | |
188 | } | |
6a488035 TO |
189 | $sql = "SELECT orig.workflow_id as workflow_id, |
190 | orig.msg_title as title | |
191 | FROM civicrm_msg_template diverted JOIN civicrm_msg_template orig ON ( | |
192 | diverted.workflow_id = orig.workflow_id AND | |
193 | orig.is_reserved = 1 AND ( | |
194 | diverted.msg_subject != orig.msg_subject OR | |
195 | diverted.msg_text != orig.msg_text OR | |
196 | diverted.msg_html != orig.msg_html | |
197 | ) | |
198 | )"; | |
199 | ||
49368097 | 200 | $dao = CRM_Core_DAO::executeQuery($sql); |
6a488035 TO |
201 | while ($dao->fetch()) { |
202 | $workflows[$dao->workflow_id] = $dao->title; | |
203 | } | |
204 | ||
205 | if (empty($workflows)) { | |
206 | return; | |
207 | } | |
208 | ||
353ffa53 | 209 | $html = NULL; |
6a488035 | 210 | $pathName = dirname(dirname(__FILE__)); |
353ffa53 | 211 | $flag = FALSE; |
6a488035 TO |
212 | foreach ($workflows as $workflow => $title) { |
213 | $name = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', | |
214 | $workflow, | |
215 | 'name', | |
216 | 'id' | |
217 | ); | |
218 | ||
219 | // check if file exists locally | |
220 | $textFileName = implode(DIRECTORY_SEPARATOR, | |
be2fb01f | 221 | [ |
6a488035 TO |
222 | $pathName, |
223 | "{$latestVer}.msg_template", | |
224 | 'message_templates', | |
225 | "{$name}_text.tpl", | |
be2fb01f | 226 | ] |
6a488035 TO |
227 | ); |
228 | ||
229 | $htmlFileName = implode(DIRECTORY_SEPARATOR, | |
be2fb01f | 230 | [ |
6a488035 TO |
231 | $pathName, |
232 | "{$latestVer}.msg_template", | |
233 | 'message_templates', | |
234 | "{$name}_html.tpl", | |
be2fb01f | 235 | ] |
6a488035 TO |
236 | ); |
237 | ||
238 | if (file_exists($textFileName) || | |
239 | file_exists($htmlFileName) | |
240 | ) { | |
241 | $flag = TRUE; | |
242 | $html .= "<li>{$title}</li>"; | |
243 | } | |
244 | } | |
245 | ||
246 | if ($flag == TRUE) { | |
247 | $html = "<ul>" . $html . "<ul>"; | |
248 | ||
be2fb01f | 249 | $message .= '<br />' . ts("The default copies of the message templates listed below will be updated to handle new features or correct a problem. Your installation has customized versions of these message templates, and you will need to apply the updates manually after running this upgrade. <a href='%1' style='color:white; text-decoration:underline; font-weight:bold;' target='_blank'>Click here</a> for detailed instructions. %2", [ |
6a0dab94 | 250 | 1 => 'https://docs.civicrm.org/user/en/latest/email/message-templates/#modifying-system-workflow-message-templates', |
3655bea4 SL |
251 | 2 => $html, |
252 | ]); | |
6a488035 TO |
253 | } |
254 | } | |
255 | ||
6a488035 | 256 | } |