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