3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 * Config handles all the run time configuration changes that the system needs to deal with.
30 * Typically we'll have different values for a user's sandbox, a qa sandbox and a production area.
31 * The default values in general, should reflect production values (minimizes chances of screwing up)
34 * @copyright CiviCRM LLC (c) 2004-2013
39 require_once 'Log.php';
40 require_once 'Mail.php';
42 require_once 'api/api.php';
43 class CRM_Core_Config
extends CRM_Core_Config_Variables
{
45 /// BASE SYSTEM PROPERTIES (CIVICRM.SETTINGS.PHP)
49 * the dsn of the database connection
55 * the name of user framework
58 public $userFramework = 'Drupal';
61 * the name of user framework url variable name
64 public $userFrameworkURLVar = 'q';
67 * the dsn of the database connection for user framework
70 public $userFrameworkDSN = NULL;
73 * The connector module for the CMS/UF
74 * @todo Introduce an interface.
76 * @var CRM_Utils_System_Base
78 public $userSystem = NULL;
81 * The root directory where Smarty should store
85 public $templateCompileDir = './templates_c/en_US/';
87 public $configAndLogDir = NULL;
89 // END: BASE SYSTEM PROPERTIES (CIVICRM.SETTINGS.PHP)
92 /// BEGIN HELPER CLASS PROPERTIES
96 * are we initialized and in a proper state
99 public $initialized = 0;
104 public $customPHPPathDir;
107 * the factory class used to instantiate our DB objects
110 private $DAOFactoryClass = 'CRM_Contact_DAO_Factory';
113 * The handle to the log that we are using
116 private static $_log = NULL;
119 * the handle on the mail handler that we are using
122 public static $_mail = NULL;
125 * We only need one instance of this object. So we use the singleton
126 * pattern and cache the instance in this variable
130 private static $_singleton = NULL;
133 * component registry object (of CRM_Core_Component type)
135 public $componentRegistry = NULL;
138 /// END HELPER CLASS PROPERTIES
142 /// RUNTIME SET CLASS PROPERTIES
146 * to determine wether the call is from cms or civicrm
148 public $inCiviCRM = FALSE;
151 /// END: RUNTIME SET CLASS PROPERTIES
155 * Define recaptcha key
158 public $recaptchaPublicKey;
161 * The constructor. Sets domain id if defined, otherwise assumes
162 * single instance installation.
167 private function __construct() {
171 * Singleton function used to manage this object.
173 * @param $loadFromDB boolean whether to load from the database
174 * @param $force boolean whether to force a reconstruction
176 * @return CRM_Core_Config
179 static function &singleton($loadFromDB = TRUE, $force = FALSE) {
180 if (self
::$_singleton === NULL ||
$force) {
181 // goto a simple error handler
182 $GLOBALS['_PEAR_default_error_mode'] = PEAR_ERROR_CALLBACK
;
183 $GLOBALS['_PEAR_default_error_options'] = array('CRM_Core_Error', 'simpleHandler');
185 // lets ensure we set E_DEPRECATED to minimize errors
187 if (defined('E_DEPRECATED')) {
188 error_reporting(error_reporting() & ~E_DEPRECATED
);
191 // first, attempt to get configuration object from cache
192 $cache = CRM_Utils_Cache
::singleton();
193 self
::$_singleton = $cache->get('CRM_Core_Config' . CRM_Core_Config
::domainID());
194 // if not in cache, fire off config construction
195 if (!self
::$_singleton) {
196 self
::$_singleton = new CRM_Core_Config
;
197 self
::$_singleton->_initialize($loadFromDB);
199 //initialize variables. for gencode we cannot load from the
200 //db since the db might not be initialized
202 // initialize stuff from the settings file
203 self
::$_singleton->setCoreVariables();
205 self
::$_singleton->_initVariables();
207 // I dont think we need to do this twice
208 // however just keeping this commented for now in 4.4
209 // in case we hit any issues - CRM-13064
210 // We can safely delete this once we release 4.4.4
211 // self::$_singleton->setCoreVariables();
213 $cache->set('CRM_Core_Config' . CRM_Core_Config
::domainID(), self
::$_singleton);
216 // we retrieve the object from memcache, so we now initialize the objects
217 self
::$_singleton->_initialize($loadFromDB);
219 // CRM-9803, NYSS-4822
220 // this causes various settings to be reset and hence we should
221 // only use the config object that we retrived from memcache
224 self
::$_singleton->initialized
= 1;
226 if (isset(self
::$_singleton->customPHPPathDir
) &&
227 self
::$_singleton->customPHPPathDir
229 $include_path = self
::$_singleton->customPHPPathDir
. PATH_SEPARATOR
. get_include_path();
230 set_include_path($include_path);
233 // set the callback at the very very end, to avoid an infinite loop
234 // set the error callback
235 CRM_Core_Error
::setCallback();
237 // call the hook so other modules can add to the config
238 // again doing this at the very very end
239 CRM_Utils_Hook
::config(self
::$_singleton);
241 // make sure session is always initialised
242 $session = CRM_Core_Session
::singleton();
244 // for logging purposes, pass the userID to the db
245 $userID = $session->get('userID');
247 CRM_Core_DAO
::executeQuery('SET @civicrm_user_id = %1',
248 array(1 => array($userID, 'Integer'))
252 // initialize authentication source
253 self
::$_singleton->initAuthSrc();
255 return self
::$_singleton;
259 private function _setUserFrameworkConfig($userFramework) {
261 $this->userFrameworkClass
= 'CRM_Utils_System_' . $userFramework;
262 $this->userHookClass
= 'CRM_Utils_Hook_' . $userFramework;
263 $userPermissionClass = 'CRM_Core_Permission_' . $userFramework;
264 $this->userPermissionClass
= new $userPermissionClass();
266 $class = $this->userFrameworkClass
;
267 // redundant with _initVariables
268 $userSystem = $this->userSystem
= new $class();
270 if ($userFramework == 'Joomla') {
271 $this->userFrameworkURLVar
= 'task';
274 if (defined('CIVICRM_UF_BASEURL')) {
275 $this->userFrameworkBaseURL
= CRM_Utils_File
::addTrailingSlash(CIVICRM_UF_BASEURL
, '/');
277 //format url for language negotiation, CRM-7803
278 $this->userFrameworkBaseURL
= CRM_Utils_System
::languageNegotiationURL($this->userFrameworkBaseURL
);
280 if (CRM_Utils_System
::isSSL()) {
281 $this->userFrameworkBaseURL
= str_replace('http://', 'https://',
282 $this->userFrameworkBaseURL
287 if (defined('CIVICRM_UF_DSN')) {
288 $this->userFrameworkDSN
= CIVICRM_UF_DSN
;
291 // this is dynamically figured out in the civicrm.settings.php file
292 if (defined('CIVICRM_CLEANURL')) {
293 $this->cleanURL
= CIVICRM_CLEANURL
;
299 $this->userFrameworkVersion
= $userSystem->getVersion();
301 if ($userFramework == 'Joomla') {
303 $dbprefix = $mainframe ?
$mainframe->getCfg('dbprefix') : 'jos_';
304 $this->userFrameworkUsersTableName
= $dbprefix . 'users';
306 elseif ($userFramework == 'WordPress') {
308 $dbprefix = $wpdb ?
$wpdb->prefix
: '';
309 $this->userFrameworkUsersTableName
= $dbprefix . 'users';
314 * Initializes the entire application.
315 * Reads constants defined in civicrm.settings.php and
316 * stores them in config properties.
321 private function _initialize($loadFromDB = TRUE) {
323 // following variables should be set in CiviCRM settings and
324 // as crucial ones, are defined upon initialisation
325 // instead of in CRM_Core_Config_Defaults
326 if (defined('CIVICRM_DSN')) {
327 $this->dsn
= CIVICRM_DSN
;
329 elseif ($loadFromDB) {
330 // bypass when calling from gencode
331 echo 'You need to define CIVICRM_DSN in civicrm.settings.php';
335 if (defined('CIVICRM_TEMPLATE_COMPILEDIR')) {
336 $this->templateCompileDir
= CRM_Utils_File
::addTrailingSlash(CIVICRM_TEMPLATE_COMPILEDIR
);
338 // also make sure we create the config directory within this directory
339 // the below statement will create both the templates directory and the config and log directory
340 $this->configAndLogDir
=
341 CRM_Utils_File
::baseFilePath($this->templateCompileDir
) .
342 'ConfigAndLog' . DIRECTORY_SEPARATOR
;
343 CRM_Utils_File
::createDir($this->configAndLogDir
);
344 CRM_Utils_File
::restrictAccess($this->configAndLogDir
);
346 // we're automatically prefixing compiled templates directories with country/language code
348 if (!empty($tsLocale)) {
349 $this->templateCompileDir
.= CRM_Utils_File
::addTrailingSlash($tsLocale);
351 elseif (!empty($this->lcMessages
)) {
352 $this->templateCompileDir
.= CRM_Utils_File
::addTrailingSlash($this->lcMessages
);
355 CRM_Utils_File
::createDir($this->templateCompileDir
);
356 CRM_Utils_File
::restrictAccess($this->templateCompileDir
);
358 elseif ($loadFromDB) {
359 echo 'You need to define CIVICRM_TEMPLATE_COMPILEDIR in civicrm.settings.php';
365 if (defined('CIVICRM_UF')) {
366 $this->userFramework
= CIVICRM_UF
;
367 $this->_setUserFrameworkConfig($this->userFramework
);
370 echo 'You need to define CIVICRM_UF in civicrm.settings.php';
374 // also initialize the logger
375 self
::$_log = Log
::singleton('display');
377 // initialize component registry early to avoid "race"
378 // between CRM_Core_Config and CRM_Core_Component (they
380 $this->componentRegistry
= new CRM_Core_Component();
384 * initialize the DataObject framework
389 private function _initDAO() {
390 CRM_Core_DAO
::init($this->dsn
);
392 $factoryClass = $this->DAOFactoryClass
;
393 require_once str_replace('_', DIRECTORY_SEPARATOR
, $factoryClass) . '.php';
394 CRM_Core_DAO
::setFactory(new $factoryClass());
395 if (CRM_Utils_Constant
::value('CIVICRM_MYSQL_STRICT', CRM_Utils_System
::isDevelopment())) {
396 CRM_Core_DAO
::executeQuery('SET SESSION sql_mode = STRICT_TRANS_TABLES');
401 * returns the singleton logger for the application
408 static public function &getLog() {
409 if (!isset(self
::$_log)) {
410 self
::$_log = Log
::singleton('display');
417 * initialize the config variables
422 private function _initVariables() {
423 // retrieve serialised settings
424 $variables = array();
425 CRM_Core_BAO_ConfigSetting
::retrieve($variables);
427 // if settings are not available, go down the full path
428 if (empty($variables)) {
429 // Step 1. get system variables with their hardcoded defaults
430 $variables = get_object_vars($this);
432 // Step 2. get default values (with settings file overrides if
433 // available - handled in CRM_Core_Config_Defaults)
434 CRM_Core_Config_Defaults
::setValues($variables);
436 // retrieve directory and url preferences also
437 CRM_Core_BAO_Setting
::retrieveDirectoryAndURLPreferences($variables);
439 // add component specific settings
440 $this->componentRegistry
->addConfig($this);
442 // serialise settings
443 $settings = $variables;
444 CRM_Core_BAO_ConfigSetting
::add($settings);
447 $urlArray = array('userFrameworkResourceURL', 'imageUploadURL');
448 $dirArray = array('uploadDir', 'customFileUploadDir');
450 foreach ($variables as $key => $value) {
451 if (in_array($key, $urlArray)) {
452 $value = CRM_Utils_File
::addTrailingSlash($value, '/');
454 elseif (in_array($key, $dirArray)) {
456 $value = CRM_Utils_File
::addTrailingSlash($value);
458 if (empty($value) ||
(CRM_Utils_File
::createDir($value, FALSE) === FALSE)) {
459 // seems like we could not create the directories
460 // settings might have changed, lets suppress a message for now
461 // so we can make some more progress and let the user fix their settings
462 // for now we assign it to a know value
464 $value = $this->templateCompileDir
;
465 $url = CRM_Utils_System
::url('civicrm/admin/setting/path', 'reset=1');
466 CRM_Core_Session
::setStatus(ts('%1 has an incorrect directory path. Please go to the <a href="%2">path setting page</a> and correct it.', array(
469 )), ts('Check Settings'), 'alert');
472 elseif ($key == 'lcMessages') {
473 // reset the templateCompileDir to locale-specific and make sure it exists
474 if (substr($this->templateCompileDir
, -1 * strlen($value) - 1, -1) != $value) {
475 $this->templateCompileDir
.= CRM_Utils_File
::addTrailingSlash($value);
476 CRM_Utils_File
::createDir($this->templateCompileDir
);
477 CRM_Utils_File
::restrictAccess($this->templateCompileDir
);
481 $this->$key = $value;
484 if ($this->userFrameworkResourceURL
) {
485 // we need to do this here so all blocks also load from an ssl server
486 if (CRM_Utils_System
::isSSL()) {
487 CRM_Utils_System
::mapConfigToSSL();
489 $rrb = parse_url($this->userFrameworkResourceURL
);
490 // dont use absolute path if resources are stored on a different server
492 $this->resourceBase
= $this->userFrameworkResourceURL
;
493 if (isset($_SERVER['HTTP_HOST']) &&
496 $this->resourceBase
= ($rrb['host'] == $_SERVER['HTTP_HOST']) ?
$rrb['path'] : $this->userFrameworkResourceURL
;
500 if (!$this->customFileUploadDir
) {
501 $this->customFileUploadDir
= $this->uploadDir
;
504 if ($this->geoProvider
) {
505 $this->geocodeMethod
= 'CRM_Utils_Geocode_' . $this->geoProvider
;
507 elseif ($this->mapProvider
) {
508 $this->geocodeMethod
= 'CRM_Utils_Geocode_' . $this->mapProvider
;
511 require_once (str_replace('_', DIRECTORY_SEPARATOR
, $this->userFrameworkClass
) . '.php');
512 $class = $this->userFrameworkClass
;
513 // redundant with _setUserFrameworkConfig
514 $this->userSystem
= new $class();
518 * Retrieve a mailer to send any mail from the application
520 * @param boolean $persist open a persistent smtp connection, should speed up mailings
524 static function &getMailer($persist = FALSE) {
525 if (!isset(self
::$_mail)) {
526 $mailingInfo = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::MAILING_PREFERENCES_NAME
,
530 if ($mailingInfo['outBound_option'] == CRM_Mailing_Config
::OUTBOUND_OPTION_REDIRECT_TO_DB ||
531 (defined('CIVICRM_MAILER_SPOOL') && CIVICRM_MAILER_SPOOL
)
533 self
::$_mail = self
::_createMailer('CRM_Mailing_BAO_Spool', array());
535 elseif ($mailingInfo['outBound_option'] == CRM_Mailing_Config
::OUTBOUND_OPTION_SMTP
) {
536 if ($mailingInfo['smtpServer'] == '' ||
!$mailingInfo['smtpServer']) {
537 CRM_Core_Error
::debug_log_message(ts('There is no valid smtp server setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the SMTP Server.', array(1 => CRM_Utils_System
::url('civicrm/admin/setting/smtp', 'reset=1'))));
538 CRM_Core_Error
::fatal(ts('There is no valid smtp server setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the SMTP Server.', array(1 => CRM_Utils_System
::url('civicrm/admin/setting/smtp', 'reset=1'))));
541 $params['host'] = $mailingInfo['smtpServer'] ?
$mailingInfo['smtpServer'] : 'localhost';
542 $params['port'] = $mailingInfo['smtpPort'] ?
$mailingInfo['smtpPort'] : 25;
544 if ($mailingInfo['smtpAuth']) {
545 $params['username'] = $mailingInfo['smtpUsername'];
546 $params['password'] = CRM_Utils_Crypt
::decrypt($mailingInfo['smtpPassword']);
547 $params['auth'] = TRUE;
550 $params['auth'] = FALSE;
553 // set the localhost value, CRM-3153
554 $params['localhost'] = CRM_Utils_Array
::value('SERVER_NAME', $_SERVER, 'localhost');
556 // also set the timeout value, lets set it to 30 seconds
558 $params['timeout'] = 30;
561 $params['persist'] = $persist;
563 self
::$_mail = self
::_createMailer('smtp', $params);
565 elseif ($mailingInfo['outBound_option'] == CRM_Mailing_Config
::OUTBOUND_OPTION_SENDMAIL
) {
566 if ($mailingInfo['sendmail_path'] == '' ||
567 !$mailingInfo['sendmail_path']
569 CRM_Core_Error
::debug_log_message(ts('There is no valid sendmail path setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the sendmail server.', array(1 => CRM_Utils_System
::url('civicrm/admin/setting/smtp', 'reset=1'))));
570 CRM_Core_Error
::fatal(ts('There is no valid sendmail path setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the sendmail server.', array(1 => CRM_Utils_System
::url('civicrm/admin/setting/smtp', 'reset=1'))));
572 $params['sendmail_path'] = $mailingInfo['sendmail_path'];
573 $params['sendmail_args'] = $mailingInfo['sendmail_args'];
575 self
::$_mail = self
::_createMailer('sendmail', $params);
577 elseif ($mailingInfo['outBound_option'] == CRM_Mailing_Config
::OUTBOUND_OPTION_MAIL
) {
578 self
::$_mail = self
::_createMailer('mail', array());
580 elseif ($mailingInfo['outBound_option'] == CRM_Mailing_Config
::OUTBOUND_OPTION_MOCK
) {
581 self
::$_mail = self
::_createMailer('mock', array());
583 elseif ($mailingInfo['outBound_option'] == CRM_Mailing_Config
::OUTBOUND_OPTION_DISABLED
) {
584 CRM_Core_Error
::debug_log_message(ts('Outbound mail has been disabled. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the OutBound Email.', array(1 => CRM_Utils_System
::url('civicrm/admin/setting/smtp', 'reset=1'))));
585 CRM_Core_Session
::setStatus(ts('Outbound mail has been disabled. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the OutBound Email.', array(1 => CRM_Utils_System
::url('civicrm/admin/setting/smtp', 'reset=1'))));
588 CRM_Core_Error
::debug_log_message(ts('There is no valid SMTP server Setting Or SendMail path setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the OutBound Email.', array(1 => CRM_Utils_System
::url('civicrm/admin/setting/smtp', 'reset=1'))));
589 CRM_Core_Session
::setStatus(ts('There is no valid SMTP server Setting Or sendMail path setting. Click <a href=\'%1\'>Administer >> System Setting >> Outbound Email</a> to set the OutBound Email.', array(1 => CRM_Utils_System
::url('civicrm/admin/setting/smtp', 'reset=1'))));
590 CRM_Core_Error
::debug_var('mailing_info', $mailingInfo);
597 * Create a new instance of a PEAR Mail driver
599 * @param string $driver 'CRM_Mailing_BAO_Spool' or a name suitable for Mail::factory()
600 * @param array $params
601 * @return Mail (More specifically, a class which implements the "send()" function)
603 public static function _createMailer($driver, $params) {
604 if ($driver == 'CRM_Mailing_BAO_Spool') {
605 $mailer = new CRM_Mailing_BAO_Spool($params);
608 $mailer = Mail
::factory($driver, $params);
610 CRM_Utils_Hook
::alterMail($mailer, $driver, $params);
615 * delete the web server writable directories
617 * @param int $value 1 - clean templates_c, 2 - clean upload, 3 - clean both
623 public function cleanup($value, $rmdir = TRUE) {
624 $value = (int ) $value;
628 CRM_Utils_File
::cleanDir($this->templateCompileDir
, $rmdir);
629 CRM_Utils_File
::createDir($this->templateCompileDir
);
633 CRM_Utils_File
::cleanDir($this->uploadDir
);
634 CRM_Utils_File
::createDir($this->uploadDir
);
637 // Whether we delete/create or simply preserve directories, we should
638 // certainly make sure the restrictions are enforced.
639 foreach (array($this->templateCompileDir
, $this->uploadDir
, $this->configAndLogDir
) as $dir) {
640 if ($dir && is_dir($dir)) {
641 CRM_Utils_File
::restrictAccess($dir);
647 * verify that the needed parameters are not null in the config
649 * @param CRM_Core_Config (reference ) the system config object
650 * @param array (reference ) the parameters that need a value
656 static function check(&$config, &$required) {
657 foreach ($required as $name) {
658 if (CRM_Utils_System
::isNull($config->$name)) {
666 * reset the serialized array and recompute
670 $query = "UPDATE civicrm_domain SET config_backend = null";
671 CRM_Core_DAO
::executeQuery($query);
674 // This method should initialize auth sources
675 function initAuthSrc() {
676 $session = CRM_Core_Session
::singleton();
677 if ($session->get('userID') && !$session->get('authSrc')) {
678 $session->set('authSrc', CRM_Core_Permission
::AUTH_SRC_LOGIN
);
682 CRM_Contact_BAO_Contact_Permission
::initChecksumAuthSrc();
686 * one function to get domain ID
688 static function domainID($domainID = NULL, $reset = FALSE) {
693 if ($reset ||
empty($domain)) {
694 $domain = defined('CIVICRM_DOMAIN_ID') ? CIVICRM_DOMAIN_ID
: 1;
701 * do general cleanup of caches, temp directories and temp tables
704 function cleanupCaches($sessionReset = TRUE) {
705 // cleanup templates_c directory
706 $this->cleanup(1, FALSE);
709 self
::clearDBCache();
712 $session = CRM_Core_Session
::singleton();
718 * Do general cleanup of module permissions.
720 function cleanupPermissions() {
721 $module_files = CRM_Extension_System
::singleton()->getMapper()->getActiveModuleFiles();
722 if ($this->userPermissionClass
->isModulePermissionSupported()) {
723 // Can store permissions -- so do it!
724 $this->userPermissionClass
->upgradePermissions(
725 CRM_Core_Permission
::basicPermissions()
728 // Cannot store permissions -- warn if any modules require them
729 $modules_with_perms = array();
730 foreach ($module_files as $module_file) {
731 $perms = $this->userPermissionClass
->getModulePermissions($module_file['prefix']);
732 if (!empty($perms)) {
733 $modules_with_perms[] = $module_file['prefix'];
736 if (!empty($modules_with_perms)) {
737 CRM_Core_Session
::setStatus(
738 ts('Some modules define permissions, but the CMS cannot store them: %1', array(1 => implode(', ', $modules_with_perms))),
739 ts('Permission Error'),
747 * Flush information about loaded modules
749 function clearModuleList() {
750 CRM_Extension_System
::singleton()->getCache()->flush();
751 CRM_Utils_Hook
::singleton(TRUE);
752 CRM_Core_PseudoConstant
::getModuleExtensions(TRUE);
753 CRM_Core_Module
::getAll(TRUE);
759 public static function clearDBCache() {
761 'TRUNCATE TABLE civicrm_acl_cache',
762 'TRUNCATE TABLE civicrm_acl_contact_cache',
763 'TRUNCATE TABLE civicrm_cache',
764 'TRUNCATE TABLE civicrm_prevnext_cache',
765 'UPDATE civicrm_group SET cache_date = NULL',
766 'TRUNCATE TABLE civicrm_group_contact_cache',
767 'TRUNCATE TABLE civicrm_menu',
768 'UPDATE civicrm_setting SET value = NULL WHERE name="navigation" AND contact_id IS NOT NULL',
769 'DELETE FROM civicrm_setting WHERE name="modulePaths"', // CRM-10543
772 foreach ($queries as $query) {
773 CRM_Core_DAO
::executeQuery($query);
776 // also delete all the import and export temp tables
777 self
::clearTempTables();
781 * clear leftover temporary tables
783 public static function clearTempTables() {
785 $dao = CRM_Core_DAO
::executeQuery("SELECT DATABASE();");
787 SELECT TABLE_NAME as tableName
788 FROM INFORMATION_SCHEMA.TABLES
789 WHERE TABLE_SCHEMA = %1
791 ( TABLE_NAME LIKE 'civicrm_import_job_%'
792 OR TABLE_NAME LIKE 'civicrm_export_temp%'
793 OR TABLE_NAME LIKE 'civicrm_task_action_temp%'
794 OR TABLE_NAME LIKE 'civicrm_report_temp%'
798 $params = array(1 => array($dao->database(), 'String'));
799 $tableDAO = CRM_Core_DAO
::executeQuery($query, $params);
801 while ($tableDAO->fetch()) {
802 $tables[] = $tableDAO->tableName
;
804 if (!empty($tables)) {
805 $table = implode(',', $tables);
806 // drop leftover temporary tables
807 CRM_Core_DAO
::executeQuery("DROP TABLE $table");
812 * function to check if running in upgrade mode
814 static function isUpgradeMode($path = NULL) {
815 if (defined('CIVICRM_UPGRADE_ACTIVE')) {
820 // note: do not re-initialize config here, since this function is part of
821 // config initialization itself
823 if (defined('CIVICRM_UF') && CIVICRM_UF
== 'Joomla') {
827 $path = CRM_Utils_Array
::value($urlVar, $_GET);
830 if ($path && preg_match('/^civicrm\/upgrade(\/.*)?$/', $path)) {
838 * Wrapper function to allow unit tests to switch user framework on the fly
840 public function setUserFramework($userFramework = NULL) {
841 $this->userFramework
= $userFramework;
842 $this->_setUserFrameworkConfig($userFramework);
845 // end CRM_Core_Config