Civi::settings() - Add short hand for accessing domain settings
[civicrm-core.git] / CRM / Upgrade / Incremental / General.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
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
e7112fa7 31 * @copyright CiviCRM LLC (c) 2004-2015
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 {
0632a523 40 const MIN_RECOMMENDED_PHP_VER = '5.5';
6a488035
TO
41
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) {
0632a523
CW
51 if (version_compare(phpversion(), self::MIN_RECOMMENDED_PHP_VER) < 0) {
52 $preUpgradeMessage .= '<br />' .
53 ts('This webserver is running an outdated version of PHP (%1). The recommended version is %2 or later.', array(
54 1 => phpversion(),
55 2 => self::MIN_RECOMMENDED_PHP_VER,
56 )) .
57 '<br />' .
58 ts('You may proceed with the upgrade and CiviCRM %1 will continue working normally, but future releases will require PHP %2.', array(
59 1 => $latestVer,
60 2 => self::MIN_RECOMMENDED_PHP_VER,
61 ));
62 }
63
7abafcbc
TO
64 // http://issues.civicrm.org/jira/browse/CRM-13572
65 // Depending on how the code was upgraded, some sites may still have copies of old
66 // source files left behind. This is often a forgivable offense, but it's quite
67 // dangerous for CIVI-SA-2013-001.
fde21984
TO
68 global $civicrm_root;
69 $ofcFile = "$civicrm_root/packages/OpenFlashChart/php-ofc-library/ofc_upload_image.php";
70 if (file_exists($ofcFile)) {
7abafcbc
TO
71 if (@unlink($ofcFile)) {
72 $preUpgradeMessage .= '<br />' . ts('This system included an outdated, insecure script (%1). The file was automatically deleted.', array(
353ffa53
TO
73 1 => $ofcFile,
74 ));
0db6c3e1
TO
75 }
76 else {
7abafcbc 77 $preUpgradeMessage .= '<br />' . ts('This system includes an outdated, insecure script (%1). Please delete it.', array(
353ffa53
TO
78 1 => $ofcFile,
79 ));
7abafcbc 80 }
fde21984 81 }
f3103b87 82
56c2750b 83 if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME, 'enable_innodb_fts', NULL, FALSE)) {
f3103b87
TO
84 // The FTS indexing feature dynamically manipulates the schema which could
85 // cause conflicts with other layers that manipulate the schema. The
86 // simplest thing is to turn it off and back on.
87
88 // It may not always be necessary to do this -- but I doubt we're going to test
89 // systematically in future releases. When it is necessary, one could probably
90 // ignore the matter and simply run CRM_Core_InnoDBIndexer::fixSchemaDifferences
91 // after the upgrade. But that's speculative. For now, we'll leave this
92 // advanced feature in the hands of the sysadmin.
93 $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".');
94 }
6a488035
TO
95 }
96
624e56fa 97 /**
624e56fa
EM
98 * @param $message
99 * @param $latestVer
100 * @param $currentVer
101 */
49368097 102 public static function checkMessageTemplate(&$message, $latestVer, $currentVer) {
6a488035
TO
103
104 $sql = "SELECT orig.workflow_id as workflow_id,
105 orig.msg_title as title
106 FROM civicrm_msg_template diverted JOIN civicrm_msg_template orig ON (
107 diverted.workflow_id = orig.workflow_id AND
108 orig.is_reserved = 1 AND (
109 diverted.msg_subject != orig.msg_subject OR
110 diverted.msg_text != orig.msg_text OR
111 diverted.msg_html != orig.msg_html
112 )
113 )";
114
49368097 115 $dao = CRM_Core_DAO::executeQuery($sql);
6a488035
TO
116 while ($dao->fetch()) {
117 $workflows[$dao->workflow_id] = $dao->title;
118 }
119
120 if (empty($workflows)) {
121 return;
122 }
123
353ffa53 124 $html = NULL;
6a488035 125 $pathName = dirname(dirname(__FILE__));
353ffa53 126 $flag = FALSE;
6a488035
TO
127 foreach ($workflows as $workflow => $title) {
128 $name = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue',
129 $workflow,
130 'name',
131 'id'
132 );
133
134 // check if file exists locally
135 $textFileName = implode(DIRECTORY_SEPARATOR,
136 array(
137 $pathName,
138 "{$latestVer}.msg_template",
139 'message_templates',
140 "{$name}_text.tpl",
141 )
142 );
143
144 $htmlFileName = implode(DIRECTORY_SEPARATOR,
145 array(
146 $pathName,
147 "{$latestVer}.msg_template",
148 'message_templates',
149 "{$name}_html.tpl",
150 )
151 );
152
153 if (file_exists($textFileName) ||
154 file_exists($htmlFileName)
155 ) {
156 $flag = TRUE;
157 $html .= "<li>{$title}</li>";
158 }
159 }
160
161 if ($flag == TRUE) {
162 $html = "<ul>" . $html . "<ul>";
163
353ffa53
TO
164 $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(
165 1 => 'http://wiki.civicrm.org/confluence/display/CRMDOC/Message+Templates#MessageTemplates-UpgradesandCustomizedSystemWorkflowTemplates',
408b79bf 166 2 => $html,
353ffa53 167 ));
6a488035
TO
168 }
169 }
170
6a488035 171}