Merge pull request #17452 from eileenmcnaughton/dummy_bag
[civicrm-core.git] / CRM / Upgrade / Incremental / General.php
CommitLineData
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 23class 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 */
59 const MIN_INSTALL_MYSQL_VER = '5.5';
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');
0632a523 78 if (version_compare(phpversion(), self::MIN_RECOMMENDED_PHP_VER) < 0) {
d89ec50a 79 $preUpgradeMessage .= '<p>';
be2fb01f 80 $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.', [
3655bea4
SL
81 1 => $latestVer,
82 2 => self::MIN_RECOMMENDED_PHP_VER,
f955c30c 83 3 => preg_replace(';^(\d+\.\d+(?:\.[1-9]\d*)?).*$;', '\1', self::RECOMMENDED_PHP_VER),
be2fb01f 84 ]);
d89ec50a 85 $preUpgradeMessage .= '</p>';
0632a523 86 }
f7738e49
SL
87 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) {
88 $preUpgradeMessage .= '<p>';
89 $preUpgradeMessage .= ts('You may proceed with the upgrade and CiviCRM %1 will continue working normally, but future releases will require MySQL version %2 or above or MariaDB version %3 or above.', [
90 1 => $latestVer,
91 2 => self::MIN_RECOMMENDED_MYSQL_VER,
92 3 => '10.1',
93 ]);
94 $preUpgradeMessage .= '</p>';
95 }
96 if (version_compare(CRM_Utils_SQL::getDatabaseVersion(), self::NEW_MIN_INSTALL_MYSQL_VER) < 0) {
97 $preUpgradeMessage .= '<p>';
98 $preUpgradeMessage .= ts('You may proceed with the upgrade and CiviCRM %1 will continue working normally, but CiviCRM versions from 5.28 onwards will require at least MySQL version %1. It is recommended to use MySQL version %3 or above or MariaDB version %4 or above.', [
99 1 => $latestVer,
100 2 => self::NEW_MIN_INSTALL_MYSQL_VER,
101 3 => self::MIN_RECOMMENDED_MYSQL_VER,
102 4 => '10.1',
103 ]);
104 $preUpgradeMessage .= '</p>';
105 }
0632a523 106
7abafcbc
TO
107 // http://issues.civicrm.org/jira/browse/CRM-13572
108 // Depending on how the code was upgraded, some sites may still have copies of old
109 // source files left behind. This is often a forgivable offense, but it's quite
110 // dangerous for CIVI-SA-2013-001.
fde21984
TO
111 global $civicrm_root;
112 $ofcFile = "$civicrm_root/packages/OpenFlashChart/php-ofc-library/ofc_upload_image.php";
113 if (file_exists($ofcFile)) {
7abafcbc 114 if (@unlink($ofcFile)) {
be2fb01f 115 $preUpgradeMessage .= '<br />' . ts('This system included an outdated, insecure script (%1). The file was automatically deleted.', [
3655bea4
SL
116 1 => $ofcFile,
117 ]);
0db6c3e1
TO
118 }
119 else {
be2fb01f 120 $preUpgradeMessage .= '<br />' . ts('This system includes an outdated, insecure script (%1). Please delete it.', [
3655bea4
SL
121 1 => $ofcFile,
122 ]);
7abafcbc 123 }
fde21984 124 }
f3103b87 125
84fb7424 126 if (Civi::settings()->get('enable_innodb_fts')) {
f3103b87
TO
127 // The FTS indexing feature dynamically manipulates the schema which could
128 // cause conflicts with other layers that manipulate the schema. The
129 // simplest thing is to turn it off and back on.
130
131 // It may not always be necessary to do this -- but I doubt we're going to test
132 // systematically in future releases. When it is necessary, one could probably
133 // ignore the matter and simply run CRM_Core_InnoDBIndexer::fixSchemaDifferences
134 // after the upgrade. But that's speculative. For now, we'll leave this
135 // advanced feature in the hands of the sysadmin.
ee705313 136 $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 137 }
5c3f5819
SL
138
139 $ftAclSetting = Civi::settings()->get('acl_financial_type');
be2fb01f 140 $financialAclExtension = civicrm_api3('extension', 'get', ['key' => 'biz.jmaconsulting.financialaclreport']);
5c3f5819 141 if ($ftAclSetting && (($financialAclExtension['count'] == 1 && $financialAclExtension['status'] != 'Installed') || $financialAclExtension['count'] !== 1)) {
be2fb01f 142 $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
143 1 => 'biz.jmaconsulting.financialaclreport',
144 2 => 'https://github.com/JMAConsulting/biz.jmaconsulting.financialaclreport',
be2fb01f 145 ]);
5c3f5819 146 }
6a488035
TO
147 }
148
fe83c251 149 /**
150 * Perform any message template updates. 5.0+.
151 * @param $message
152 * @param $version
153 */
154 public static function updateMessageTemplate(&$message, $version) {
155 if (version_compare($version, 5.0, '<')) {
156 return;
157 }
158 $messageObj = new CRM_Upgrade_Incremental_MessageTemplates($version);
159 $messages = $messageObj->getUpgradeMessages();
160 if (empty($messages)) {
161 return;
162 }
7d39079e
TO
163 $messagesHtml = array_map(function($k, $v) {
164 return sprintf("<li><em>%s</em> - %s</li>", htmlentities($k), htmlentities($v));
165 }, array_keys($messages), $messages);
166
be2fb01f 167 $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 168 1 => 'https://docs.civicrm.org/user/en/latest/email/message-templates/#modifying-system-workflow-message-templates',
3655bea4
SL
169 2 => '<ul>' . implode('', $messagesHtml) . '</ul>',
170 ]);
fe83c251 171
172 $messageObj->updateTemplates();
173 }
174
624e56fa 175 /**
624e56fa
EM
176 * @param $message
177 * @param $latestVer
178 * @param $currentVer
179 */
49368097 180 public static function checkMessageTemplate(&$message, $latestVer, $currentVer) {
fe83c251 181 if (version_compare($currentVer, 5.0, '>')) {
182 return;
183 }
6a488035
TO
184 $sql = "SELECT orig.workflow_id as workflow_id,
185 orig.msg_title as title
186 FROM civicrm_msg_template diverted JOIN civicrm_msg_template orig ON (
187 diverted.workflow_id = orig.workflow_id AND
188 orig.is_reserved = 1 AND (
189 diverted.msg_subject != orig.msg_subject OR
190 diverted.msg_text != orig.msg_text OR
191 diverted.msg_html != orig.msg_html
192 )
193 )";
194
49368097 195 $dao = CRM_Core_DAO::executeQuery($sql);
6a488035
TO
196 while ($dao->fetch()) {
197 $workflows[$dao->workflow_id] = $dao->title;
198 }
199
200 if (empty($workflows)) {
201 return;
202 }
203
353ffa53 204 $html = NULL;
6a488035 205 $pathName = dirname(dirname(__FILE__));
353ffa53 206 $flag = FALSE;
6a488035
TO
207 foreach ($workflows as $workflow => $title) {
208 $name = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue',
209 $workflow,
210 'name',
211 'id'
212 );
213
214 // check if file exists locally
215 $textFileName = implode(DIRECTORY_SEPARATOR,
be2fb01f 216 [
6a488035
TO
217 $pathName,
218 "{$latestVer}.msg_template",
219 'message_templates',
220 "{$name}_text.tpl",
be2fb01f 221 ]
6a488035
TO
222 );
223
224 $htmlFileName = implode(DIRECTORY_SEPARATOR,
be2fb01f 225 [
6a488035
TO
226 $pathName,
227 "{$latestVer}.msg_template",
228 'message_templates',
229 "{$name}_html.tpl",
be2fb01f 230 ]
6a488035
TO
231 );
232
233 if (file_exists($textFileName) ||
234 file_exists($htmlFileName)
235 ) {
236 $flag = TRUE;
237 $html .= "<li>{$title}</li>";
238 }
239 }
240
241 if ($flag == TRUE) {
242 $html = "<ul>" . $html . "<ul>";
243
be2fb01f 244 $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 245 1 => 'https://docs.civicrm.org/user/en/latest/email/message-templates/#modifying-system-workflow-message-templates',
3655bea4
SL
246 2 => $html,
247 ]);
6a488035
TO
248 }
249 }
250
6a488035 251}