Merge pull request #4875 from civicrm/minor-fix
[civicrm-core.git] / CRM / Core / BAO / ConfigSetting.php
CommitLineData
6a488035
TO
1<?php
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 and the CiviCRM Licensing Exception. |
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 and the CiviCRM Licensing Exception along |
21 | 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 *
31 * @package CRM
06b69b18 32 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
33 * $Id$
34 *
35 */
36
37/**
38 * file contains functions used in civicrm configuration
39 *
40 */
41class CRM_Core_BAO_ConfigSetting {
42
43 /**
100fef9d 44 * Create civicrm settings. This is the same as add but it clears the cache and
b597d0b1 45 * reloads the config object
6a488035 46 *
6a0b768e
TO
47 * @param array $params
48 * Associated array of civicrm variables.
77b97be7 49 *
6a488035
TO
50 * @return null
51 * @static
52 */
00be9182 53 public static function create($params) {
6a488035
TO
54 self::add($params);
55 $cache = CRM_Utils_Cache::singleton();
56 $cache->delete('CRM_Core_Config');
0e04f44e 57 $cache->delete('CRM_Core_Config' . CRM_Core_Config::domainID());
6a488035
TO
58 $config = CRM_Core_Config::singleton(TRUE, TRUE);
59 }
60
61 /**
100fef9d 62 * Add civicrm settings
6a488035 63 *
6a0b768e
TO
64 * @param array $params
65 * Associated array of civicrm variables.
dd244018 66 *
6a488035
TO
67 * @return null
68 * @static
69 */
00be9182 70 public static function add(&$params) {
6a488035
TO
71 self::fixParams($params);
72
73 // also set a template url so js files can use this
74 // CRM-6194
75 $params['civiRelativeURL'] = CRM_Utils_System::url('CIVI_BASE_TEMPLATE');
b597d0b1
DL
76 $params['civiRelativeURL'] =
77 str_replace(
78 'CIVI_BASE_TEMPLATE',
79 '',
4c235182
EM
80 $params['civiRelativeURL']
81 );
6a488035 82
b597d0b1
DL
83 // also add the version number for use by template / js etc
84 $params['civiVersion'] = CRM_Utils_System::version();
85
6a488035
TO
86 $domain = new CRM_Core_DAO_Domain();
87 $domain->id = CRM_Core_Config::domainID();
88 $domain->find(TRUE);
89 if ($domain->config_backend) {
90 $values = unserialize($domain->config_backend);
91 self::formatParams($params, $values);
92 }
93
94 // CRM-6151
95 if (isset($params['localeCustomStrings']) &&
96 is_array($params['localeCustomStrings'])
97 ) {
98 $domain->locale_custom_strings = serialize($params['localeCustomStrings']);
99 }
100
101 // unset any of the variables we read from file that should not be stored in the database
102 // the username and certpath are stored flat with _test and _live
103 // check CRM-1470
104 $skipVars = self::skipVars();
105 foreach ($skipVars as $var) {
106 unset($params[$var]);
107 }
108
109 CRM_Core_BAO_Setting::fixAndStoreDirAndURL($params);
110
111 // also skip all Dir Params, we dont need to store those in the DB!
112 foreach ($params as $name => $val) {
113 if (substr($name, -3) == 'Dir') {
114 unset($params[$name]);
115 }
116 }
117
118 //keep user preferred language upto date, CRM-7746
119 $session = CRM_Core_Session::singleton();
120 $lcMessages = CRM_Utils_Array::value('lcMessages', $params);
121 if ($lcMessages && $session->get('userID')) {
122 $languageLimit = CRM_Utils_Array::value('languageLimit', $params);
123 if (is_array($languageLimit) &&
124 !in_array($lcMessages, array_keys($languageLimit))
125 ) {
126 $lcMessages = $session->get('lcMessages');
127 }
128
129 $ufm = new CRM_Core_DAO_UFMatch();
130 $ufm->contact_id = $session->get('userID');
131 if ($lcMessages && $ufm->find(TRUE)) {
132 $ufm->language = $lcMessages;
133 $ufm->save();
134 $session->set('lcMessages', $lcMessages);
135 $params['lcMessages'] = $lcMessages;
136 }
137 }
138
139 $domain->config_backend = serialize($params);
140 $domain->save();
141 }
142
143 /**
100fef9d 144 * Fix civicrm setting variables
6a488035 145 *
6a0b768e
TO
146 * @param array $params
147 * Associated array of civicrm variables.
dd244018 148 *
6a488035
TO
149 * @return null
150 * @static
151 */
00be9182 152 public static function fixParams(&$params) {
6a488035
TO
153 // in our old civicrm.settings.php we were using ISO code for country and
154 // province limit, now we have changed it to use ids
155
156 $countryIsoCodes = CRM_Core_PseudoConstant::countryIsoCode();
157
158 $specialArray = array('countryLimit', 'provinceLimit');
159
160 foreach ($params as $key => $value) {
161 if (in_array($key, $specialArray) && is_array($value)) {
162 foreach ($value as $k => $val) {
163 if (!is_numeric($val)) {
164 $params[$key][$k] = array_search($val, $countryIsoCodes);
165 }
166 }
167 }
168 elseif ($key == 'defaultContactCountry') {
169 if (!is_numeric($value)) {
170 $params[$key] = array_search($value, $countryIsoCodes);
171 }
172 }
173 }
174 }
175
176 /**
100fef9d 177 * Format the array containing before inserting in db
6a488035 178 *
6a0b768e
TO
179 * @param array $params
180 * Associated array of civicrm variables(submitted).
181 * @param array $values
182 * Associated array of civicrm variables stored in db.
6a488035
TO
183 *
184 * @return null
185 * @static
186 */
00be9182 187 public static function formatParams(&$params, &$values) {
6a488035
TO
188 if (empty($params) ||
189 !is_array($params)
190 ) {
191 $params = $values;
192 }
193 else {
194 foreach ($params as $key => $val) {
195 if (array_key_exists($key, $values)) {
196 unset($values[$key]);
197 }
198 }
199 $params = array_merge($params, $values);
200 }
201 }
202
203 /**
100fef9d 204 * Retrieve the settings values from db
6a488035 205 *
da6b46f4
EM
206 * @param $defaults
207 *
a6c01b45 208 * @return array
6a488035
TO
209 * @static
210 */
00be9182 211 public static function retrieve(&$defaults) {
6a488035
TO
212 $domain = new CRM_Core_DAO_Domain();
213
214 //we are initializing config, really can't use, CRM-7863
215 $urlVar = 'q';
216 if (defined('CIVICRM_UF') && CIVICRM_UF == 'Joomla') {
217 $urlVar = 'task';
218 }
219
220 if (CRM_Core_Config::isUpgradeMode()) {
221 $domain->selectAdd('config_backend');
222 }
223 elseif (CRM_Utils_Array::value($urlVar, $_GET) == 'admin/modules/list/confirm') {
224 $domain->selectAdd('config_backend', 'locales');
225 }
226 else {
227 $domain->selectAdd('config_backend, locales, locale_custom_strings');
228 }
229
230 $domain->id = CRM_Core_Config::domainID();
231 $domain->find(TRUE);
232 if ($domain->config_backend) {
233 $defaults = unserialize($domain->config_backend);
234 if ($defaults === FALSE || !is_array($defaults)) {
235 $defaults = array();
236 return;
237 }
238
239 $skipVars = self::skipVars();
240 foreach ($skipVars as $skip) {
241 if (array_key_exists($skip, $defaults)) {
242 unset($defaults[$skip]);
243 }
244 }
245
6a488035
TO
246 // check if there are any locale strings
247 if ($domain->locale_custom_strings) {
248 $defaults['localeCustomStrings'] = unserialize($domain->locale_custom_strings);
249 }
250 else {
251 $defaults['localeCustomStrings'] = NULL;
252 }
253
254 // are we in a multi-language setup?
255 $multiLang = $domain->locales ? TRUE : FALSE;
256
257 // set the current language
258 $lcMessages = NULL;
259
260 $session = CRM_Core_Session::singleton();
261
262 // on multi-lang sites based on request and civicrm_uf_match
263 if ($multiLang) {
264 $lcMessagesRequest = CRM_Utils_Request::retrieve('lcMessages', 'String', $this);
265 $languageLimit = array();
266 if (array_key_exists('languageLimit', $defaults) && is_array($defaults['languageLimit'])) {
267 $languageLimit = $defaults['languageLimit'];
268 }
269
270 if (in_array($lcMessagesRequest, array_keys($languageLimit))) {
271 $lcMessages = $lcMessagesRequest;
272
273 //CRM-8559, cache navigation do not respect locale if it is changed, so reseting cache.
274 CRM_Core_BAO_Cache::deleteGroup('navigation');
275 }
276 else {
277 $lcMessagesRequest = NULL;
278 }
279
280 if (!$lcMessagesRequest) {
281 $lcMessagesSession = $session->get('lcMessages');
282 if (in_array($lcMessagesSession, array_keys($languageLimit))) {
283 $lcMessages = $lcMessagesSession;
284 }
285 else {
286 $lcMessagesSession = NULL;
287 }
288 }
289
290 if ($lcMessagesRequest) {
291 $ufm = new CRM_Core_DAO_UFMatch();
292 $ufm->contact_id = $session->get('userID');
293 if ($ufm->find(TRUE)) {
294 $ufm->language = $lcMessages;
295 $ufm->save();
296 }
297 $session->set('lcMessages', $lcMessages);
298 }
299
300 if (!$lcMessages and $session->get('userID')) {
301 $ufm = new CRM_Core_DAO_UFMatch();
302 $ufm->contact_id = $session->get('userID');
303 if ($ufm->find(TRUE) &&
304 in_array($ufm->language, array_keys($languageLimit))
305 ) {
306 $lcMessages = $ufm->language;
307 }
308 $session->set('lcMessages', $lcMessages);
309 }
310 }
311 global $dbLocale;
312
313 // try to inherit the language from the hosting CMS
a7488080 314 if (!empty($defaults['inheritLocale'])) {
6a488035
TO
315 // FIXME: On multilanguage installs, CRM_Utils_System::getUFLocale() in many cases returns nothing if $dbLocale is not set
316 $dbLocale = $multiLang ? "_{$defaults['lcMessages']}" : '';
317 $lcMessages = CRM_Utils_System::getUFLocale();
318 if ($domain->locales and !in_array($lcMessages, explode(CRM_Core_DAO::VALUE_SEPARATOR,
4c235182
EM
319 $domain->locales
320 ))
321 ) {
6a488035
TO
322 $lcMessages = NULL;
323 }
324 }
325
5b6ed484 326 if (empty($lcMessages)) {
6b3f6bd5 327 //CRM-11993 - if a single-lang site, use default
5b6ed484 328 $lcMessages = CRM_Utils_Array::value('lcMessages', $defaults);
329 }
6a488035
TO
330
331 // set suffix for table names - use views if more than one language
332 $dbLocale = $multiLang ? "_{$lcMessages}" : '';
333
334 // FIXME: an ugly hack to fix CRM-4041
335 global $tsLocale;
336 $tsLocale = $lcMessages;
337
338 // FIXME: as bad aplace as any to fix CRM-5428
339 // (to be moved to a sane location along with the above)
340 if (function_exists('mb_internal_encoding')) {
341 mb_internal_encoding('UTF-8');
342 }
343 }
344
345 // dont add if its empty
346 if (!empty($defaults)) {
347 // retrieve directory and url preferences also
348 CRM_Core_BAO_Setting::retrieveDirectoryAndURLPreferences($defaults);
3124edb3 349
2efcf0c2 350 // Pickup enabled-components from settings table if found.
4acb1c97
DS
351 $enableComponents = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enable_components', NULL, array());
352 if (!empty($enableComponents)) {
353 $defaults['enableComponents'] = $enableComponents;
2efcf0c2 354
3124edb3
DS
355 $components = CRM_Core_Component::getComponents();
356 $enabledComponentIDs = array();
357 foreach ($defaults['enableComponents'] as $name) {
358 $enabledComponentIDs[] = $components[$name]->componentID;
359 }
360 $defaults['enableComponentIDs'] = $enabledComponentIDs;
361 }
6a488035
TO
362 }
363 }
364
b5c2afd0
EM
365 /**
366 * @return array
367 */
00be9182 368 public static function getConfigSettings() {
6a488035
TO
369 $config = CRM_Core_Config::singleton();
370
371 $url = $dir = $siteName = $siteRoot = NULL;
372 if ($config->userFramework == 'Joomla') {
e51744f5
DL
373 $url = preg_replace(
374 '|administrator/components/com_civicrm/civicrm/|',
6a488035
TO
375 '',
376 $config->userFrameworkResourceURL
377 );
378
379 // lets use imageUploadDir since we dont mess around with its values
380 // in the config object, lets kep it a bit generic since folks
381 // might have different values etc
4c235182
EM
382
383 //CRM-15365 - Fix preg_replace to handle backslash for Windows File Paths
384 if (DIRECTORY_SEPARATOR == '\\') {
385 $dir = preg_replace(
386 '|civicrm[/\\\\]templates_c[/\\\\].*$|',
387 '',
388 $config->templateCompileDir
37b395e8 389 );
4c235182
EM
390 }
391 else {
392 $dir = preg_replace(
393 '|civicrm/templates_c/.*$|',
394 '',
395 $config->templateCompileDir
37b395e8 396 );
4c235182
EM
397 }
398
e51744f5
DL
399 $siteRoot = preg_replace(
400 '|/media/civicrm/.*$|',
401 '',
402 $config->imageUploadDir
403 );
404 }
4c9b6178 405 elseif ($config->userFramework == 'WordPress') {
e51744f5
DL
406 $url = preg_replace(
407 '|wp-content/plugins/civicrm/civicrm/|',
408 '',
409 $config->userFrameworkResourceURL
410 );
411
412 // lets use imageUploadDir since we dont mess around with its values
413 // in the config object, lets kep it a bit generic since folks
414 // might have different values etc
4c235182
EM
415
416 //CRM-15365 - Fix preg_replace to handle backslash for Windows File Paths
417 if (DIRECTORY_SEPARATOR == '\\') {
418 $dir = preg_replace(
419 '|civicrm[/\\\\]templates_c[/\\\\].*$|',
420 '',
421 $config->templateCompileDir
37b395e8 422 );
4c235182
EM
423 }
424 else {
425 $dir = preg_replace(
426 '|civicrm/templates_c/.*$|',
427 '',
428 $config->templateCompileDir
37b395e8 429 );
4c235182
EM
430 }
431
e51744f5
DL
432 $siteRoot = preg_replace(
433 '|/wp-content/plugins/files/civicrm/.*$|',
6a488035
TO
434 '',
435 $config->imageUploadDir
436 );
437 }
438 else {
e51744f5
DL
439 $url = preg_replace(
440 '|sites/[\w\.\-\_]+/modules/civicrm/|',
6a488035
TO
441 '',
442 $config->userFrameworkResourceURL
443 );
444
445 // lets use imageUploadDir since we dont mess around with its values
446 // in the config object, lets kep it a bit generic since folks
447 // might have different values etc
4c235182
EM
448
449 //CRM-15365 - Fix preg_replace to handle backslash for Windows File Paths
450 if (DIRECTORY_SEPARATOR == '\\') {
451 $dir = preg_replace(
452 '|[/\\\\]files[/\\\\]civicrm[/\\\\].*$|',
453 '\\\\files\\\\',
454 $config->imageUploadDir
37b395e8 455 );
4c235182
EM
456 }
457 else {
458 $dir = preg_replace(
459 '|/files/civicrm/.*$|',
460 '/files/',
461 $config->imageUploadDir
37b395e8 462 );
4c235182
EM
463 }
464
6a488035 465 $matches = array();
e51744f5 466 if (preg_match(
4c235182
EM
467 '|/sites/([\w\.\-\_]+)/|',
468 $config->imageUploadDir,
469 $matches
470 )) {
6a488035
TO
471 $siteName = $matches[1];
472 if ($siteName) {
473 $siteName = "/sites/$siteName/";
474 $siteNamePos = strpos($dir, $siteName);
475 if ($siteNamePos !== FALSE) {
476 $siteRoot = substr($dir, 0, $siteNamePos);
477 }
478 }
479 }
480 }
481
6a488035
TO
482 return array($url, $dir, $siteName, $siteRoot);
483 }
484
4c235182
EM
485 /**
486 * Return likely default settings
a6c01b45
CW
487 * @return array
488 * site settings
4c235182
EM
489 * -$url,
490 * - $dir Base Directory
491 * - $siteName
492 * - $siteRoot
493 */
00be9182 494 public static function getBestGuessSettings() {
6a488035 495 $config = CRM_Core_Config::singleton();
4c235182
EM
496
497 //CRM-15365 - Fix preg_replace to handle backslash for Windows File Paths
498 if (DIRECTORY_SEPARATOR == '\\') {
499 $needle = 'civicrm[/\\\\]templates_c[/\\\\].*$';
500 }
501 else {
502 $needle = 'civicrm/templates_c/.*$';
503 }
504
505 $dir = preg_replace(
37b395e8 506 "|$needle|",
6a488035
TO
507 '',
508 $config->templateCompileDir
509 );
510
9977c6f5 511 list($url, $siteName, $siteRoot) = $config->userSystem->getDefaultSiteSettings($dir);
6a488035
TO
512 return array($url, $dir, $siteName, $siteRoot);
513 }
514
b5c2afd0
EM
515 /**
516 * @param array $defaultValues
517 *
518 * @return string
519 * @throws Exception
520 */
00be9182 521 public static function doSiteMove($defaultValues = array()) {
6a488035
TO
522 $moveStatus = ts('Beginning site move process...') . '<br />';
523 // get the current and guessed values
524 list($oldURL, $oldDir, $oldSiteName, $oldSiteRoot) = self::getConfigSettings();
525 list($newURL, $newDir, $newSiteName, $newSiteRoot) = self::getBestGuessSettings();
526
527
528 // retrieve these values from the argument list
529 $variables = array('URL', 'Dir', 'SiteName', 'SiteRoot', 'Val_1', 'Val_2', 'Val_3');
530 $states = array('old', 'new');
531 foreach ($variables as $varSuffix) {
532 foreach ($states as $state) {
533 $var = "{$state}{$varSuffix}";
534 if (!isset($$var)) {
535 if (isset($defaultValues[$var])) {
536 $$var = $defaultValues[$var];
537 }
538 else {
539 $$var = NULL;
540 }
541 }
542 $$var = CRM_Utils_Request::retrieve($var,
543 'String',
544 CRM_Core_DAO::$_nullArray,
545 FALSE,
546 $$var,
547 'REQUEST'
548 );
549 }
550 }
551
552 $from = $to = array();
553 foreach ($variables as $varSuffix) {
554 $oldVar = "old{$varSuffix}";
555 $newVar = "new{$varSuffix}";
556 //skip it if either is empty or both are exactly the same
557 if ($$oldVar &&
558 $$newVar &&
559 $$oldVar != $$newVar
560 ) {
561 $from[] = $$oldVar;
562 $to[] = $$newVar;
563 }
564 }
565
566 $sql = "
567SELECT config_backend
568FROM civicrm_domain
569WHERE id = %1
570";
571 $params = array(1 => array(CRM_Core_Config::domainID(), 'Integer'));
572 $configBackend = CRM_Core_DAO::singleValueQuery($sql, $params);
573 if (!$configBackend) {
574 CRM_Core_Error::fatal(ts('Returning early due to unexpected error - civicrm_domain.config_backend column value is NULL. Try visiting CiviCRM Home page.'));
575 }
576 $configBackend = unserialize($configBackend);
577
578 $configBackend = str_replace($from,
579 $to,
580 $configBackend
581 );
582
583 $configBackend = serialize($configBackend);
584 $sql = "
585UPDATE civicrm_domain
586SET config_backend = %2
587WHERE id = %1
588";
589 $params[2] = array($configBackend, 'String');
590 CRM_Core_DAO::executeQuery($sql, $params);
591
592 // Apply the changes to civicrm_option_values
593 $optionGroups = array('url_preferences', 'directory_preferences');
594 foreach ($optionGroups as $option) {
595 foreach ($variables as $varSuffix) {
596 $oldVar = "old{$varSuffix}";
597 $newVar = "new{$varSuffix}";
598
599 $from = $$oldVar;
600 $to = $$newVar;
601
602 if ($from && $to && $from != $to) {
603 $sql = '
604UPDATE civicrm_option_value
605SET value = REPLACE(value, %1, %2)
606WHERE option_group_id = (
607 SELECT id
608 FROM civicrm_option_group
609 WHERE name = %3 )
610';
4c235182
EM
611 $params = array(
612 1 => array($from, 'String'),
6a488035
TO
613 2 => array($to, 'String'),
614 3 => array($option, 'String'),
615 );
616 CRM_Core_DAO::executeQuery($sql, $params);
617 }
618 }
619 }
620
4c235182
EM
621 $moveStatus .=
622 ts('Directory and Resource URLs have been updated in the moved database to reflect current site location.') .
623 '<br />';
6a488035
TO
624
625 $config = CRM_Core_Config::singleton();
626
627 // clear the template_c and upload directory also
628 $config->cleanup(3, TRUE);
629 $moveStatus .= ts('Template cache and upload directory have been cleared.') . '<br />';
630
631 // clear all caches
632 CRM_Core_Config::clearDBCache();
633 $moveStatus .= ts('Database cache tables cleared.') . '<br />';
634
635 $resetSessionTable = CRM_Utils_Request::retrieve('resetSessionTable',
636 'Boolean',
637 CRM_Core_DAO::$_nullArray,
638 FALSE,
639 FALSE,
640 'REQUEST'
641 );
642 if ($config->userSystem->is_drupal &&
643 $resetSessionTable
644 ) {
645 db_query("DELETE FROM {sessions} WHERE 1");
646 $moveStatus .= ts('Drupal session table cleared.') . '<br />';
647 }
648 else {
649 $session = CRM_Core_Session::singleton();
650 $session->reset(2);
651 $moveStatus .= ts('Session has been reset.') . '<br />';
652 }
653
654 return $moveStatus;
655 }
656
657 /**
100fef9d 658 * Takes a componentName and enables it in the config
6a488035
TO
659 * Primarily used during unit testing
660 *
6a0b768e
TO
661 * @param string $componentName
662 * Name of the component to be enabled, needs to be valid.
6a488035 663 *
a6c01b45
CW
664 * @return boolean
665 * true if valid component name and enabling succeeds, else false
6a488035
TO
666 * @static
667 */
00be9182 668 public static function enableComponent($componentName) {
6a488035
TO
669 $config = CRM_Core_Config::singleton();
670 if (in_array($componentName, $config->enableComponents)) {
671 // component is already enabled
672 return TRUE;
673 }
6a488035
TO
674
675 // return if component does not exist
b086633a 676 if (!array_key_exists($componentName, CRM_Core_Component::getComponents())) {
6a488035
TO
677 return FALSE;
678 }
679
3124edb3 680 // get enabled-components from DB and add to the list
2efcf0c2 681 $enabledComponents =
3124edb3
DS
682 CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enable_components', NULL, array());
683 $enabledComponents[] = $componentName;
6a488035 684
b086633a
TO
685 self::setEnabledComponents($enabledComponents);
686
687 return TRUE;
688 }
689
00be9182 690 public static function disableComponent($componentName) {
b086633a 691 $config = CRM_Core_Config::singleton();
4c235182
EM
692 if (!in_array($componentName, $config->enableComponents) ||
693 !array_key_exists($componentName, CRM_Core_Component::getComponents())
694 ) {
b086633a
TO
695 // post-condition satisified
696 return TRUE;
697 }
698
699 // get enabled-components from DB and add to the list
700 $enabledComponents =
701 CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enable_components', NULL, array());
702 $enabledComponents = array_diff($enabledComponents, array($componentName));
703
704 self::setEnabledComponents($enabledComponents);
705
706 return TRUE;
707 }
708
709 public static function setEnabledComponents($enabledComponents) {
710 $config = CRM_Core_Config::singleton();
711 $components = CRM_Core_Component::getComponents();
712
3124edb3
DS
713 $enabledComponentIDs = array();
714 foreach ($enabledComponents as $name) {
715 $enabledComponentIDs[] = $components[$name]->componentID;
6a488035 716 }
6a488035
TO
717
718 // fix the config object
3124edb3
DS
719 $config->enableComponents = $enabledComponents;
720 $config->enableComponentIDs = $enabledComponentIDs;
6a488035
TO
721
722 // also force reset of component array
723 CRM_Core_Component::getEnabledComponents(TRUE);
724
3124edb3
DS
725 // update DB
726 CRM_Core_BAO_Setting::setItem($enabledComponents,
b086633a 727 CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enable_components');
6a488035
TO
728 }
729
b5c2afd0
EM
730 /**
731 * @return array
732 */
00be9182 733 public static function skipVars() {
6a488035 734 return array(
4c235182
EM
735 'dsn',
736 'templateCompileDir',
6a488035
TO
737 'userFrameworkDSN',
738 'userFramework',
4c235182
EM
739 'userFrameworkBaseURL',
740 'userFrameworkClass',
741 'userHookClass',
742 'userPermissionClass',
743 'userFrameworkURLVar',
744 'userFrameworkVersion',
745 'newBaseURL',
746 'newBaseDir',
747 'newSiteName',
748 'configAndLogDir',
749 'qfKey',
750 'gettextResourceDir',
751 'cleanURL',
752 'locale_custom_strings',
753 'localeCustomStrings',
6a488035
TO
754 'autocompleteContactSearch',
755 'autocompleteContactReference',
756 'checksumTimeout',
757 );
758 }
759}