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