fix header
[civicrm-core.git] / CRM / Upgrade / Incremental / General.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
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.0';
45
46 /**
47 * The previous recommended PHP version.
48 */
49 const MIN_RECOMMENDED_PHP_VER = '5.6';
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.4';
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 * @param $message
122 * @param $latestVer
123 * @param $currentVer
124 */
125 public static function checkMessageTemplate(&$message, $latestVer, $currentVer) {
126
127 $sql = "SELECT orig.workflow_id as workflow_id,
128 orig.msg_title as title
129 FROM civicrm_msg_template diverted JOIN civicrm_msg_template orig ON (
130 diverted.workflow_id = orig.workflow_id AND
131 orig.is_reserved = 1 AND (
132 diverted.msg_subject != orig.msg_subject OR
133 diverted.msg_text != orig.msg_text OR
134 diverted.msg_html != orig.msg_html
135 )
136 )";
137
138 $dao = CRM_Core_DAO::executeQuery($sql);
139 while ($dao->fetch()) {
140 $workflows[$dao->workflow_id] = $dao->title;
141 }
142
143 if (empty($workflows)) {
144 return;
145 }
146
147 $html = NULL;
148 $pathName = dirname(dirname(__FILE__));
149 $flag = FALSE;
150 foreach ($workflows as $workflow => $title) {
151 $name = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue',
152 $workflow,
153 'name',
154 'id'
155 );
156
157 // check if file exists locally
158 $textFileName = implode(DIRECTORY_SEPARATOR,
159 array(
160 $pathName,
161 "{$latestVer}.msg_template",
162 'message_templates',
163 "{$name}_text.tpl",
164 )
165 );
166
167 $htmlFileName = implode(DIRECTORY_SEPARATOR,
168 array(
169 $pathName,
170 "{$latestVer}.msg_template",
171 'message_templates',
172 "{$name}_html.tpl",
173 )
174 );
175
176 if (file_exists($textFileName) ||
177 file_exists($htmlFileName)
178 ) {
179 $flag = TRUE;
180 $html .= "<li>{$title}</li>";
181 }
182 }
183
184 if ($flag == TRUE) {
185 $html = "<ul>" . $html . "<ul>";
186
187 $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(
188 1 => 'http://wiki.civicrm.org/confluence/display/CRMDOC/Message+Templates#MessageTemplates-UpgradesandCustomizedSystemWorkflowTemplates',
189 2 => $html,
190 ));
191 }
192 }
193
194 }