Ian province abbreviation patch - issue 724
[civicrm-core.git] / CRM / Upgrade / Incremental / General.php
... / ...
CommitLineData
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 */
39class 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 .= '<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
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.
68 global $civicrm_root;
69 $ofcFile = "$civicrm_root/packages/OpenFlashChart/php-ofc-library/ofc_upload_image.php";
70 if (file_exists($ofcFile)) {
71 if (@unlink($ofcFile)) {
72 $preUpgradeMessage .= '<br />' . ts('This system included an outdated, insecure script (%1). The file was automatically deleted.', array(
73 1 => $ofcFile,
74 ));
75 }
76 else {
77 $preUpgradeMessage .= '<br />' . ts('This system includes an outdated, insecure script (%1). Please delete it.', array(
78 1 => $ofcFile,
79 ));
80 }
81 }
82
83 if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SEARCH_PREFERENCES_NAME, 'enable_innodb_fts', NULL, FALSE)) {
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 }
95 }
96
97 /**
98 * @param $message
99 * @param $latestVer
100 * @param $currentVer
101 */
102 public static function checkMessageTemplate(&$message, $latestVer, $currentVer) {
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
115 $dao = CRM_Core_DAO::executeQuery($sql);
116 while ($dao->fetch()) {
117 $workflows[$dao->workflow_id] = $dao->title;
118 }
119
120 if (empty($workflows)) {
121 return;
122 }
123
124 $html = NULL;
125 $pathName = dirname(dirname(__FILE__));
126 $flag = FALSE;
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
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',
166 2 => $html,
167 ));
168 }
169 }
170
171}