Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
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 | |
8c9251b3 | 31 | * @copyright CiviCRM LLC (c) 2004-2018 |
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)) { | |
b604d7ec | 48 | $errors[] = 'CiviCase now requires CREATE VIEW and DROP VIEW permissions for the database user.'; |
6a488035 TO |
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. | |
6a488035 | 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 | |
b604d7ec | 71 | $postUpgradeMessage .= '<br />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 | 72 | |
9d72cede EM |
73 | $postUpgradeMessage .= '<br />' . |
74 | 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 |
75 | } |
76 | } | |
77 | ||
624e56fa EM |
78 | /** |
79 | * @param $rev | |
80 | */ | |
00be9182 | 81 | public function upgrade_4_1_alpha1($rev) { |
6a488035 TO |
82 | $config = CRM_Core_Config::singleton(); |
83 | if (in_array('CiviCase', $config->enableComponents)) { | |
84 | if (!CRM_Case_BAO_Case::createCaseViews()) { | |
85 | $template = CRM_Core_Smarty::singleton(); | |
86 | $afterUpgradeMessage = ''; | |
87 | if ($afterUpgradeMessage = $template->get_template_vars('afterUpgradeMessage')) { | |
88 | $afterUpgradeMessage .= "<br/><br/>"; | |
89 | } | |
9d72cede EM |
90 | $afterUpgradeMessage .= |
91 | '<div class="crm-upgrade-case-views-error" style="background-color: #E43D2B; padding: 10px;">' . | |
92 | ts("There was a problem creating CiviCase database views. Please create the following views manually before using CiviCase:"); | |
93 | $afterUpgradeMessage .= | |
94 | '<div class="crm-upgrade-case-views-query"><div>' . | |
95 | CRM_Case_BAO_Case::createCaseViewsQuery('upcoming') . '</div><div>' . | |
96 | CRM_Case_BAO_Case::createCaseViewsQuery('recent') . '</div>' . | |
97 | '</div></div>'; | |
6a488035 TO |
98 | $template->assign('afterUpgradeMessage', $afterUpgradeMessage); |
99 | } | |
100 | } | |
101 | ||
102 | $upgrade = new CRM_Upgrade_Form(); | |
103 | $upgrade->processSQL($rev); | |
104 | ||
6a488035 TO |
105 | $this->transferPreferencesToSettings(); |
106 | $this->createNewSettings(); | |
107 | ||
108 | // now modify the config so that the directories are now stored in the settings table | |
109 | // CRM-8780 | |
110 | $params = array(); | |
111 | CRM_Core_BAO_ConfigSetting::add($params); | |
112 | ||
113 | // also reset navigation | |
114 | CRM_Core_BAO_Navigation::resetNavigation(); | |
115 | } | |
116 | ||
00be9182 | 117 | public function transferPreferencesToSettings() { |
6a488035 TO |
118 | // first transfer system preferences |
119 | $domainColumnNames = array( | |
120 | CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME => array( | |
121 | 'contact_view_options', | |
122 | 'contact_edit_options', | |
123 | 'advanced_search_options', | |
124 | 'user_dashboard_options', | |
125 | 'address_options', | |
126 | 'address_format', | |
127 | 'mailing_format', | |
128 | 'display_name_format', | |
129 | 'sort_name_format', | |
130 | 'editor_id', | |
131 | 'contact_autocomplete_options', | |
132 | ), | |
133 | CRM_Core_BAO_Setting::ADDRESS_STANDARDIZATION_PREFERENCES_NAME => array( | |
134 | 'address_standardization_provider', | |
135 | 'address_standardization_userid', | |
136 | 'address_standardization_url', | |
137 | ), | |
138 | CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME => array( | |
139 | 'mailing_backend', | |
140 | ), | |
141 | ); | |
142 | ||
6a488035 | 143 | $userColumnNames = array( |
8c904f47 | 144 | self::NAVIGATION_NAME => array( |
6a488035 TO |
145 | 'navigation', |
146 | ), | |
147 | ); | |
148 | ||
149 | $sql = " | |
150 | SELECT * | |
151 | FROM civicrm_preferences | |
152 | WHERE domain_id = %1 | |
153 | "; | |
154 | $params = array(1 => array(CRM_Core_Config::domainID(), 'Integer')); | |
155 | $dao = CRM_Core_DAO::executeQuery($sql, $params); | |
156 | ||
157 | $domainID = CRM_Core_Config::domainID(); | |
158 | $createdDate = date('YmdHis'); | |
159 | ||
160 | while ($dao->fetch()) { | |
161 | if ($dao->is_domain) { | |
162 | $values = array(); | |
163 | foreach ($domainColumnNames as $groupName => $settingNames) { | |
164 | foreach ($settingNames as $settingName) { | |
165 | if (empty($dao->$settingName)) { | |
166 | $value = NULL; | |
167 | } | |
168 | else { | |
169 | if ($settingName == 'mailing_backend') { | |
170 | $value = $dao->$settingName; | |
171 | } | |
172 | else { | |
173 | $value = serialize($dao->$settingName); | |
174 | } | |
175 | } | |
176 | ||
177 | if ($value) { | |
178 | $value = addslashes($value); | |
179 | } | |
180 | $value = $value ? "'{$value}'" : 'null'; | |
181 | $values[] = " ('{$groupName}','{$settingName}', {$value}, {$domainID}, null, 1, '{$createdDate}', null )"; | |
182 | } | |
183 | } | |
184 | } | |
185 | else { | |
186 | // this is a user setting | |
187 | foreach ($userColumnNames as $groupName => $settingNames) { | |
188 | foreach ($settingNames as $settingName) { | |
189 | $value = empty($dao->$settingName) ? NULL : serialize($dao->$settingName); | |
190 | ||
191 | if ($value) { | |
192 | $value = addslashes($value); | |
193 | } | |
194 | $value = $value ? "'{$value}'" : 'null'; | |
195 | $values[] = " ('{$groupName}', '{$settingName}', {$value}, {$domainID}, {$dao->contact_id}, 0, '{$createdDate}', null )"; | |
196 | } | |
197 | } | |
198 | } | |
199 | } | |
200 | ||
201 | $sql = " | |
202 | INSERT INTO civicrm_setting( group_name, name, value, domain_id, contact_id, is_domain, created_date, created_id ) | |
203 | VALUES | |
204 | "; | |
205 | ||
206 | $sql .= implode(",\n", $values); | |
207 | CRM_Core_DAO::executeQuery($sql); | |
208 | ||
209 | // now drop the civicrm_preferences table | |
210 | $sql = "DROP TABLE civicrm_preferences"; | |
211 | CRM_Core_DAO::executeQuery($sql); | |
212 | } | |
213 | ||
00be9182 | 214 | public function createNewSettings() { |
6a488035 | 215 | $domainColumns = array( |
9d72cede EM |
216 | CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME => array( |
217 | array('contact_ajax_check_similar', 1), | |
6a488035 TO |
218 | array('activity_assignee_notification', 1), |
219 | ), | |
9d72cede EM |
220 | CRM_Core_BAO_Setting::CAMPAIGN_PREFERENCES_NAME => array( |
221 | array('tag_unconfirmed', 'Unconfirmed'), | |
6a488035 TO |
222 | array('petition_contacts', 'Petition Contacts'), |
223 | ), | |
9d72cede EM |
224 | CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME => array( |
225 | array('enable_cart', 0), | |
6a488035 | 226 | ), |
9d72cede EM |
227 | CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME => array( |
228 | array('profile_double_optin', 1), | |
6a488035 TO |
229 | array('profile_add_to_group_double_optin', 0), |
230 | array('track_civimail_replies', 0), | |
231 | array('civimail_workflow', 0), | |
232 | array('civimail_server_wide_lock', 0), | |
233 | ), | |
9d72cede EM |
234 | CRM_Core_BAO_Setting::MEMBER_PREFERENCES_NAME => array( |
235 | array('default_renewal_contribution_page', NULL), | |
6a488035 | 236 | ), |
9d72cede EM |
237 | CRM_Core_BAO_Setting::MULTISITE_PREFERENCES_NAME => array( |
238 | array('is_enabled', 0), | |
6a488035 TO |
239 | array('uniq_email_per_site', 0), |
240 | array('domain_group_id', 0), | |
241 | array('event_price_set_domain_id', 0), | |
242 | ), | |
9d72cede EM |
243 | CRM_Core_BAO_Setting::DIRECTORY_PREFERENCES_NAME => array( |
244 | array('uploadDir', NULL), | |
6a488035 TO |
245 | array('imageUploadDir', NULL), |
246 | array('customFileUploadDir', NULL), | |
247 | array('customTemplateDir', NULL), | |
248 | array('customPHPPathDir', NULL), | |
249 | array('extensionsDir', NULL), | |
250 | ), | |
9d72cede EM |
251 | CRM_Core_BAO_Setting::URL_PREFERENCES_NAME => array( |
252 | array('userFrameworkResourceURL', NULL), | |
6a488035 TO |
253 | array('imageUploadURL', NULL), |
254 | array('customCSSURL', NULL), | |
255 | ), | |
256 | ); | |
257 | ||
258 | $domainID = CRM_Core_Config::domainID(); | |
259 | $createdDate = date('YmdHis'); | |
260 | ||
261 | $dbSettings = array(); | |
262 | self::retrieveDirectoryAndURLPaths($dbSettings); | |
263 | ||
264 | foreach ($domainColumns as $groupName => $settings) { | |
265 | foreach ($settings as $setting) { | |
266 | ||
9d72cede EM |
267 | if (isset($dbSettings[$groupName][$setting[0]]) && |
268 | !empty($dbSettings[$groupName][$setting[0]]) | |
269 | ) { | |
6a488035 TO |
270 | $setting[1] = $dbSettings[$groupName][$setting[0]]; |
271 | } | |
272 | ||
273 | $value = $setting[1] === NULL ? NULL : serialize($setting[1]); | |
274 | ||
275 | if ($value) { | |
276 | $value = addslashes($value); | |
277 | } | |
278 | ||
279 | $value = $value ? "'{$value}'" : 'null'; | |
280 | $values[] = "( '{$groupName}', '{$setting[0]}', {$value}, {$domainID}, null, 0, '{$createdDate}', null )"; | |
281 | } | |
282 | } | |
283 | $sql = " | |
284 | INSERT INTO civicrm_setting( group_name, name, value, domain_id, contact_id, is_domain, created_date, created_id ) | |
285 | VALUES | |
286 | "; | |
287 | $sql .= implode(",\n", $values); | |
288 | CRM_Core_DAO::executeQuery($sql); | |
289 | } | |
290 | ||
624e56fa | 291 | /** |
c490a46a | 292 | * @param array $params |
624e56fa | 293 | */ |
00be9182 | 294 | public static function retrieveDirectoryAndURLPaths(&$params) { |
6a488035 TO |
295 | |
296 | $sql = " | |
297 | SELECT v.name as valueName, v.value, g.name as optionName | |
298 | FROM civicrm_option_value v, | |
299 | civicrm_option_group g | |
300 | WHERE ( g.name = 'directory_preferences' | |
301 | OR g.name = 'url_preferences' ) | |
302 | AND v.option_group_id = g.id | |
303 | AND v.is_active = 1 | |
304 | "; | |
305 | $dao = CRM_Core_DAO::executeQuery($sql); | |
306 | while ($dao->fetch()) { | |
307 | if (!$dao->value) { | |
308 | continue; | |
309 | } | |
310 | ||
311 | $groupName = CRM_Core_BAO_Setting::DIRECTORY_PREFERENCES_NAME; | |
312 | if ($dao->optionName == 'url_preferences') { | |
313 | $groupName = CRM_Core_BAO_Setting::URL_PREFERENCES_NAME; | |
314 | } | |
315 | $params[$groupName][$dao->valueName] = $dao->value; | |
316 | } | |
317 | } | |
318 | ||
624e56fa EM |
319 | /** |
320 | * @param $rev | |
321 | */ | |
00be9182 | 322 | public function upgrade_4_1_alpha2($rev) { |
9d72cede | 323 | $dao = new CRM_Core_DAO_Setting(); |
6a488035 | 324 | $dao->group_name = 'Directory Preferences'; |
9d72cede | 325 | $dao->name = 'customTemplateDir'; |
6a488035 | 326 | if (!($dao->find(TRUE))) { |
9d72cede | 327 | $dao->domain_id = CRM_Core_Config::domainID(); |
6a488035 | 328 | $dao->created_date = date('YmdHis'); |
9d72cede | 329 | $dao->is_domain = 0; |
6a488035 TO |
330 | $dao->save(); |
331 | } | |
332 | $dao->free(); | |
333 | ||
334 | // Do the regular upgrade | |
408b79bf | 335 | $upgrade = new CRM_Upgrade_Form(); |
6a488035 TO |
336 | $upgrade->processSQL($rev); |
337 | } | |
338 | ||
624e56fa EM |
339 | /** |
340 | * @param $rev | |
341 | */ | |
00be9182 | 342 | public function upgrade_4_1_beta1($rev) { |
6a488035 TO |
343 | //CRM-9311 |
344 | $groupNames = array('directory_preferences', 'url_preferences'); | |
345 | foreach ($groupNames as $groupName) { | |
346 | CRM_Core_OptionGroup::deleteAssoc($groupName); | |
347 | } | |
348 | ||
349 | $domainCols = array( | |
9d72cede | 350 | CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME => array( |
6a488035 TO |
351 | 'contact_ajax_check_similar', |
352 | 'activity_assignee_notification', | |
353 | ), | |
9d72cede | 354 | CRM_Core_BAO_Setting::CAMPAIGN_PREFERENCES_NAME => array( |
6a488035 TO |
355 | 'tag_unconfirmed', |
356 | 'petition_contacts', | |
357 | ), | |
9d72cede | 358 | CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME => array( |
6a488035 TO |
359 | 'enable_cart', |
360 | ), | |
9d72cede | 361 | CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME => array( |
6a488035 TO |
362 | 'profile_double_optin', |
363 | 'profile_add_to_group_double_optin', | |
364 | 'track_civimail_replies', | |
365 | 'civimail_workflow', | |
366 | 'civimail_server_wide_lock', | |
367 | ), | |
9d72cede | 368 | CRM_Core_BAO_Setting::MEMBER_PREFERENCES_NAME => array( |
6a488035 TO |
369 | 'default_renewal_contribution_page', |
370 | ), | |
9d72cede | 371 | CRM_Core_BAO_Setting::MULTISITE_PREFERENCES_NAME => array( |
6a488035 TO |
372 | 'is_enabled', |
373 | 'uniq_email_per_site', | |
374 | 'domain_group_id', | |
375 | 'event_price_set_domain_id', | |
376 | ), | |
9d72cede | 377 | CRM_Core_BAO_Setting::DIRECTORY_PREFERENCES_NAME => array( |
6a488035 TO |
378 | 'uploadDir', |
379 | 'imageUploadDir', | |
380 | 'customFileUploadDir', | |
381 | 'customTemplateDir', | |
382 | 'customPHPPathDir', | |
383 | 'extensionsDir', | |
384 | ), | |
9d72cede | 385 | CRM_Core_BAO_Setting::URL_PREFERENCES_NAME => array( |
6a488035 TO |
386 | 'userFrameworkResourceURL', |
387 | 'imageUploadURL', | |
388 | 'customCSSURL', | |
389 | ), | |
390 | ); | |
391 | ||
392 | $arrGroupNames = array_keys($domainCols); | |
9d72cede EM |
393 | $groupNames = implode("','", $arrGroupNames); |
394 | $arrNames = array(); | |
6a488035 TO |
395 | foreach ($domainCols as $groupName => $names) { |
396 | $arrNames[] = implode("','", $names); | |
397 | } | |
398 | $name = implode("','", $arrNames); | |
399 | ||
400 | $sql = " | |
401 | update civicrm_setting set is_domain = 1 where is_domain = 0 and group_name in ( '{$groupNames}' ) and name in ('{$name}')"; | |
402 | ||
403 | CRM_Core_DAO::executeQuery($sql); | |
404 | ||
405 | $upgrade = new CRM_Upgrade_Form(); | |
406 | $upgrade->assign('addWightForActivity', !(CRM_Core_DAO::checkFieldExists('civicrm_activity', 'weight'))); | |
407 | $upgrade->processSQL($rev); | |
408 | } | |
409 | ||
624e56fa EM |
410 | /** |
411 | * @param $rev | |
412 | */ | |
00be9182 | 413 | public function upgrade_4_1_1($rev) { |
6a488035 TO |
414 | $upgrade = new CRM_Upgrade_Form(); |
415 | $upgrade->assign('addDedupeEmail', !(CRM_Core_DAO::checkFieldExists('civicrm_mailing', 'dedupe_email'))); | |
416 | ||
417 | $sql = "SELECT id FROM civicrm_worldregion LIMIT 1"; | |
418 | $upgrade->assign('worldRegionEmpty', !CRM_Core_DAO::singleValueQuery($sql)); | |
419 | ||
420 | $upgrade->processSQL($rev); | |
421 | } | |
422 | ||
624e56fa EM |
423 | /** |
424 | * @return string | |
425 | */ | |
00be9182 | 426 | public function getTemplateMessage() { |
6a488035 TO |
427 | return "Blah"; |
428 | } | |
96025800 | 429 | |
6a488035 | 430 | } |