Merge pull request #9573 from totten/master-inheritdoc
[civicrm-core.git] / CRM / Upgrade / Incremental / General.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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-2016
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 MIN_RECOMMENDED_PHP_VER = '5.5';
45
46 /**
47 * The minimum PHP version required to install Civi.
48 *
49 * @see install/index.php
50 */
51 const MIN_INSTALL_PHP_VER = '5.3.4';
52
53 /**
54 * The minimum PHP version required to avoid known
55 * limits or defects.
56 */
57 const MIN_DEFECT_PHP_VER = '5.3.23';
58
59 /**
60 * Compute any messages which should be displayed before upgrade.
61 *
62 * @param string $preUpgradeMessage
63 * alterable.
64 * @param $currentVer
65 * @param $latestVer
66 */
67 public static function setPreUpgradeMessage(&$preUpgradeMessage, $currentVer, $latestVer) {
68 if (version_compare(phpversion(), self::MIN_RECOMMENDED_PHP_VER) < 0) {
69 $preUpgradeMessage .= '<p>' .
70 ts('This webserver is running an outdated version of PHP (%1). It is strongly recommended to upgrade to PHP %2 or later, as older versions can present a security risk.', array(
71 1 => phpversion(),
72 2 => self::MIN_RECOMMENDED_PHP_VER,
73 )) .
74 '</p>';
75 }
76
77 // http://issues.civicrm.org/jira/browse/CRM-13572
78 // Depending on how the code was upgraded, some sites may still have copies of old
79 // source files left behind. This is often a forgivable offense, but it's quite
80 // dangerous for CIVI-SA-2013-001.
81 global $civicrm_root;
82 $ofcFile = "$civicrm_root/packages/OpenFlashChart/php-ofc-library/ofc_upload_image.php";
83 if (file_exists($ofcFile)) {
84 if (@unlink($ofcFile)) {
85 $preUpgradeMessage .= '<br />' . ts('This system included an outdated, insecure script (%1). The file was automatically deleted.', array(
86 1 => $ofcFile,
87 ));
88 }
89 else {
90 $preUpgradeMessage .= '<br />' . ts('This system includes an outdated, insecure script (%1). Please delete it.', array(
91 1 => $ofcFile,
92 ));
93 }
94 }
95
96 if (Civi::settings()->get('enable_innodb_fts')) {
97 // The FTS indexing feature dynamically manipulates the schema which could
98 // cause conflicts with other layers that manipulate the schema. The
99 // simplest thing is to turn it off and back on.
100
101 // It may not always be necessary to do this -- but I doubt we're going to test
102 // systematically in future releases. When it is necessary, one could probably
103 // ignore the matter and simply run CRM_Core_InnoDBIndexer::fixSchemaDifferences
104 // after the upgrade. But that's speculative. For now, we'll leave this
105 // advanced feature in the hands of the sysadmin.
106 $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".');
107 }
108 }
109
110 /**
111 * @param $message
112 * @param $latestVer
113 * @param $currentVer
114 */
115 public static function checkMessageTemplate(&$message, $latestVer, $currentVer) {
116
117 $sql = "SELECT orig.workflow_id as workflow_id,
118 orig.msg_title as title
119 FROM civicrm_msg_template diverted JOIN civicrm_msg_template orig ON (
120 diverted.workflow_id = orig.workflow_id AND
121 orig.is_reserved = 1 AND (
122 diverted.msg_subject != orig.msg_subject OR
123 diverted.msg_text != orig.msg_text OR
124 diverted.msg_html != orig.msg_html
125 )
126 )";
127
128 $dao = CRM_Core_DAO::executeQuery($sql);
129 while ($dao->fetch()) {
130 $workflows[$dao->workflow_id] = $dao->title;
131 }
132
133 if (empty($workflows)) {
134 return;
135 }
136
137 $html = NULL;
138 $pathName = dirname(dirname(__FILE__));
139 $flag = FALSE;
140 foreach ($workflows as $workflow => $title) {
141 $name = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue',
142 $workflow,
143 'name',
144 'id'
145 );
146
147 // check if file exists locally
148 $textFileName = implode(DIRECTORY_SEPARATOR,
149 array(
150 $pathName,
151 "{$latestVer}.msg_template",
152 'message_templates',
153 "{$name}_text.tpl",
154 )
155 );
156
157 $htmlFileName = implode(DIRECTORY_SEPARATOR,
158 array(
159 $pathName,
160 "{$latestVer}.msg_template",
161 'message_templates',
162 "{$name}_html.tpl",
163 )
164 );
165
166 if (file_exists($textFileName) ||
167 file_exists($htmlFileName)
168 ) {
169 $flag = TRUE;
170 $html .= "<li>{$title}</li>";
171 }
172 }
173
174 if ($flag == TRUE) {
175 $html = "<ul>" . $html . "<ul>";
176
177 $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(
178 1 => 'http://wiki.civicrm.org/confluence/display/CRMDOC/Message+Templates#MessageTemplates-UpgradesandCustomizedSystemWorkflowTemplates',
179 2 => $html,
180 ));
181 }
182 }
183
184 }