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