Merge pull request #17329 from civicrm/5.26
[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 * Compute any messages which should be displayed before upgrade.
63 *
64 * @param string $preUpgradeMessage
65 * alterable.
66 * @param $currentVer
67 * @param $latestVer
68 */
69 public static function setPreUpgradeMessage(&$preUpgradeMessage, $currentVer, $latestVer) {
70 $dateFormat = Civi::Settings()->get('dateformatshortdate');
71 if (version_compare(phpversion(), self::MIN_RECOMMENDED_PHP_VER) < 0) {
72 $preUpgradeMessage .= '<p>';
73 $preUpgradeMessage .= ts('You may proceed with the upgrade and CiviCRM %1 will continue working normally, but future releases will require PHP %2 or above. We recommend PHP version %3.', [
74 1 => $latestVer,
75 2 => self::MIN_RECOMMENDED_PHP_VER,
76 3 => preg_replace(';^(\d+\.\d+(?:\.[1-9]\d*)?).*$;', '\1', self::RECOMMENDED_PHP_VER),
77 ]);
78 $preUpgradeMessage .= '</p>';
79 }
80
81 // http://issues.civicrm.org/jira/browse/CRM-13572
82 // Depending on how the code was upgraded, some sites may still have copies of old
83 // source files left behind. This is often a forgivable offense, but it's quite
84 // dangerous for CIVI-SA-2013-001.
85 global $civicrm_root;
86 $ofcFile = "$civicrm_root/packages/OpenFlashChart/php-ofc-library/ofc_upload_image.php";
87 if (file_exists($ofcFile)) {
88 if (@unlink($ofcFile)) {
89 $preUpgradeMessage .= '<br />' . ts('This system included an outdated, insecure script (%1). The file was automatically deleted.', [
90 1 => $ofcFile,
91 ]);
92 }
93 else {
94 $preUpgradeMessage .= '<br />' . ts('This system includes an outdated, insecure script (%1). Please delete it.', [
95 1 => $ofcFile,
96 ]);
97 }
98 }
99
100 if (Civi::settings()->get('enable_innodb_fts')) {
101 // The FTS indexing feature dynamically manipulates the schema which could
102 // cause conflicts with other layers that manipulate the schema. The
103 // simplest thing is to turn it off and back on.
104
105 // It may not always be necessary to do this -- but I doubt we're going to test
106 // systematically in future releases. When it is necessary, one could probably
107 // ignore the matter and simply run CRM_Core_InnoDBIndexer::fixSchemaDifferences
108 // after the upgrade. But that's speculative. For now, we'll leave this
109 // advanced feature in the hands of the sysadmin.
110 $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".');
111 }
112
113 $ftAclSetting = Civi::settings()->get('acl_financial_type');
114 $financialAclExtension = civicrm_api3('extension', 'get', ['key' => 'biz.jmaconsulting.financialaclreport']);
115 if ($ftAclSetting && (($financialAclExtension['count'] == 1 && $financialAclExtension['status'] != 'Installed') || $financialAclExtension['count'] !== 1)) {
116 $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>', [
117 1 => 'biz.jmaconsulting.financialaclreport',
118 2 => 'https://github.com/JMAConsulting/biz.jmaconsulting.financialaclreport',
119 ]);
120 }
121 }
122
123 /**
124 * Perform any message template updates. 5.0+.
125 * @param $message
126 * @param $version
127 */
128 public static function updateMessageTemplate(&$message, $version) {
129 if (version_compare($version, 5.0, '<')) {
130 return;
131 }
132 $messageObj = new CRM_Upgrade_Incremental_MessageTemplates($version);
133 $messages = $messageObj->getUpgradeMessages();
134 if (empty($messages)) {
135 return;
136 }
137 $messagesHtml = array_map(function($k, $v) {
138 return sprintf("<li><em>%s</em> - %s</li>", htmlentities($k), htmlentities($v));
139 }, array_keys($messages), $messages);
140
141 $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", [
142 1 => 'https://docs.civicrm.org/user/en/latest/email/message-templates/#modifying-system-workflow-message-templates',
143 2 => '<ul>' . implode('', $messagesHtml) . '</ul>',
144 ]);
145
146 $messageObj->updateTemplates();
147 }
148
149 /**
150 * @param $message
151 * @param $latestVer
152 * @param $currentVer
153 */
154 public static function checkMessageTemplate(&$message, $latestVer, $currentVer) {
155 if (version_compare($currentVer, 5.0, '>')) {
156 return;
157 }
158 $sql = "SELECT orig.workflow_id as workflow_id,
159 orig.msg_title as title
160 FROM civicrm_msg_template diverted JOIN civicrm_msg_template orig ON (
161 diverted.workflow_id = orig.workflow_id AND
162 orig.is_reserved = 1 AND (
163 diverted.msg_subject != orig.msg_subject OR
164 diverted.msg_text != orig.msg_text OR
165 diverted.msg_html != orig.msg_html
166 )
167 )";
168
169 $dao = CRM_Core_DAO::executeQuery($sql);
170 while ($dao->fetch()) {
171 $workflows[$dao->workflow_id] = $dao->title;
172 }
173
174 if (empty($workflows)) {
175 return;
176 }
177
178 $html = NULL;
179 $pathName = dirname(dirname(__FILE__));
180 $flag = FALSE;
181 foreach ($workflows as $workflow => $title) {
182 $name = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue',
183 $workflow,
184 'name',
185 'id'
186 );
187
188 // check if file exists locally
189 $textFileName = implode(DIRECTORY_SEPARATOR,
190 [
191 $pathName,
192 "{$latestVer}.msg_template",
193 'message_templates',
194 "{$name}_text.tpl",
195 ]
196 );
197
198 $htmlFileName = implode(DIRECTORY_SEPARATOR,
199 [
200 $pathName,
201 "{$latestVer}.msg_template",
202 'message_templates',
203 "{$name}_html.tpl",
204 ]
205 );
206
207 if (file_exists($textFileName) ||
208 file_exists($htmlFileName)
209 ) {
210 $flag = TRUE;
211 $html .= "<li>{$title}</li>";
212 }
213 }
214
215 if ($flag == TRUE) {
216 $html = "<ul>" . $html . "<ul>";
217
218 $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", [
219 1 => 'https://docs.civicrm.org/user/en/latest/email/message-templates/#modifying-system-workflow-message-templates',
220 2 => $html,
221 ]);
222 }
223 }
224
225 }