Merge pull request #12634 from seamuslee001/dev_core_273
[civicrm-core.git] / CRM / Upgrade / Incremental / General.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
6a488035 5 +--------------------------------------------------------------------+
8c9251b3 6 | Copyright CiviCRM LLC (c) 2004-2018 |
6a488035
TO
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
8c9251b3 31 * @copyright CiviCRM LLC (c) 2004-2018
6a488035
TO
32 * $Id$
33 *
34 */
35
36/**
49368097 37 * This class contains generic upgrade logic which runs regardless of version.
6a488035 38 */
49368097 39class CRM_Upgrade_Incremental_General {
d0c1e96f
TO
40
41 /**
42 * The recommended PHP version.
43 */
cc1f4988 44 const RECOMMENDED_PHP_VER = '7.0';
d89ec50a
SL
45
46 /**
47 * The previous recommended PHP version.
48 */
cc1f4988 49 const MIN_RECOMMENDED_PHP_VER = '5.6';
d0c1e96f
TO
50
51 /**
52 * The minimum PHP version required to install Civi.
53 *
54 * @see install/index.php
55 */
e2383acd 56 const MIN_INSTALL_PHP_VER = '5.5';
d0c1e96f 57
6a488035 58 /**
fe482240 59 * Compute any messages which should be displayed before upgrade.
6a488035 60 *
5a4f6742
CW
61 * @param string $preUpgradeMessage
62 * alterable.
77b97be7
EM
63 * @param $currentVer
64 * @param $latestVer
6a488035 65 */
00be9182 66 public static function setPreUpgradeMessage(&$preUpgradeMessage, $currentVer, $latestVer) {
d89ec50a 67 $dateFormat = Civi::Settings()->get('dateformatshortdate');
0632a523 68 if (version_compare(phpversion(), self::MIN_RECOMMENDED_PHP_VER) < 0) {
d89ec50a 69 $preUpgradeMessage .= '<p>';
b045058d 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(
cc1f4988
CW
71 1 => $latestVer,
72 2 => self::MIN_RECOMMENDED_PHP_VER,
b045058d 73 3 => self::RECOMMENDED_PHP_VER,
cc1f4988 74 ));
d89ec50a 75 $preUpgradeMessage .= '</p>';
0632a523
CW
76 }
77
7abafcbc
TO
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.
fde21984
TO
82 global $civicrm_root;
83 $ofcFile = "$civicrm_root/packages/OpenFlashChart/php-ofc-library/ofc_upload_image.php";
84 if (file_exists($ofcFile)) {
7abafcbc
TO
85 if (@unlink($ofcFile)) {
86 $preUpgradeMessage .= '<br />' . ts('This system included an outdated, insecure script (%1). The file was automatically deleted.', array(
353ffa53
TO
87 1 => $ofcFile,
88 ));
0db6c3e1
TO
89 }
90 else {
7abafcbc 91 $preUpgradeMessage .= '<br />' . ts('This system includes an outdated, insecure script (%1). Please delete it.', array(
353ffa53
TO
92 1 => $ofcFile,
93 ));
7abafcbc 94 }
fde21984 95 }
f3103b87 96
84fb7424 97 if (Civi::settings()->get('enable_innodb_fts')) {
f3103b87
TO
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 }
5c3f5819
SL
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 }
6a488035
TO
118 }
119
fe83c251 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 $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(
135 1 => 'http://wiki.civicrm.org/confluence/display/CRMDOC/Message+Templates#MessageTemplates-UpgradesandCustomizedSystemWorkflowTemplates',
136 2 => '<ul><l>' . implode('</li><li>', $messages) . '</li></ul>',
137 ));
138
139 $messageObj->updateTemplates();
140 }
141
624e56fa 142 /**
624e56fa
EM
143 * @param $message
144 * @param $latestVer
145 * @param $currentVer
146 */
49368097 147 public static function checkMessageTemplate(&$message, $latestVer, $currentVer) {
fe83c251 148 if (version_compare($currentVer, 5.0, '>')) {
149 return;
150 }
6a488035
TO
151 $sql = "SELECT orig.workflow_id as workflow_id,
152 orig.msg_title as title
153 FROM civicrm_msg_template diverted JOIN civicrm_msg_template orig ON (
154 diverted.workflow_id = orig.workflow_id AND
155 orig.is_reserved = 1 AND (
156 diverted.msg_subject != orig.msg_subject OR
157 diverted.msg_text != orig.msg_text OR
158 diverted.msg_html != orig.msg_html
159 )
160 )";
161
49368097 162 $dao = CRM_Core_DAO::executeQuery($sql);
6a488035
TO
163 while ($dao->fetch()) {
164 $workflows[$dao->workflow_id] = $dao->title;
165 }
166
167 if (empty($workflows)) {
168 return;
169 }
170
353ffa53 171 $html = NULL;
6a488035 172 $pathName = dirname(dirname(__FILE__));
353ffa53 173 $flag = FALSE;
6a488035
TO
174 foreach ($workflows as $workflow => $title) {
175 $name = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue',
176 $workflow,
177 'name',
178 'id'
179 );
180
181 // check if file exists locally
182 $textFileName = implode(DIRECTORY_SEPARATOR,
183 array(
184 $pathName,
185 "{$latestVer}.msg_template",
186 'message_templates',
187 "{$name}_text.tpl",
188 )
189 );
190
191 $htmlFileName = implode(DIRECTORY_SEPARATOR,
192 array(
193 $pathName,
194 "{$latestVer}.msg_template",
195 'message_templates',
196 "{$name}_html.tpl",
197 )
198 );
199
200 if (file_exists($textFileName) ||
201 file_exists($htmlFileName)
202 ) {
203 $flag = TRUE;
204 $html .= "<li>{$title}</li>";
205 }
206 }
207
208 if ($flag == TRUE) {
209 $html = "<ul>" . $html . "<ul>";
210
353ffa53
TO
211 $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(
212 1 => 'http://wiki.civicrm.org/confluence/display/CRMDOC/Message+Templates#MessageTemplates-UpgradesandCustomizedSystemWorkflowTemplates',
408b79bf 213 2 => $html,
353ffa53 214 ));
6a488035
TO
215 }
216 }
217
6a488035 218}