Merge pull request #17535 from eileenmcnaughton/gone
[civicrm-core.git] / CRM / Upgrade / Incremental / General.php
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 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 * $Id$
17 *
18 */
19
20 /**
21 * This class contains generic upgrade logic which runs regardless of version.
22 */
23 class CRM_Upgrade_Incremental_General {
24
25 /**
26 * The recommended PHP version.
27 *
28 * The point release will be dropped in recommendations unless it's .1 or
29 * higher.
30 */
31 const RECOMMENDED_PHP_VER = '7.3.0';
32
33 /**
34 * The minimum recommended PHP version.
35 *
36 * A site running an earlier version will be told to upgrade.
37 */
38 const MIN_RECOMMENDED_PHP_VER = '7.2.0';
39
40 /**
41 * The minimum PHP version required to install Civi.
42 *
43 * @see install/index.php
44 */
45 const MIN_INSTALL_PHP_VER = '7.1.0';
46
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 */
59 const MIN_INSTALL_MYSQL_VER = '5.5';
60
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
68 /**
69 * Compute any messages which should be displayed before upgrade.
70 *
71 * @param string $preUpgradeMessage
72 * alterable.
73 * @param $currentVer
74 * @param $latestVer
75 */
76 public static function setPreUpgradeMessage(&$preUpgradeMessage, $currentVer, $latestVer) {
77 $dateFormat = Civi::Settings()->get('dateformatshortdate');
78 $phpversion = phpversion();
79 if (version_compare($phpversion, self::MIN_RECOMMENDED_PHP_VER) < 0) {
80 $preUpgradeMessage .= '<p>';
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.', [
82 1 => $latestVer,
83 2 => self::MIN_RECOMMENDED_PHP_VER . '+',
84 3 => preg_replace(';^(\d+\.\d+(?:\.[1-9]\d*)?).*$;', '\1', self::RECOMMENDED_PHP_VER) . '+',
85 4 => $phpversion,
86 ]);
87 $preUpgradeMessage .= '</p>';
88 }
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>';
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.', [
92 1 => $latestVer,
93 2 => self::MIN_RECOMMENDED_MYSQL_VER . '+',
94 3 => '10.1' . '+',
95 4 => CRM_Utils_SQL::getDatabaseVersion(),
96 ]);
97 $preUpgradeMessage .= '</p>';
98 }
99 if (version_compare(CRM_Utils_SQL::getDatabaseVersion(), self::NEW_MIN_INSTALL_MYSQL_VER) < 0) {
100 $preUpgradeMessage .= '<p>';
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.', [
102 1 => $latestVer,
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(),
108 ]);
109 $preUpgradeMessage .= '</p>';
110 }
111
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.
116 global $civicrm_root;
117 $ofcFile = "$civicrm_root/packages/OpenFlashChart/php-ofc-library/ofc_upload_image.php";
118 if (file_exists($ofcFile)) {
119 if (@unlink($ofcFile)) {
120 $preUpgradeMessage .= '<br />' . ts('This system included an outdated, insecure script (%1). The file was automatically deleted.', [
121 1 => $ofcFile,
122 ]);
123 }
124 else {
125 $preUpgradeMessage .= '<br />' . ts('This system includes an outdated, insecure script (%1). Please delete it.', [
126 1 => $ofcFile,
127 ]);
128 }
129 }
130
131 if (Civi::settings()->get('enable_innodb_fts')) {
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.
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".');
142 }
143
144 $ftAclSetting = Civi::settings()->get('acl_financial_type');
145 $financialAclExtension = civicrm_api3('extension', 'get', ['key' => 'biz.jmaconsulting.financialaclreport']);
146 if ($ftAclSetting && (($financialAclExtension['count'] == 1 && $financialAclExtension['status'] != 'Installed') || $financialAclExtension['count'] !== 1)) {
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>', [
148 1 => 'biz.jmaconsulting.financialaclreport',
149 2 => 'https://github.com/JMAConsulting/biz.jmaconsulting.financialaclreport',
150 ]);
151 }
152 }
153
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 }
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
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", [
173 1 => 'https://docs.civicrm.org/user/en/latest/email/message-templates/#modifying-system-workflow-message-templates',
174 2 => '<ul>' . implode('', $messagesHtml) . '</ul>',
175 ]);
176
177 $messageObj->updateTemplates();
178 }
179
180 /**
181 * @param $message
182 * @param $latestVer
183 * @param $currentVer
184 */
185 public static function checkMessageTemplate(&$message, $latestVer, $currentVer) {
186 if (version_compare($currentVer, 5.0, '>')) {
187 return;
188 }
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
200 $dao = CRM_Core_DAO::executeQuery($sql);
201 while ($dao->fetch()) {
202 $workflows[$dao->workflow_id] = $dao->title;
203 }
204
205 if (empty($workflows)) {
206 return;
207 }
208
209 $html = NULL;
210 $pathName = dirname(dirname(__FILE__));
211 $flag = FALSE;
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,
221 [
222 $pathName,
223 "{$latestVer}.msg_template",
224 'message_templates',
225 "{$name}_text.tpl",
226 ]
227 );
228
229 $htmlFileName = implode(DIRECTORY_SEPARATOR,
230 [
231 $pathName,
232 "{$latestVer}.msg_template",
233 'message_templates',
234 "{$name}_html.tpl",
235 ]
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
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", [
250 1 => 'https://docs.civicrm.org/user/en/latest/email/message-templates/#modifying-system-workflow-message-templates',
251 2 => $html,
252 ]);
253 }
254 }
255
256 }