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