Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | ||
3 | /* | |
4 | +--------------------------------------------------------------------+ | |
39de6fd5 | 5 | | CiviCRM version 4.6 | |
6a488035 | 6 | +--------------------------------------------------------------------+ |
06b69b18 | 7 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
8 | +--------------------------------------------------------------------+ |
9 | | This file is a part of CiviCRM. | | |
10 | | | | |
11 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
12 | | under the terms of the GNU Affero General Public License | | |
13 | | Version 3, 19 November 2007. | | |
14 | | | | |
15 | | CiviCRM is distributed in the hope that it will be useful, but | | |
16 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
17 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
18 | | See the GNU Affero General Public License for more details. | | |
19 | | | | |
20 | | You should have received a copy of the GNU Affero General Public | | |
21 | | License along 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 | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | class CRM_Upgrade_Incremental_php_FourOne { | |
8c904f47 CW |
36 | // This was changed in 4.3 so we define it locally for compatability with older dbs |
37 | const NAVIGATION_NAME = "Navigation Menu"; | |
38 | ||
624e56fa EM |
39 | /** |
40 | * @param $errors | |
41 | * | |
42 | * @return bool | |
43 | */ | |
00be9182 | 44 | public function verifyPreDBstate(&$errors) { |
6a488035 TO |
45 | $config = CRM_Core_Config::singleton(); |
46 | if (in_array('CiviCase', $config->enableComponents)) { | |
47 | if (!CRM_Core_DAO::checkTriggerViewPermission(TRUE, FALSE)) { | |
48 | $errors[] = ts('CiviCase now requires CREATE VIEW and DROP VIEW permissions for the database user.'); | |
49 | return FALSE; | |
50 | } | |
51 | } | |
52 | ||
53 | return TRUE; | |
54 | } | |
55 | ||
56 | /** | |
57 | * Compute any messages which should be displayed after upgrade | |
58 | * | |
59 | * @param $postUpgradeMessage string, alterable | |
60 | * @param $rev string, an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs | |
9d72cede | 61 | * |
6a488035 TO |
62 | * @return void |
63 | */ | |
00be9182 | 64 | public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) { |
6a488035 | 65 | if ($rev == '4.1.alpha1') { |
9d72cede EM |
66 | $postUpgradeMessage .= '<br />' . |
67 | ts('WARNING! CiviCRM 4.1 introduces an improved way of handling cron jobs. However the new method is NOT backwards compatible. <strong>Please notify your system administrator that all CiviCRM related cron jobs will cease to work, and will need to be re-configured (this includes sending CiviMail mailings, updating membership statuses, etc.).</strong> Refer to the <a href="%1">online documentation</a> for detailed instructions.', array(1 => 'http://wiki.civicrm.org/confluence/display/CRMDOC41/Managing+Scheduled+Jobs')); | |
68 | $postUpgradeMessage .= '<br />' . | |
69 | ts('The CiviCRM Administration menu structure has been re-organized during this upgrade to make it easier to find things and reduce the number of keystrokes. If you have customized this portion of the navigation menu - you should take a few minutes to review the changes. You may need to reimplement or move your customizations.'); | |
6a488035 | 70 | |
9d72cede EM |
71 | $postUpgradeMessage .= '<br />' . |
72 | ts('Yahoo recently discontinued their geocoding and mapping API service. If you previously used Yahoo, you will need to select and configure an alternate service in order to continue using geocoding/mapping tools.'); | |
6a488035 | 73 | |
9d72cede EM |
74 | $postUpgradeMessage .= '<br />' . |
75 | ts('We have integrated KCFinder with CKEditor and TinyMCE, which enables user to upload images. Note that all the images uploaded using KCFinder will be public.'); | |
6a488035 TO |
76 | } |
77 | } | |
78 | ||
624e56fa EM |
79 | /** |
80 | * @param $rev | |
81 | */ | |
00be9182 | 82 | public function upgrade_4_1_alpha1($rev) { |
6a488035 TO |
83 | $config = CRM_Core_Config::singleton(); |
84 | if (in_array('CiviCase', $config->enableComponents)) { | |
85 | if (!CRM_Case_BAO_Case::createCaseViews()) { | |
86 | $template = CRM_Core_Smarty::singleton(); | |
87 | $afterUpgradeMessage = ''; | |
88 | if ($afterUpgradeMessage = $template->get_template_vars('afterUpgradeMessage')) { | |
89 | $afterUpgradeMessage .= "<br/><br/>"; | |
90 | } | |
9d72cede EM |
91 | $afterUpgradeMessage .= |
92 | '<div class="crm-upgrade-case-views-error" style="background-color: #E43D2B; padding: 10px;">' . | |
93 | ts("There was a problem creating CiviCase database views. Please create the following views manually before using CiviCase:"); | |
94 | $afterUpgradeMessage .= | |
95 | '<div class="crm-upgrade-case-views-query"><div>' . | |
96 | CRM_Case_BAO_Case::createCaseViewsQuery('upcoming') . '</div><div>' . | |
97 | CRM_Case_BAO_Case::createCaseViewsQuery('recent') . '</div>' . | |
98 | '</div></div>'; | |
6a488035 TO |
99 | $template->assign('afterUpgradeMessage', $afterUpgradeMessage); |
100 | } | |
101 | } | |
102 | ||
103 | $upgrade = new CRM_Upgrade_Form(); | |
104 | $upgrade->processSQL($rev); | |
105 | ||
106 | ||
107 | $this->transferPreferencesToSettings(); | |
108 | $this->createNewSettings(); | |
109 | ||
110 | // now modify the config so that the directories are now stored in the settings table | |
111 | // CRM-8780 | |
112 | $params = array(); | |
113 | CRM_Core_BAO_ConfigSetting::add($params); | |
114 | ||
115 | // also reset navigation | |
116 | CRM_Core_BAO_Navigation::resetNavigation(); | |
117 | } | |
118 | ||
00be9182 | 119 | public function transferPreferencesToSettings() { |
6a488035 TO |
120 | // first transfer system preferences |
121 | $domainColumnNames = array( | |
122 | CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME => array( | |
123 | 'contact_view_options', | |
124 | 'contact_edit_options', | |
125 | 'advanced_search_options', | |
126 | 'user_dashboard_options', | |
127 | 'address_options', | |
128 | 'address_format', | |
129 | 'mailing_format', | |
130 | 'display_name_format', | |
131 | 'sort_name_format', | |
132 | 'editor_id', | |
133 | 'contact_autocomplete_options', | |
134 | ), | |
135 | CRM_Core_BAO_Setting::ADDRESS_STANDARDIZATION_PREFERENCES_NAME => array( | |
136 | 'address_standardization_provider', | |
137 | 'address_standardization_userid', | |
138 | 'address_standardization_url', | |
139 | ), | |
140 | CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME => array( | |
141 | 'mailing_backend', | |
142 | ), | |
143 | ); | |
144 | ||
145 | ||
6a488035 | 146 | $userColumnNames = array( |
8c904f47 | 147 | self::NAVIGATION_NAME => array( |
6a488035 TO |
148 | 'navigation', |
149 | ), | |
150 | ); | |
151 | ||
152 | $sql = " | |
153 | SELECT * | |
154 | FROM civicrm_preferences | |
155 | WHERE domain_id = %1 | |
156 | "; | |
157 | $params = array(1 => array(CRM_Core_Config::domainID(), 'Integer')); | |
158 | $dao = CRM_Core_DAO::executeQuery($sql, $params); | |
159 | ||
160 | $domainID = CRM_Core_Config::domainID(); | |
161 | $createdDate = date('YmdHis'); | |
162 | ||
163 | while ($dao->fetch()) { | |
164 | if ($dao->is_domain) { | |
165 | $values = array(); | |
166 | foreach ($domainColumnNames as $groupName => $settingNames) { | |
167 | foreach ($settingNames as $settingName) { | |
168 | if (empty($dao->$settingName)) { | |
169 | $value = NULL; | |
170 | } | |
171 | else { | |
172 | if ($settingName == 'mailing_backend') { | |
173 | $value = $dao->$settingName; | |
174 | } | |
175 | else { | |
176 | $value = serialize($dao->$settingName); | |
177 | } | |
178 | } | |
179 | ||
180 | if ($value) { | |
181 | $value = addslashes($value); | |
182 | } | |
183 | $value = $value ? "'{$value}'" : 'null'; | |
184 | $values[] = " ('{$groupName}','{$settingName}', {$value}, {$domainID}, null, 1, '{$createdDate}', null )"; | |
185 | } | |
186 | } | |
187 | } | |
188 | else { | |
189 | // this is a user setting | |
190 | foreach ($userColumnNames as $groupName => $settingNames) { | |
191 | foreach ($settingNames as $settingName) { | |
192 | $value = empty($dao->$settingName) ? NULL : serialize($dao->$settingName); | |
193 | ||
194 | if ($value) { | |
195 | $value = addslashes($value); | |
196 | } | |
197 | $value = $value ? "'{$value}'" : 'null'; | |
198 | $values[] = " ('{$groupName}', '{$settingName}', {$value}, {$domainID}, {$dao->contact_id}, 0, '{$createdDate}', null )"; | |
199 | } | |
200 | } | |
201 | } | |
202 | } | |
203 | ||
204 | $sql = " | |
205 | INSERT INTO civicrm_setting( group_name, name, value, domain_id, contact_id, is_domain, created_date, created_id ) | |
206 | VALUES | |
207 | "; | |
208 | ||
209 | $sql .= implode(",\n", $values); | |
210 | CRM_Core_DAO::executeQuery($sql); | |
211 | ||
212 | // now drop the civicrm_preferences table | |
213 | $sql = "DROP TABLE civicrm_preferences"; | |
214 | CRM_Core_DAO::executeQuery($sql); | |
215 | } | |
216 | ||
00be9182 | 217 | public function createNewSettings() { |
6a488035 | 218 | $domainColumns = array( |
9d72cede EM |
219 | CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME => array( |
220 | array('contact_ajax_check_similar', 1), | |
6a488035 TO |
221 | array('activity_assignee_notification', 1), |
222 | ), | |
9d72cede EM |
223 | CRM_Core_BAO_Setting::CAMPAIGN_PREFERENCES_NAME => array( |
224 | array('tag_unconfirmed', 'Unconfirmed'), | |
6a488035 TO |
225 | array('petition_contacts', 'Petition Contacts'), |
226 | ), | |
9d72cede EM |
227 | CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME => array( |
228 | array('enable_cart', 0), | |
6a488035 | 229 | ), |
9d72cede EM |
230 | CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME => array( |
231 | array('profile_double_optin', 1), | |
6a488035 TO |
232 | array('profile_add_to_group_double_optin', 0), |
233 | array('track_civimail_replies', 0), | |
234 | array('civimail_workflow', 0), | |
235 | array('civimail_server_wide_lock', 0), | |
236 | ), | |
9d72cede EM |
237 | CRM_Core_BAO_Setting::MEMBER_PREFERENCES_NAME => array( |
238 | array('default_renewal_contribution_page', NULL), | |
6a488035 | 239 | ), |
9d72cede EM |
240 | CRM_Core_BAO_Setting::MULTISITE_PREFERENCES_NAME => array( |
241 | array('is_enabled', 0), | |
6a488035 TO |
242 | array('uniq_email_per_site', 0), |
243 | array('domain_group_id', 0), | |
244 | array('event_price_set_domain_id', 0), | |
245 | ), | |
9d72cede EM |
246 | CRM_Core_BAO_Setting::DIRECTORY_PREFERENCES_NAME => array( |
247 | array('uploadDir', NULL), | |
6a488035 TO |
248 | array('imageUploadDir', NULL), |
249 | array('customFileUploadDir', NULL), | |
250 | array('customTemplateDir', NULL), | |
251 | array('customPHPPathDir', NULL), | |
252 | array('extensionsDir', NULL), | |
253 | ), | |
9d72cede EM |
254 | CRM_Core_BAO_Setting::URL_PREFERENCES_NAME => array( |
255 | array('userFrameworkResourceURL', NULL), | |
6a488035 TO |
256 | array('imageUploadURL', NULL), |
257 | array('customCSSURL', NULL), | |
258 | ), | |
259 | ); | |
260 | ||
261 | $domainID = CRM_Core_Config::domainID(); | |
262 | $createdDate = date('YmdHis'); | |
263 | ||
264 | $dbSettings = array(); | |
265 | self::retrieveDirectoryAndURLPaths($dbSettings); | |
266 | ||
267 | foreach ($domainColumns as $groupName => $settings) { | |
268 | foreach ($settings as $setting) { | |
269 | ||
9d72cede EM |
270 | if (isset($dbSettings[$groupName][$setting[0]]) && |
271 | !empty($dbSettings[$groupName][$setting[0]]) | |
272 | ) { | |
6a488035 TO |
273 | $setting[1] = $dbSettings[$groupName][$setting[0]]; |
274 | } | |
275 | ||
276 | $value = $setting[1] === NULL ? NULL : serialize($setting[1]); | |
277 | ||
278 | if ($value) { | |
279 | $value = addslashes($value); | |
280 | } | |
281 | ||
282 | $value = $value ? "'{$value}'" : 'null'; | |
283 | $values[] = "( '{$groupName}', '{$setting[0]}', {$value}, {$domainID}, null, 0, '{$createdDate}', null )"; | |
284 | } | |
285 | } | |
286 | $sql = " | |
287 | INSERT INTO civicrm_setting( group_name, name, value, domain_id, contact_id, is_domain, created_date, created_id ) | |
288 | VALUES | |
289 | "; | |
290 | $sql .= implode(",\n", $values); | |
291 | CRM_Core_DAO::executeQuery($sql); | |
292 | } | |
293 | ||
624e56fa | 294 | /** |
c490a46a | 295 | * @param array $params |
624e56fa | 296 | */ |
00be9182 | 297 | public static function retrieveDirectoryAndURLPaths(&$params) { |
6a488035 TO |
298 | |
299 | $sql = " | |
300 | SELECT v.name as valueName, v.value, g.name as optionName | |
301 | FROM civicrm_option_value v, | |
302 | civicrm_option_group g | |
303 | WHERE ( g.name = 'directory_preferences' | |
304 | OR g.name = 'url_preferences' ) | |
305 | AND v.option_group_id = g.id | |
306 | AND v.is_active = 1 | |
307 | "; | |
308 | $dao = CRM_Core_DAO::executeQuery($sql); | |
309 | while ($dao->fetch()) { | |
310 | if (!$dao->value) { | |
311 | continue; | |
312 | } | |
313 | ||
314 | $groupName = CRM_Core_BAO_Setting::DIRECTORY_PREFERENCES_NAME; | |
315 | if ($dao->optionName == 'url_preferences') { | |
316 | $groupName = CRM_Core_BAO_Setting::URL_PREFERENCES_NAME; | |
317 | } | |
318 | $params[$groupName][$dao->valueName] = $dao->value; | |
319 | } | |
320 | } | |
321 | ||
624e56fa EM |
322 | /** |
323 | * @param $rev | |
324 | */ | |
00be9182 | 325 | public function upgrade_4_1_alpha2($rev) { |
9d72cede | 326 | $dao = new CRM_Core_DAO_Setting(); |
6a488035 | 327 | $dao->group_name = 'Directory Preferences'; |
9d72cede | 328 | $dao->name = 'customTemplateDir'; |
6a488035 | 329 | if (!($dao->find(TRUE))) { |
9d72cede | 330 | $dao->domain_id = CRM_Core_Config::domainID(); |
6a488035 | 331 | $dao->created_date = date('YmdHis'); |
9d72cede | 332 | $dao->is_domain = 0; |
6a488035 TO |
333 | $dao->save(); |
334 | } | |
335 | $dao->free(); | |
336 | ||
337 | // Do the regular upgrade | |
338 | $upgrade = new CRM_Upgrade_Form; | |
339 | $upgrade->processSQL($rev); | |
340 | } | |
341 | ||
624e56fa EM |
342 | /** |
343 | * @param $rev | |
344 | */ | |
00be9182 | 345 | public function upgrade_4_1_beta1($rev) { |
6a488035 TO |
346 | //CRM-9311 |
347 | $groupNames = array('directory_preferences', 'url_preferences'); | |
348 | foreach ($groupNames as $groupName) { | |
349 | CRM_Core_OptionGroup::deleteAssoc($groupName); | |
350 | } | |
351 | ||
352 | $domainCols = array( | |
9d72cede | 353 | CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME => array( |
6a488035 TO |
354 | 'contact_ajax_check_similar', |
355 | 'activity_assignee_notification', | |
356 | ), | |
9d72cede | 357 | CRM_Core_BAO_Setting::CAMPAIGN_PREFERENCES_NAME => array( |
6a488035 TO |
358 | 'tag_unconfirmed', |
359 | 'petition_contacts', | |
360 | ), | |
9d72cede | 361 | CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME => array( |
6a488035 TO |
362 | 'enable_cart', |
363 | ), | |
9d72cede | 364 | CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME => array( |
6a488035 TO |
365 | 'profile_double_optin', |
366 | 'profile_add_to_group_double_optin', | |
367 | 'track_civimail_replies', | |
368 | 'civimail_workflow', | |
369 | 'civimail_server_wide_lock', | |
370 | ), | |
9d72cede | 371 | CRM_Core_BAO_Setting::MEMBER_PREFERENCES_NAME => array( |
6a488035 TO |
372 | 'default_renewal_contribution_page', |
373 | ), | |
9d72cede | 374 | CRM_Core_BAO_Setting::MULTISITE_PREFERENCES_NAME => array( |
6a488035 TO |
375 | 'is_enabled', |
376 | 'uniq_email_per_site', | |
377 | 'domain_group_id', | |
378 | 'event_price_set_domain_id', | |
379 | ), | |
9d72cede | 380 | CRM_Core_BAO_Setting::DIRECTORY_PREFERENCES_NAME => array( |
6a488035 TO |
381 | 'uploadDir', |
382 | 'imageUploadDir', | |
383 | 'customFileUploadDir', | |
384 | 'customTemplateDir', | |
385 | 'customPHPPathDir', | |
386 | 'extensionsDir', | |
387 | ), | |
9d72cede | 388 | CRM_Core_BAO_Setting::URL_PREFERENCES_NAME => array( |
6a488035 TO |
389 | 'userFrameworkResourceURL', |
390 | 'imageUploadURL', | |
391 | 'customCSSURL', | |
392 | ), | |
393 | ); | |
394 | ||
395 | $arrGroupNames = array_keys($domainCols); | |
9d72cede EM |
396 | $groupNames = implode("','", $arrGroupNames); |
397 | $arrNames = array(); | |
6a488035 TO |
398 | foreach ($domainCols as $groupName => $names) { |
399 | $arrNames[] = implode("','", $names); | |
400 | } | |
401 | $name = implode("','", $arrNames); | |
402 | ||
403 | $sql = " | |
404 | update civicrm_setting set is_domain = 1 where is_domain = 0 and group_name in ( '{$groupNames}' ) and name in ('{$name}')"; | |
405 | ||
406 | CRM_Core_DAO::executeQuery($sql); | |
407 | ||
408 | $upgrade = new CRM_Upgrade_Form(); | |
409 | $upgrade->assign('addWightForActivity', !(CRM_Core_DAO::checkFieldExists('civicrm_activity', 'weight'))); | |
410 | $upgrade->processSQL($rev); | |
411 | } | |
412 | ||
624e56fa EM |
413 | /** |
414 | * @param $rev | |
415 | */ | |
00be9182 | 416 | public function upgrade_4_1_1($rev) { |
6a488035 TO |
417 | $upgrade = new CRM_Upgrade_Form(); |
418 | $upgrade->assign('addDedupeEmail', !(CRM_Core_DAO::checkFieldExists('civicrm_mailing', 'dedupe_email'))); | |
419 | ||
420 | $sql = "SELECT id FROM civicrm_worldregion LIMIT 1"; | |
421 | $upgrade->assign('worldRegionEmpty', !CRM_Core_DAO::singleValueQuery($sql)); | |
422 | ||
423 | $upgrade->processSQL($rev); | |
424 | } | |
425 | ||
624e56fa EM |
426 | /** |
427 | * @return string | |
428 | */ | |
00be9182 | 429 | public function getTemplateMessage() { |
6a488035 TO |
430 | return "Blah"; |
431 | } | |
432 | } |