Merge pull request #12964 from civicrm/5.7
[civicrm-core.git] / CRM / Upgrade / Incremental / General.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2018
32 * $Id$
33 *
34 */
35
36 /**
37 * This class contains generic upgrade logic which runs regardless of version.
38 */
39 class CRM_Upgrade_Incremental_General {
40
41 /**
42 * The recommended PHP version.
43 */
44 const RECOMMENDED_PHP_VER = '7.1';
45
46 /**
47 * The previous recommended PHP version.
48 */
49 const MIN_RECOMMENDED_PHP_VER = '7.0';
50
51 /**
52 * The minimum PHP version required to install Civi.
53 *
54 * @see install/index.php
55 */
56 const MIN_INSTALL_PHP_VER = '5.5';
57
58 /**
59 * Compute any messages which should be displayed before upgrade.
60 *
61 * @param string $preUpgradeMessage
62 * alterable.
63 * @param $currentVer
64 * @param $latestVer
65 */
66 public static function setPreUpgradeMessage(&$preUpgradeMessage, $currentVer, $latestVer) {
67 $dateFormat = Civi::Settings()->get('dateformatshortdate');
68 if (version_compare(phpversion(), self::MIN_RECOMMENDED_PHP_VER) < 0) {
69 $preUpgradeMessage .= '<p>';
70 $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.', array(
71 1 => $latestVer,
72 2 => self::MIN_RECOMMENDED_PHP_VER,
73 3 => self::RECOMMENDED_PHP_VER,
74 ));
75 $preUpgradeMessage .= '</p>';
76 }
77
78 // http://issues.civicrm.org/jira/browse/CRM-13572
79 // Depending on how the code was upgraded, some sites may still have copies of old
80 // source files left behind. This is often a forgivable offense, but it's quite
81 // dangerous for CIVI-SA-2013-001.
82 global $civicrm_root;
83 $ofcFile = "$civicrm_root/packages/OpenFlashChart/php-ofc-library/ofc_upload_image.php";
84 if (file_exists($ofcFile)) {
85 if (@unlink($ofcFile)) {
86 $preUpgradeMessage .= '<br />' . ts('This system included an outdated, insecure script (%1). The file was automatically deleted.', array(
87 1 => $ofcFile,
88 ));
89 }
90 else {
91 $preUpgradeMessage .= '<br />' . ts('This system includes an outdated, insecure script (%1). Please delete it.', array(
92 1 => $ofcFile,
93 ));
94 }
95 }
96
97 if (Civi::settings()->get('enable_innodb_fts')) {
98 // The FTS indexing feature dynamically manipulates the schema which could
99 // cause conflicts with other layers that manipulate the schema. The
100 // simplest thing is to turn it off and back on.
101
102 // It may not always be necessary to do this -- but I doubt we're going to test
103 // systematically in future releases. When it is necessary, one could probably
104 // ignore the matter and simply run CRM_Core_InnoDBIndexer::fixSchemaDifferences
105 // after the upgrade. But that's speculative. For now, we'll leave this
106 // advanced feature in the hands of the sysadmin.
107 $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 => System Settings => Miscellaneous".');
108 }
109
110 $ftAclSetting = Civi::settings()->get('acl_financial_type');
111 $financialAclExtension = civicrm_api3('extension', 'get', array('key' => 'biz.jmaconsulting.financialaclreport'));
112 if ($ftAclSetting && (($financialAclExtension['count'] == 1 && $financialAclExtension['status'] != 'Installed') || $financialAclExtension['count'] !== 1)) {
113 $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>', array(
114 1 => 'biz.jmaconsulting.financialaclreport',
115 2 => 'https://github.com/JMAConsulting/biz.jmaconsulting.financialaclreport',
116 ));
117 }
118 }
119
120 /**
121 * Perform any message template updates. 5.0+.
122 * @param $message
123 * @param $version
124 */
125 public static function updateMessageTemplate(&$message, $version) {
126 if (version_compare($version, 5.0, '<')) {
127 return;
128 }
129 $messageObj = new CRM_Upgrade_Incremental_MessageTemplates($version);
130 $messages = $messageObj->getUpgradeMessages();
131 if (empty($messages)) {
132 return;
133 }
134 $messagesHtml = array_map(function($k, $v) {
135 return sprintf("<li><em>%s</em> - %s</li>", htmlentities($k), htmlentities($v));
136 }, array_keys($messages), $messages);
137
138 $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", array(
139 1 => 'http://wiki.civicrm.org/confluence/display/CRMDOC/Message+Templates#MessageTemplates-UpgradesandCustomizedSystemWorkflowTemplates',
140 2 => '<ul>' . implode('', $messagesHtml) . '</ul>',
141 ));
142
143 $messageObj->updateTemplates();
144 }
145
146 /**
147 * @param $message
148 * @param $latestVer
149 * @param $currentVer
150 */
151 public static function checkMessageTemplate(&$message, $latestVer, $currentVer) {
152 if (version_compare($currentVer, 5.0, '>')) {
153 return;
154 }
155 $sql = "SELECT orig.workflow_id as workflow_id,
156 orig.msg_title as title
157 FROM civicrm_msg_template diverted JOIN civicrm_msg_template orig ON (
158 diverted.workflow_id = orig.workflow_id AND
159 orig.is_reserved = 1 AND (
160 diverted.msg_subject != orig.msg_subject OR
161 diverted.msg_text != orig.msg_text OR
162 diverted.msg_html != orig.msg_html
163 )
164 )";
165
166 $dao = CRM_Core_DAO::executeQuery($sql);
167 while ($dao->fetch()) {
168 $workflows[$dao->workflow_id] = $dao->title;
169 }
170
171 if (empty($workflows)) {
172 return;
173 }
174
175 $html = NULL;
176 $pathName = dirname(dirname(__FILE__));
177 $flag = FALSE;
178 foreach ($workflows as $workflow => $title) {
179 $name = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue',
180 $workflow,
181 'name',
182 'id'
183 );
184
185 // check if file exists locally
186 $textFileName = implode(DIRECTORY_SEPARATOR,
187 array(
188 $pathName,
189 "{$latestVer}.msg_template",
190 'message_templates',
191 "{$name}_text.tpl",
192 )
193 );
194
195 $htmlFileName = implode(DIRECTORY_SEPARATOR,
196 array(
197 $pathName,
198 "{$latestVer}.msg_template",
199 'message_templates',
200 "{$name}_html.tpl",
201 )
202 );
203
204 if (file_exists($textFileName) ||
205 file_exists($htmlFileName)
206 ) {
207 $flag = TRUE;
208 $html .= "<li>{$title}</li>";
209 }
210 }
211
212 if ($flag == TRUE) {
213 $html = "<ul>" . $html . "<ul>";
214
215 $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", array(
216 1 => 'http://wiki.civicrm.org/confluence/display/CRMDOC/Message+Templates#MessageTemplates-UpgradesandCustomizedSystemWorkflowTemplates',
217 2 => $html,
218 ));
219 }
220 }
221
222 }