Merge pull request #15882 from demeritcowboy/audit-timeline
[civicrm-core.git] / CRM / Upgrade / Incremental / General.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
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 |
6a488035 9 +--------------------------------------------------------------------+
d25dd0ee 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 * $Id$
17 *
18 */
19
20/**
49368097 21 * This class contains generic upgrade logic which runs regardless of version.
6a488035 22 */
49368097 23class CRM_Upgrade_Incremental_General {
d0c1e96f
TO
24
25 /**
26 * The recommended PHP version.
27 */
ea91bc31 28 const RECOMMENDED_PHP_VER = '7.2';
d89ec50a
SL
29
30 /**
31 * The previous recommended PHP version.
32 */
ea91bc31 33 const MIN_RECOMMENDED_PHP_VER = '7.1';
d0c1e96f
TO
34
35 /**
36 * The minimum PHP version required to install Civi.
37 *
38 * @see install/index.php
39 */
96298d46 40 const MIN_INSTALL_PHP_VER = '7.0';
d0c1e96f 41
6a488035 42 /**
fe482240 43 * Compute any messages which should be displayed before upgrade.
6a488035 44 *
5a4f6742
CW
45 * @param string $preUpgradeMessage
46 * alterable.
77b97be7
EM
47 * @param $currentVer
48 * @param $latestVer
6a488035 49 */
00be9182 50 public static function setPreUpgradeMessage(&$preUpgradeMessage, $currentVer, $latestVer) {
d89ec50a 51 $dateFormat = Civi::Settings()->get('dateformatshortdate');
0632a523 52 if (version_compare(phpversion(), self::MIN_RECOMMENDED_PHP_VER) < 0) {
d89ec50a 53 $preUpgradeMessage .= '<p>';
be2fb01f 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.', [
3655bea4
SL
55 1 => $latestVer,
56 2 => self::MIN_RECOMMENDED_PHP_VER,
57 3 => self::RECOMMENDED_PHP_VER,
be2fb01f 58 ]);
d89ec50a 59 $preUpgradeMessage .= '</p>';
0632a523
CW
60 }
61
7abafcbc
TO
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.
fde21984
TO
66 global $civicrm_root;
67 $ofcFile = "$civicrm_root/packages/OpenFlashChart/php-ofc-library/ofc_upload_image.php";
68 if (file_exists($ofcFile)) {
7abafcbc 69 if (@unlink($ofcFile)) {
be2fb01f 70 $preUpgradeMessage .= '<br />' . ts('This system included an outdated, insecure script (%1). The file was automatically deleted.', [
3655bea4
SL
71 1 => $ofcFile,
72 ]);
0db6c3e1
TO
73 }
74 else {
be2fb01f 75 $preUpgradeMessage .= '<br />' . ts('This system includes an outdated, insecure script (%1). Please delete it.', [
3655bea4
SL
76 1 => $ofcFile,
77 ]);
7abafcbc 78 }
fde21984 79 }
f3103b87 80
84fb7424 81 if (Civi::settings()->get('enable_innodb_fts')) {
f3103b87
TO
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.
ee705313 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".');
f3103b87 92 }
5c3f5819
SL
93
94 $ftAclSetting = Civi::settings()->get('acl_financial_type');
be2fb01f 95 $financialAclExtension = civicrm_api3('extension', 'get', ['key' => 'biz.jmaconsulting.financialaclreport']);
5c3f5819 96 if ($ftAclSetting && (($financialAclExtension['count'] == 1 && $financialAclExtension['status'] != 'Installed') || $financialAclExtension['count'] !== 1)) {
be2fb01f 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>', [
5c3f5819
SL
98 1 => 'biz.jmaconsulting.financialaclreport',
99 2 => 'https://github.com/JMAConsulting/biz.jmaconsulting.financialaclreport',
be2fb01f 100 ]);
5c3f5819 101 }
6a488035
TO
102 }
103
fe83c251 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 }
7d39079e
TO
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
be2fb01f 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", [
3655bea4
SL
123 1 => 'http://wiki.civicrm.org/confluence/display/CRMDOC/Message+Templates#MessageTemplates-UpgradesandCustomizedSystemWorkflowTemplates',
124 2 => '<ul>' . implode('', $messagesHtml) . '</ul>',
125 ]);
fe83c251 126
127 $messageObj->updateTemplates();
128 }
129
624e56fa 130 /**
624e56fa
EM
131 * @param $message
132 * @param $latestVer
133 * @param $currentVer
134 */
49368097 135 public static function checkMessageTemplate(&$message, $latestVer, $currentVer) {
fe83c251 136 if (version_compare($currentVer, 5.0, '>')) {
137 return;
138 }
6a488035
TO
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
49368097 150 $dao = CRM_Core_DAO::executeQuery($sql);
6a488035
TO
151 while ($dao->fetch()) {
152 $workflows[$dao->workflow_id] = $dao->title;
153 }
154
155 if (empty($workflows)) {
156 return;
157 }
158
353ffa53 159 $html = NULL;
6a488035 160 $pathName = dirname(dirname(__FILE__));
353ffa53 161 $flag = FALSE;
6a488035
TO
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,
be2fb01f 171 [
6a488035
TO
172 $pathName,
173 "{$latestVer}.msg_template",
174 'message_templates',
175 "{$name}_text.tpl",
be2fb01f 176 ]
6a488035
TO
177 );
178
179 $htmlFileName = implode(DIRECTORY_SEPARATOR,
be2fb01f 180 [
6a488035
TO
181 $pathName,
182 "{$latestVer}.msg_template",
183 'message_templates',
184 "{$name}_html.tpl",
be2fb01f 185 ]
6a488035
TO
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
be2fb01f 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", [
3655bea4
SL
200 1 => 'http://wiki.civicrm.org/confluence/display/CRMDOC/Message+Templates#MessageTemplates-UpgradesandCustomizedSystemWorkflowTemplates',
201 2 => $html,
202 ]);
6a488035
TO
203 }
204 }
205
6a488035 206}