Commit | Line | Data |
---|---|---|
6cc25669 CW |
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. | | |
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 along with this program; if not, contact CiviCRM LLC | | |
21 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
22 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
23 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
24 | +--------------------------------------------------------------------+ | |
25 | */ | |
26 | ||
27 | /** | |
bf6a5362 | 28 | * Upgrade logic for 4.7 |
6cc25669 | 29 | */ |
bf6a5362 | 30 | class CRM_Upgrade_Incremental_php_FourSeven extends CRM_Upgrade_Incremental_Base { |
6cc25669 | 31 | |
f431d51f J |
32 | /** |
33 | * Compute any messages which should be displayed beforeupgrade. | |
34 | * | |
35 | * Note: This function is called iteratively for each upcoming | |
36 | * revision to the database. | |
37 | * | |
38 | * @param $preUpgradeMessage | |
39 | * @param string $rev | |
40 | * a version number, e.g. '4.4.alpha1', '4.4.beta3', '4.4.0'. | |
41 | * @param null $currentVer | |
42 | * | |
43 | * @return void | |
44 | */ | |
45 | public function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL) { | |
46 | if ($rev == '4.7.alpha1') { | |
47 | ||
48 | // CRM-16478 Remove custom fatal error template path option | |
49 | $config = CRM_Core_Config::singleton(); | |
18b3bef6 | 50 | if (!empty($config->fatalErrorTemplate) && $config->fatalErrorTemplate != 'CRM/common/fatal.tpl') { |
f431d51f J |
51 | $preUpgradeMessage .= '<p>' . ts('The custom fatal error template setting will be removed during the upgrade. You are currently using this custom template: %1 . Following the upgrade you will need to use the standard approach to overriding template files, as described in the documentation.', array(1 => $config->fatalErrorTemplate)) . '</p>'; |
52 | } | |
f431d51f J |
53 | } |
54 | } | |
55 | ||
6cc25669 CW |
56 | /** |
57 | * Compute any messages which should be displayed after upgrade. | |
58 | * | |
59 | * @param string $postUpgradeMessage | |
60 | * alterable. | |
61 | * @param string $rev | |
62 | * an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs. | |
63 | * @return void | |
64 | */ | |
65 | public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) { | |
6dbe2c23 CW |
66 | if ($rev == '4.7.alpha1') { |
67 | $config = CRM_Core_Config::singleton(); | |
bf6a5362 | 68 | // FIXME: Performing an upgrade step during postUpgrade message phase is probably bad |
6dbe2c23 CW |
69 | $editor_id = self::updateWysiwyg(); |
70 | $msg = NULL; | |
71 | $ext_href = 'href="' . CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1') . '"'; | |
72 | $dsp_href = 'href="' . CRM_Utils_System::url('civicrm/admin/setting/preferences/display', 'reset=1') . '"'; | |
73 | $blog_href = 'href="https://civicrm.org/blogs/colemanw/big-changes-wysiwyg-editing-47"'; | |
74 | switch ($editor_id) { | |
75 | // TinyMCE | |
76 | case 1: | |
77 | $msg = ts('Your configured editor "TinyMCE" is no longer part of the main CiviCRM download. To continue using it, visit the <a %1>Manage Extensions</a> page to download and install the TinyMCE extension.', array(1 => $ext_href)); | |
78 | break; | |
79 | ||
80 | // Drupal/Joomla editor | |
81 | case 3: | |
82 | case 4: | |
83 | $msg = ts('CiviCRM no longer integrates with the "%1 Default Editor." Your wysiwyg setting has been reset to the built-in CKEditor. <a %2>Learn more...</a>', array(1 => $config->userFramework, 2 => $blog_href)); | |
84 | break; | |
85 | } | |
86 | if ($msg) { | |
87 | $postUpgradeMessage .= '<p>' . $msg . '</p>'; | |
88 | } | |
89 | $postUpgradeMessage .= '<p>' . ts('CiviCRM now includes the easy-to-use CKEditor Configurator. To customize the features and display of your wysiwyg editor, visit the <a %1>Display Preferences</a> page. <a %2>Learn more...</a>', array(1 => $dsp_href, 2 => $blog_href)) . '</p>'; | |
dd55005c | 90 | |
91 | $postUpgradeMessage .= '<br /><br />' . ts('Default version of the following System Workflow Message Templates have been modified: <ul><li>Personal Campaign Pages - Owner Notification</li></ul> If you have modified these templates, please review the new default versions and implement updates as needed to your copies (Administer > Communications > Message Templates > System Workflow Messages).'); | |
f431d51f J |
92 | |
93 | $postUpgradeMessage .= '<p>' . ts('The custom fatal error template setting has been removed.') . '</p>'; | |
6dbe2c23 | 94 | } |
6cc25669 CW |
95 | } |
96 | ||
6cc25669 CW |
97 | /** |
98 | * Upgrade function. | |
99 | * | |
100 | * @param string $rev | |
101 | */ | |
102 | public function upgrade_4_7_alpha1($rev) { | |
18a687d7 | 103 | $this->addTask(ts('Migrate \'on behalf of\' information to module_data'), 'migrateOnBehalfOfInfo'); |
bf6a5362 | 104 | $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev); |
f806379b | 105 | $this->addTask(ts('Migrate Settings to %1', array(1 => $rev)), 'migrateSettings', $rev); |
0a95c936 | 106 | $this->addTask(ts('Add Getting Started dashlet to %1: SQL', array(1 => $rev)), 'addGettingStartedDashlet', $rev); |
6cc25669 CW |
107 | } |
108 | ||
109 | /** | |
110 | * CRM-16354 | |
111 | * | |
6dbe2c23 | 112 | * @return int |
6cc25669 | 113 | */ |
6dbe2c23 | 114 | public static function updateWysiwyg() { |
6cc25669 | 115 | $editorID = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'editor_id'); |
6dbe2c23 CW |
116 | // Previously a numeric value indicated one of 4 wysiwyg editors shipped in core, and no value indicated 'Textarea' |
117 | // Now the options are "Textarea", "CKEditor", and the rest have been dropped from core. | |
118 | $newEditor = $editorID ? "CKEditor" : "Textarea"; | |
119 | CRM_Core_BAO_Setting::setItem($newEditor, CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'editor_id'); | |
6cc25669 | 120 | |
6dbe2c23 | 121 | return $editorID; |
6cc25669 CW |
122 | } |
123 | ||
f806379b TO |
124 | /** |
125 | * Migrate any last remaining options from `civicrm_domain.config_backend` to `civicrm_setting`. | |
126 | * Cleanup setting schema. | |
127 | * | |
128 | * @param CRM_Queue_TaskContext $ctx | |
129 | * @return bool | |
130 | */ | |
131 | public function migrateSettings(CRM_Queue_TaskContext $ctx) { | |
132 | CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_setting DROP INDEX index_group_name'); | |
133 | CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_setting DROP COLUMN group_name'); | |
134 | CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_setting ADD UNIQUE INDEX index_domain_contact_name (domain_id, contact_id, name)'); | |
135 | ||
136 | $domainDao = CRM_Core_DAO::executeQuery('SELECT id, config_backend FROM civicrm_domain'); | |
137 | while ($domainDao->fetch()) { | |
138 | $settings = CRM_Upgrade_Incremental_php_FourSeven::convertBackendToSettings($domainDao->id, $domainDao->config_backend); | |
139 | CRM_Core_Error::debug_var('convertBackendToSettings', array( | |
140 | 'domainId' => $domainDao->id, | |
141 | 'backend' => $domainDao->config_backend, | |
142 | 'settings' => $settings, | |
143 | )); | |
144 | ||
145 | foreach ($settings as $name => $value) { | |
146 | $rowParams = array( | |
147 | 1 => array($domainDao->id, 'Positive'), | |
148 | 2 => array($name, 'String'), | |
149 | 3 => array(serialize($value), 'String'), | |
150 | ); | |
151 | $settingId = CRM_Core_DAO::singleValueQuery( | |
152 | 'SELECT id FROM civicrm_setting WHERE domain_id = %1 AND name = %2', | |
153 | $rowParams); | |
154 | if (!$settingId) { | |
155 | CRM_Core_DAO::executeQuery( | |
156 | 'INSERT INTO civicrm_setting (domain_id, name, value, is_domain) VALUES (%1,%2,%3,1)', | |
157 | $rowParams); | |
158 | } | |
159 | } | |
160 | } | |
161 | ||
162 | // TODO Should drop config_backend, but keeping it during alpha/beta cycle in case we miss something. | |
163 | // CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_domain DROP COLUMN config_backend'); | |
164 | ||
165 | return TRUE; | |
166 | } | |
167 | ||
168 | /** | |
169 | * Take a config_backend blob and produce an equivalent list of settings. | |
170 | * | |
171 | * @param int $domainId | |
172 | * Domain ID. | |
173 | * @param string $config_backend | |
174 | * Serialized blob. | |
175 | * @return array | |
176 | */ | |
177 | public static function convertBackendToSettings($domainId, $config_backend) { | |
178 | if (!$config_backend) { | |
179 | return array(); | |
180 | } | |
181 | ||
182 | $backend = unserialize($config_backend); | |
183 | if (!$backend) { | |
184 | return array(); | |
185 | } | |
186 | ||
187 | $mappings = \CRM_Core_Config_MagicMerge::getPropertyMap(); | |
188 | $settings = array(); | |
189 | foreach ($backend as $propertyName => $propertyValue) { | |
190 | if (isset($mappings[$propertyName][0]) && preg_match('/^setting/', $mappings[$propertyName][0])) { | |
191 | // $mapping format: $propertyName => Array(0 => $type, 1 => $setting|NULL). | |
192 | $settingName = isset($mappings[$propertyName][1]) ? $mappings[$propertyName][1] : $propertyName; | |
193 | $settings[$settingName] = $propertyValue; | |
194 | } | |
195 | } | |
196 | ||
197 | return $settings; | |
198 | } | |
199 | ||
0a95c936 | 200 | /** |
201 | * Add Getting Started dashlet to dashboard | |
202 | * | |
203 | * @param \CRM_Queue_TaskContext $ctx | |
204 | * | |
205 | * @return bool | |
206 | */ | |
207 | public function addGettingStartedDashlet(CRM_Queue_TaskContext $ctx) { | |
e1674273 | 208 | $sql = "SELECT count(*) FROM civicrm_dashboard WHERE name='gettingStarted'"; |
209 | $res = CRM_Core_DAO::singleValueQuery($sql); | |
210 | $domainId = CRM_Core_Config::domainID(); | |
211 | if ($res <= 0) { | |
212 | $sql = "INSERT INTO `civicrm_dashboard` | |
a8b704c5 | 213 | ( `domain_id`, `name`, `label`, `url`, `permission`, `permission_operator`, `column_no`, `is_minimized`, `is_active`, `weight`, `fullscreen_url`, `is_fullscreen`, `is_reserved`) VALUES ( {$domainId}, 'getting-started', 'Getting Started', 'civicrm/dashlet/getting-started?reset=1&snippet=5', 'access CiviCRM', NULL, 0, 0, 1, 0, 'civicrm/dashlet/getting-started?reset=1&snippet=5&context=dashletFullscreen', 1, 1)"; |
e1674273 | 214 | CRM_Core_DAO::executeQuery($sql); |
215 | // Add default position for Getting Started Dashlet ( left column) | |
216 | $sql = "INSERT INTO `civicrm_dashboard_contact` (dashboard_id, contact_id, column_no, is_active) | |
217 | SELECT (SELECT MAX(id) FROM `civicrm_dashboard`), contact_id, 0, IF (SUM(is_active) > 0, 1, 0) | |
218 | FROM `civicrm_dashboard_contact` WHERE 1 GROUP BY contact_id"; | |
219 | CRM_Core_DAO::executeQuery($sql); | |
220 | } | |
0a95c936 | 221 | return TRUE; |
e1674273 | 222 | } |
4175ee03 | 223 | |
6b1e1a2c | 224 | /** |
225 | * Migrate on-behalf information to uf_join.module_data as on-behalf columns will be dropped | |
226 | * on DB upgrade | |
227 | * | |
228 | * @param CRM_Queue_TaskContext $ctx | |
229 | * | |
230 | * @return bool | |
231 | * TRUE for success | |
232 | */ | |
233 | public static function migrateOnBehalfOfInfo(CRM_Queue_TaskContext $ctx) { | |
d3e92c88 | 234 | $domain = new CRM_Core_DAO_Domain(); |
235 | $domain->find(TRUE); | |
6b1e1a2c | 236 | |
d3e92c88 | 237 | // fetch onBehalf entry in UFJoin table |
6b1e1a2c | 238 | $ufGroupDAO = new CRM_Core_DAO_UFJoin(); |
239 | $ufGroupDAO->module = 'OnBehalf'; | |
240 | $ufGroupDAO->find(TRUE); | |
241 | ||
d3e92c88 | 242 | $forOrgColums = array(); |
243 | if ($domain->locales) { | |
244 | $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales); | |
245 | foreach ($locales as $locale) { | |
246 | $forOrgColums[] = "for_organization_{$locale}"; | |
247 | } | |
248 | } | |
249 | else { | |
250 | $forOrgColums[] = "for_organization"; | |
251 | } | |
252 | ||
253 | $query = " | |
254 | SELECT " . implode(", ", $forOrgColums) . ", uj.id as join_id, uj.uf_group_id as uf_group_id | |
255 | FROM civicrm_contribution_page cp | |
256 | INNER JOIN civicrm_uf_join uj ON uj.entity_id = cp.id AND uj.module = 'OnBehalf'"; | |
257 | $dao = CRM_Core_DAO::executeQuery($query, array(), TRUE, NULL, FALSE, FALSE); | |
6b1e1a2c | 258 | |
259 | if ($dao->N) { | |
6b1e1a2c | 260 | while ($dao->fetch()) { |
261 | $onBehalfParams['on_behalf'] = array('is_for_organization' => $dao->is_for_organization); | |
262 | if ($domain->locales) { | |
6b1e1a2c | 263 | foreach ($locales as $locale) { |
264 | $for_organization = "for_organization_{$locale}"; | |
265 | $onBehalfParams['on_behalf'] += array( | |
266 | $locale => array( | |
267 | 'for_organization' => $dao->$for_organization, | |
268 | ), | |
269 | ); | |
270 | } | |
271 | } | |
272 | else { | |
273 | $onBehalfParams['on_behalf'] += array( | |
274 | 'default' => array( | |
275 | 'for_organization' => $dao->for_organization, | |
276 | ), | |
277 | ); | |
278 | } | |
279 | $ufJoinParam = array( | |
280 | 'id' => $dao->join_id, | |
281 | 'module' => 'on_behalf', | |
d3e92c88 | 282 | 'uf_group_id' => $dao->uf_group_id, |
6b1e1a2c | 283 | 'module_data' => json_encode($onBehalfParams), |
284 | ); | |
285 | CRM_Core_BAO_UFJoin::create($ufJoinParam); | |
286 | } | |
287 | } | |
288 | ||
289 | return TRUE; | |
290 | } | |
cb804cd9 | 291 | |
6cc25669 | 292 | } |