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