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