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