Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
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 | |
6b83d5bd | 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
49368097 | 37 | * This class contains generic upgrade logic which runs regardless of version. |
6a488035 | 38 | */ |
49368097 | 39 | class CRM_Upgrade_Incremental_General { |
d0c1e96f TO |
40 | |
41 | /** | |
42 | * The recommended PHP version. | |
43 | */ | |
e6180d9a | 44 | const RECOMMENDED_PHP_VER = '7.1'; |
d89ec50a SL |
45 | |
46 | /** | |
47 | * The previous recommended PHP version. | |
48 | */ | |
e6180d9a | 49 | const MIN_RECOMMENDED_PHP_VER = '7.0'; |
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 | } | |
7d39079e TO |
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 | ||
fe83c251 | 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', | |
7d39079e | 140 | 2 => '<ul>' . implode('', $messagesHtml) . '</ul>', |
fe83c251 | 141 | )); |
142 | ||
143 | $messageObj->updateTemplates(); | |
144 | } | |
145 | ||
624e56fa | 146 | /** |
624e56fa EM |
147 | * @param $message |
148 | * @param $latestVer | |
149 | * @param $currentVer | |
150 | */ | |
49368097 | 151 | public static function checkMessageTemplate(&$message, $latestVer, $currentVer) { |
fe83c251 | 152 | if (version_compare($currentVer, 5.0, '>')) { |
153 | return; | |
154 | } | |
6a488035 TO |
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 | ||
49368097 | 166 | $dao = CRM_Core_DAO::executeQuery($sql); |
6a488035 TO |
167 | while ($dao->fetch()) { |
168 | $workflows[$dao->workflow_id] = $dao->title; | |
169 | } | |
170 | ||
171 | if (empty($workflows)) { | |
172 | return; | |
173 | } | |
174 | ||
353ffa53 | 175 | $html = NULL; |
6a488035 | 176 | $pathName = dirname(dirname(__FILE__)); |
353ffa53 | 177 | $flag = FALSE; |
6a488035 TO |
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 | ||
353ffa53 TO |
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', | |
408b79bf | 217 | 2 => $html, |
353ffa53 | 218 | )); |
6a488035 TO |
219 | } |
220 | } | |
221 | ||
6a488035 | 222 | } |