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