Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
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 | | |
c73475ea | 12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | |
6a488035 TO |
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 | | |
c73475ea WA |
20 | | License and the CiviCRM Licensing Exception along | |
21 | | with this program; if not, contact CiviCRM LLC | | |
6a488035 TO |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | class CRM_Upgrade_Incremental_php_FourOne { | |
b44e3f84 | 36 | // This was changed in 4.3 so we define it locally for compatibility with older dbs |
8c904f47 CW |
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 | /** | |
fe482240 | 57 | * Compute any messages which should be displayed after upgrade. |
6a488035 | 58 | * |
5a4f6742 CW |
59 | * @param string $postUpgradeMessage |
60 | * alterable. | |
61 | * @param string $rev | |
62 | * an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs. | |
9d72cede | 63 | * |
6a488035 TO |
64 | * @return void |
65 | */ | |
00be9182 | 66 | public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) { |
6a488035 | 67 | if ($rev == '4.1.alpha1') { |
9d72cede EM |
68 | $postUpgradeMessage .= '<br />' . |
69 | 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')); | |
70 | $postUpgradeMessage .= '<br />' . | |
71 | 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 | 72 | |
9d72cede EM |
73 | $postUpgradeMessage .= '<br />' . |
74 | 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 | 75 | |
9d72cede EM |
76 | $postUpgradeMessage .= '<br />' . |
77 | 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 |
78 | } |
79 | } | |
80 | ||
624e56fa EM |
81 | /** |
82 | * @param $rev | |
83 | */ | |
00be9182 | 84 | public function upgrade_4_1_alpha1($rev) { |
6a488035 TO |
85 | $config = CRM_Core_Config::singleton(); |
86 | if (in_array('CiviCase', $config->enableComponents)) { | |
87 | if (!CRM_Case_BAO_Case::createCaseViews()) { | |
88 | $template = CRM_Core_Smarty::singleton(); | |
89 | $afterUpgradeMessage = ''; | |
90 | if ($afterUpgradeMessage = $template->get_template_vars('afterUpgradeMessage')) { | |
91 | $afterUpgradeMessage .= "<br/><br/>"; | |
92 | } | |
9d72cede EM |
93 | $afterUpgradeMessage .= |
94 | '<div class="crm-upgrade-case-views-error" style="background-color: #E43D2B; padding: 10px;">' . | |
95 | ts("There was a problem creating CiviCase database views. Please create the following views manually before using CiviCase:"); | |
96 | $afterUpgradeMessage .= | |
97 | '<div class="crm-upgrade-case-views-query"><div>' . | |
98 | CRM_Case_BAO_Case::createCaseViewsQuery('upcoming') . '</div><div>' . | |
99 | CRM_Case_BAO_Case::createCaseViewsQuery('recent') . '</div>' . | |
100 | '</div></div>'; | |
6a488035 TO |
101 | $template->assign('afterUpgradeMessage', $afterUpgradeMessage); |
102 | } | |
103 | } | |
104 | ||
105 | $upgrade = new CRM_Upgrade_Form(); | |
106 | $upgrade->processSQL($rev); | |
107 | ||
6a488035 TO |
108 | $this->transferPreferencesToSettings(); |
109 | $this->createNewSettings(); | |
110 | ||
111 | // now modify the config so that the directories are now stored in the settings table | |
112 | // CRM-8780 | |
113 | $params = array(); | |
114 | CRM_Core_BAO_ConfigSetting::add($params); | |
115 | ||
116 | // also reset navigation | |
117 | CRM_Core_BAO_Navigation::resetNavigation(); | |
118 | } | |
119 | ||
00be9182 | 120 | public function transferPreferencesToSettings() { |
6a488035 TO |
121 | // first transfer system preferences |
122 | $domainColumnNames = array( | |
123 | CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME => array( | |
124 | 'contact_view_options', | |
125 | 'contact_edit_options', | |
126 | 'advanced_search_options', | |
127 | 'user_dashboard_options', | |
128 | 'address_options', | |
129 | 'address_format', | |
130 | 'mailing_format', | |
131 | 'display_name_format', | |
132 | 'sort_name_format', | |
133 | 'editor_id', | |
134 | 'contact_autocomplete_options', | |
135 | ), | |
136 | CRM_Core_BAO_Setting::ADDRESS_STANDARDIZATION_PREFERENCES_NAME => array( | |
137 | 'address_standardization_provider', | |
138 | 'address_standardization_userid', | |
139 | 'address_standardization_url', | |
140 | ), | |
141 | CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME => array( | |
142 | 'mailing_backend', | |
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 | |
408b79bf | 338 | $upgrade = new CRM_Upgrade_Form(); |
6a488035 TO |
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 | } | |
96025800 | 432 | |
6a488035 | 433 | } |