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