3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
39 require_once 'Log.php';
40 require_once 'Mail.php';
42 require_once 'api/api.php';
44 class CRM_Core_Config
extends CRM_Core_Config_Variables
{
46 /// BASE SYSTEM PROPERTIES (CIVICRM.SETTINGS.PHP)
50 * the dsn of the database connection
57 * the name of user framework
61 public $userFramework = 'Drupal';
64 * the name of user framework url variable name
68 public $userFrameworkURLVar = 'q';
71 * the dsn of the database connection for user framework
75 public $userFrameworkDSN = NULL;
78 * The connector module for the CMS/UF
79 * @todo Introduce an interface.
81 * @var CRM_Utils_System_Base
83 public $userSystem = NULL;
86 * The root directory where Smarty should store compiled files
90 public $templateCompileDir = './templates_c/en_US/';
95 public $configAndLogDir = NULL;
97 // END: BASE SYSTEM PROPERTIES (CIVICRM.SETTINGS.PHP)
100 /// BEGIN HELPER CLASS PROPERTIES
104 * are we initialized and in a proper state
108 public $initialized = 0;
113 public $customPHPPathDir;
116 * the factory class used to instantiate our DB objects
120 private $DAOFactoryClass = 'CRM_Contact_DAO_Factory';
123 * The handle to the log that we are using
126 private static $_log = NULL;
129 * the handle on the mail handler that we are using
133 public static $_mail = NULL;
136 * We only need one instance of this object. So we use the singleton
137 * pattern and cache the instance in this variable
139 * @var CRM_Core_Config
141 private static $_singleton = NULL;
144 * @var CRM_Core_Component
146 public $componentRegistry = NULL;
149 /// END HELPER CLASS PROPERTIES
153 /// RUNTIME SET CLASS PROPERTIES
158 * TRUE, if the call is CiviCRM.
159 * FALSE, if the call is from the CMS.
161 public $inCiviCRM = FALSE;
164 /// END: RUNTIME SET CLASS PROPERTIES
170 public $recaptchaPublicKey;
173 * The constructor. Sets domain id if defined, otherwise assumes
174 * single instance installation.
176 private function __construct() {
180 * Singleton function used to manage this object.
182 * @param $loadFromDB boolean whether to load from the database
183 * @param $force boolean whether to force a reconstruction
185 * @return CRM_Core_Config
188 static function &singleton($loadFromDB = TRUE, $force = FALSE) {
189 if (self
::$_singleton === NULL ||
$force) {
190 // goto a simple error handler
191 $GLOBALS['civicrm_default_error_scope'] = CRM_Core_TemporaryErrorScope
::create(array('CRM_Core_Error', 'handle'));
192 $errorScope = CRM_Core_TemporaryErrorScope
::create(array('CRM_Core_Error', 'simpleHandler'));
194 // lets ensure we set E_DEPRECATED to minimize errors
196 if (defined('E_DEPRECATED')) {
197 error_reporting(error_reporting() & ~E_DEPRECATED
);
200 // first, attempt to get configuration object from cache
201 $cache = CRM_Utils_Cache
::singleton();
202 self
::$_singleton = $cache->get('CRM_Core_Config' . CRM_Core_Config
::domainID());
203 // if not in cache, fire off config construction
204 if (!self
::$_singleton) {
205 self
::$_singleton = new CRM_Core_Config
;
206 self
::$_singleton->_initialize($loadFromDB);
208 //initialize variables. for gencode we cannot load from the
209 //db since the db might not be initialized
211 // initialize stuff from the settings file
212 self
::$_singleton->setCoreVariables();
214 self
::$_singleton->_initVariables();
216 // I dont think we need to do this twice
217 // however just keeping this commented for now in 4.4
218 // in case we hit any issues - CRM-13064
219 // We can safely delete this once we release 4.4.4
220 // self::$_singleton->setCoreVariables();
222 $cache->set('CRM_Core_Config' . CRM_Core_Config
::domainID(), self
::$_singleton);
225 // we retrieve the object from memcache, so we now initialize the objects
226 self
::$_singleton->_initialize($loadFromDB);
228 // CRM-9803, NYSS-4822
229 // this causes various settings to be reset and hence we should
230 // only use the config object that we retrived from memcache
233 self
::$_singleton->initialized
= 1;
235 if (isset(self
::$_singleton->customPHPPathDir
) &&
236 self
::$_singleton->customPHPPathDir
238 $include_path = self
::$_singleton->customPHPPathDir
. PATH_SEPARATOR
. get_include_path();
239 set_include_path($include_path);
242 // set the callback at the very very end, to avoid an infinite loop
243 // set the error callback
246 // call the hook so other modules can add to the config
247 // again doing this at the very very end
248 CRM_Utils_Hook
::config(self
::$_singleton);
250 // make sure session is always initialised
251 $session = CRM_Core_Session
::singleton();
253 // for logging purposes, pass the userID to the db
254 $userID = $session->get('userID');
256 CRM_Core_DAO
::executeQuery('SET @civicrm_user_id = %1',
257 array(1 => array($userID, 'Integer'))
261 // initialize authentication source
262 self
::$_singleton->initAuthSrc();
264 return self
::$_singleton;
268 * @param string $userFramework
269 * One of 'Drupal', 'Joomla', etc.
271 private function _setUserFrameworkConfig($userFramework) {
273 $this->userFrameworkClass
= 'CRM_Utils_System_' . $userFramework;
274 $this->userHookClass
= 'CRM_Utils_Hook_' . $userFramework;
275 $userPermissionClass = 'CRM_Core_Permission_' . $userFramework;
276 $this->userPermissionClass
= new $userPermissionClass();
278 $class = $this->userFrameworkClass
;
279 // redundant with _initVariables
280 $this->userSystem
= new $class();
282 if ($userFramework == 'Joomla') {
283 $this->userFrameworkURLVar
= 'task';
286 if (defined('CIVICRM_UF_BASEURL')) {
287 $this->userFrameworkBaseURL
= CRM_Utils_File
::addTrailingSlash(CIVICRM_UF_BASEURL
, '/');
289 //format url for language negotiation, CRM-7803
290 $this->userFrameworkBaseURL
= CRM_Utils_System
::languageNegotiationURL($this->userFrameworkBaseURL
);
292 if (CRM_Utils_System
::isSSL()) {
293 $this->userFrameworkBaseURL
= str_replace('http://', 'https://',
294 $this->userFrameworkBaseURL
299 if (defined('CIVICRM_UF_DSN')) {
300 $this->userFrameworkDSN
= CIVICRM_UF_DSN
;
303 // this is dynamically figured out in the civicrm.settings.php file
304 if (defined('CIVICRM_CLEANURL')) {
305 $this->cleanURL
= CIVICRM_CLEANURL
;
311 $this->userFrameworkVersion
= $this->userSystem
->getVersion();
313 if ($userFramework == 'Joomla') {
314 /** @var object|null $mainframe */
316 $dbprefix = $mainframe ?
$mainframe->getCfg('dbprefix') : 'jos_';
317 $this->userFrameworkUsersTableName
= $dbprefix . 'users';
319 elseif ($userFramework == 'WordPress') {
321 $dbprefix = $wpdb ?
$wpdb->prefix
: '';
322 $this->userFrameworkUsersTableName
= $dbprefix . 'users';
327 * Initializes the entire application.
328 * Reads constants defined in civicrm.settings.php and
329 * stores them in config properties.
331 * @param bool $loadFromDB
333 private function _initialize($loadFromDB = TRUE) {
335 // following variables should be set in CiviCRM settings and
336 // as crucial ones, are defined upon initialisation
337 // instead of in CRM_Core_Config_Defaults
338 if (defined('CIVICRM_DSN')) {
339 $this->dsn
= CIVICRM_DSN
;
341 elseif ($loadFromDB) {
342 // bypass when calling from gencode
343 echo 'You need to define CIVICRM_DSN in civicrm.settings.php';
347 if (defined('CIVICRM_TEMPLATE_COMPILEDIR')) {
348 $this->templateCompileDir
= CRM_Utils_File
::addTrailingSlash(CIVICRM_TEMPLATE_COMPILEDIR
);
350 // also make sure we create the config directory within this directory
351 // the below statement will create both the templates directory and the config and log directory
352 $this->configAndLogDir
=
353 CRM_Utils_File
::baseFilePath($this->templateCompileDir
) .
354 'ConfigAndLog' . DIRECTORY_SEPARATOR
;
355 CRM_Utils_File
::createDir($this->configAndLogDir
);
356 CRM_Utils_File
::restrictAccess($this->configAndLogDir
);
358 // we're automatically prefixing compiled templates directories with country/language code
360 if (!empty($tsLocale)) {
361 $this->templateCompileDir
.= CRM_Utils_File
::addTrailingSlash($tsLocale);
363 elseif (!empty($this->lcMessages
)) {
364 $this->templateCompileDir
.= CRM_Utils_File
::addTrailingSlash($this->lcMessages
);
367 CRM_Utils_File
::createDir($this->templateCompileDir
);
368 CRM_Utils_File
::restrictAccess($this->templateCompileDir
);
370 elseif ($loadFromDB) {
371 echo 'You need to define CIVICRM_TEMPLATE_COMPILEDIR in civicrm.settings.php';
377 if (defined('CIVICRM_UF')) {
378 $this->userFramework
= CIVICRM_UF
;
379 $this->_setUserFrameworkConfig($this->userFramework
);
382 echo 'You need to define CIVICRM_UF in civicrm.settings.php';
386 // also initialize the logger
387 self
::$_log = Log
::singleton('display');
389 // initialize component registry early to avoid "race"
390 // between CRM_Core_Config and CRM_Core_Component (they
392 $this->componentRegistry
= new CRM_Core_Component();
396 * initialize the DataObject framework
401 private function _initDAO() {
402 CRM_Core_DAO
::init($this->dsn
);
404 $factoryClass = $this->DAOFactoryClass
;
405 require_once str_replace('_', DIRECTORY_SEPARATOR
, $factoryClass) . '.php';
406 CRM_Core_DAO
::setFactory(new $factoryClass());
407 if (CRM_Utils_Constant
::value('CIVICRM_MYSQL_STRICT', CRM_Utils_System
::isDevelopment())) {
408 CRM_Core_DAO
::executeQuery('SET SESSION sql_mode = STRICT_TRANS_TABLES');
413 * returns the singleton logger for the application
420 static public function &getLog() {
421 if (!isset(self
::$_log)) {
422 self
::$_log = Log
::singleton('display');
429 * initialize the config variables
434 private function _initVariables() {
435 // retrieve serialised settings
436 $variables = array();
437 CRM_Core_BAO_ConfigSetting
::retrieve($variables);
439 // if settings are not available, go down the full path
440 if (empty($variables)) {
441 // Step 1. get system variables with their hardcoded defaults
442 $variables = get_object_vars($this);
444 // Step 2. get default values (with settings file overrides if
445 // available - handled in CRM_Core_Config_Defaults)
446 CRM_Core_Config_Defaults
::setValues($variables);
448 // retrieve directory and url preferences also
449 CRM_Core_BAO_Setting
::retrieveDirectoryAndURLPreferences($variables);
451 // add component specific settings
452 $this->componentRegistry
->addConfig($this);
454 // serialise settings
455 $settings = $variables;
456 CRM_Core_BAO_ConfigSetting
::add($settings);
459 $urlArray = array('userFrameworkResourceURL', 'imageUploadURL');
460 $dirArray = array('uploadDir', 'customFileUploadDir');
462 foreach ($variables as $key => $value) {
463 if (in_array($key, $urlArray)) {
464 $value = CRM_Utils_File
::addTrailingSlash($value, '/');
466 elseif (in_array($key, $dirArray)) {
468 $value = CRM_Utils_File
::addTrailingSlash($value);
470 if (empty($value) ||
(CRM_Utils_File
::createDir($value, FALSE) === FALSE)) {
471 // seems like we could not create the directories
472 // settings might have changed, lets suppress a message for now
473 // so we can make some more progress and let the user fix their settings
474 // for now we assign it to a know value
476 $value = $this->templateCompileDir
;
477 $url = CRM_Utils_System
::url('civicrm/admin/setting/path', 'reset=1');
478 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(
481 )), ts('Check Settings'), 'alert');
484 elseif ($key == 'lcMessages') {
485 // reset the templateCompileDir to locale-specific and make sure it exists
486 if (substr($this->templateCompileDir
, -1 * strlen($value) - 1, -1) != $value) {
487 $this->templateCompileDir
.= CRM_Utils_File
::addTrailingSlash($value);
488 CRM_Utils_File
::createDir($this->templateCompileDir
);
489 CRM_Utils_File
::restrictAccess($this->templateCompileDir
);
493 $this->$key = $value;
496 if ($this->userFrameworkResourceURL
) {
497 // we need to do this here so all blocks also load from an ssl server
498 if (CRM_Utils_System
::isSSL()) {
499 CRM_Utils_System
::mapConfigToSSL();
501 $rrb = parse_url($this->userFrameworkResourceURL
);
502 // dont use absolute path if resources are stored on a different server
504 $this->resourceBase
= $this->userFrameworkResourceURL
;
505 if (isset($_SERVER['HTTP_HOST']) &&
508 $this->resourceBase
= ($rrb['host'] == $_SERVER['HTTP_HOST']) ?
$rrb['path'] : $this->userFrameworkResourceURL
;
512 if (!$this->customFileUploadDir
) {
513 $this->customFileUploadDir
= $this->uploadDir
;
516 if ($this->geoProvider
) {
517 $this->geocodeMethod
= 'CRM_Utils_Geocode_' . $this->geoProvider
;
519 elseif ($this->mapProvider
) {
520 $this->geocodeMethod
= 'CRM_Utils_Geocode_' . $this->mapProvider
;
523 require_once (str_replace('_', DIRECTORY_SEPARATOR
, $this->userFrameworkClass
) . '.php');
524 $class = $this->userFrameworkClass
;
525 // redundant with _setUserFrameworkConfig
526 $this->userSystem
= new $class();
530 * Retrieve a mailer to send any mail from the application
532 * @param boolean $persist open a persistent smtp connection, should speed up mailings
536 static function &getMailer($persist = FALSE) {
537 if (!isset(self
::$_mail)) {
538 $mailingInfo = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::MAILING_PREFERENCES_NAME
,
542 if ($mailingInfo['outBound_option'] == CRM_Mailing_Config
::OUTBOUND_OPTION_REDIRECT_TO_DB ||
543 (defined('CIVICRM_MAILER_SPOOL') && CIVICRM_MAILER_SPOOL
)
545 self
::$_mail = self
::_createMailer('CRM_Mailing_BAO_Spool', array());
547 elseif ($mailingInfo['outBound_option'] == CRM_Mailing_Config
::OUTBOUND_OPTION_SMTP
) {
548 if ($mailingInfo['smtpServer'] == '' ||
!$mailingInfo['smtpServer']) {
549 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'))));
550 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'))));
553 $params['host'] = $mailingInfo['smtpServer'] ?
$mailingInfo['smtpServer'] : 'localhost';
554 $params['port'] = $mailingInfo['smtpPort'] ?
$mailingInfo['smtpPort'] : 25;
556 if ($mailingInfo['smtpAuth']) {
557 $params['username'] = $mailingInfo['smtpUsername'];
558 $params['password'] = CRM_Utils_Crypt
::decrypt($mailingInfo['smtpPassword']);
559 $params['auth'] = TRUE;
562 $params['auth'] = FALSE;
565 // set the localhost value, CRM-3153
566 $params['localhost'] = CRM_Utils_Array
::value('SERVER_NAME', $_SERVER, 'localhost');
568 // also set the timeout value, lets set it to 30 seconds
570 $params['timeout'] = 30;
573 $params['persist'] = $persist;
575 self
::$_mail = self
::_createMailer('smtp', $params);
577 elseif ($mailingInfo['outBound_option'] == CRM_Mailing_Config
::OUTBOUND_OPTION_SENDMAIL
) {
578 if ($mailingInfo['sendmail_path'] == '' ||
579 !$mailingInfo['sendmail_path']
581 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'))));
582 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'))));
584 $params['sendmail_path'] = $mailingInfo['sendmail_path'];
585 $params['sendmail_args'] = $mailingInfo['sendmail_args'];
587 self
::$_mail = self
::_createMailer('sendmail', $params);
589 elseif ($mailingInfo['outBound_option'] == CRM_Mailing_Config
::OUTBOUND_OPTION_MAIL
) {
590 self
::$_mail = self
::_createMailer('mail', array());
592 elseif ($mailingInfo['outBound_option'] == CRM_Mailing_Config
::OUTBOUND_OPTION_MOCK
) {
593 self
::$_mail = self
::_createMailer('mock', array());
595 elseif ($mailingInfo['outBound_option'] == CRM_Mailing_Config
::OUTBOUND_OPTION_DISABLED
) {
596 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'))));
597 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'))));
600 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'))));
601 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'))));
602 CRM_Core_Error
::debug_var('mailing_info', $mailingInfo);
609 * Create a new instance of a PEAR Mail driver
611 * @param string $driver 'CRM_Mailing_BAO_Spool' or a name suitable for Mail::factory()
612 * @param array $params
613 * @return Mail (More specifically, a class which implements the "send()" function)
615 public static function _createMailer($driver, $params) {
616 if ($driver == 'CRM_Mailing_BAO_Spool') {
617 $mailer = new CRM_Mailing_BAO_Spool($params);
620 $mailer = Mail
::factory($driver, $params);
622 CRM_Utils_Hook
::alterMail($mailer, $driver, $params);
627 * Deletes the web server writable directories
630 * 1: clean templates_c, 2: clean upload, 3: clean both
633 public function cleanup($value, $rmdir = TRUE) {
634 $value = (int ) $value;
638 CRM_Utils_File
::cleanDir($this->templateCompileDir
, $rmdir);
639 CRM_Utils_File
::createDir($this->templateCompileDir
);
643 CRM_Utils_File
::cleanDir($this->uploadDir
);
644 CRM_Utils_File
::createDir($this->uploadDir
);
647 // Whether we delete/create or simply preserve directories, we should
648 // certainly make sure the restrictions are enforced.
649 foreach (array($this->templateCompileDir
, $this->uploadDir
, $this->configAndLogDir
, $this->customFileUploadDir
) as $dir) {
650 if ($dir && is_dir($dir)) {
651 CRM_Utils_File
::restrictAccess($dir);
657 * verify that the needed parameters are not null in the config
659 * @param CRM_Core_Config (reference ) the system config object
660 * @param array (reference ) the parameters that need a value
666 static function check(&$config, &$required) {
667 foreach ($required as $name) {
668 if (CRM_Utils_System
::isNull($config->$name)) {
676 * reset the serialized array and recompute
680 $query = "UPDATE civicrm_domain SET config_backend = null";
681 CRM_Core_DAO
::executeQuery($query);
684 // This method should initialize auth sources
685 function initAuthSrc() {
686 $session = CRM_Core_Session
::singleton();
687 if ($session->get('userID') && !$session->get('authSrc')) {
688 $session->set('authSrc', CRM_Core_Permission
::AUTH_SRC_LOGIN
);
692 CRM_Contact_BAO_Contact_Permission
::initChecksumAuthSrc();
696 * one function to get domain ID
698 static function domainID($domainID = NULL, $reset = FALSE) {
703 if ($reset ||
empty($domain)) {
704 $domain = defined('CIVICRM_DOMAIN_ID') ? CIVICRM_DOMAIN_ID
: 1;
711 * do general cleanup of caches, temp directories and temp tables
714 function cleanupCaches($sessionReset = TRUE) {
715 // cleanup templates_c directory
716 $this->cleanup(1, FALSE);
719 self
::clearDBCache();
722 $session = CRM_Core_Session
::singleton();
728 * Do general cleanup of module permissions.
730 function cleanupPermissions() {
731 $module_files = CRM_Extension_System
::singleton()->getMapper()->getActiveModuleFiles();
732 if ($this->userPermissionClass
->isModulePermissionSupported()) {
733 // Can store permissions -- so do it!
734 $this->userPermissionClass
->upgradePermissions(
735 CRM_Core_Permission
::basicPermissions()
738 // Cannot store permissions -- warn if any modules require them
739 $modules_with_perms = array();
740 foreach ($module_files as $module_file) {
741 $perms = $this->userPermissionClass
->getModulePermissions($module_file['prefix']);
742 if (!empty($perms)) {
743 $modules_with_perms[] = $module_file['prefix'];
746 if (!empty($modules_with_perms)) {
747 CRM_Core_Session
::setStatus(
748 ts('Some modules define permissions, but the CMS cannot store them: %1', array(1 => implode(', ', $modules_with_perms))),
749 ts('Permission Error'),
757 * Flush information about loaded modules
759 function clearModuleList() {
760 CRM_Extension_System
::singleton()->getCache()->flush();
761 CRM_Utils_Hook
::singleton(TRUE);
762 CRM_Core_PseudoConstant
::getModuleExtensions(TRUE);
763 CRM_Core_Module
::getAll(TRUE);
769 public static function clearDBCache() {
771 'TRUNCATE TABLE civicrm_acl_cache',
772 'TRUNCATE TABLE civicrm_acl_contact_cache',
773 'TRUNCATE TABLE civicrm_cache',
774 'TRUNCATE TABLE civicrm_prevnext_cache',
775 'UPDATE civicrm_group SET cache_date = NULL',
776 'TRUNCATE TABLE civicrm_group_contact_cache',
777 'TRUNCATE TABLE civicrm_menu',
778 'UPDATE civicrm_setting SET value = NULL WHERE name="navigation" AND contact_id IS NOT NULL',
779 'DELETE FROM civicrm_setting WHERE name="modulePaths"', // CRM-10543
782 foreach ($queries as $query) {
783 CRM_Core_DAO
::executeQuery($query);
786 // also delete all the import and export temp tables
787 self
::clearTempTables();
791 * clear leftover temporary tables
793 public static function clearTempTables() {
795 $dao = CRM_Core_DAO
::executeQuery("SELECT DATABASE();");
797 SELECT TABLE_NAME as tableName
798 FROM INFORMATION_SCHEMA.TABLES
799 WHERE TABLE_SCHEMA = %1
801 ( TABLE_NAME LIKE 'civicrm_import_job_%'
802 OR TABLE_NAME LIKE 'civicrm_export_temp%'
803 OR TABLE_NAME LIKE 'civicrm_task_action_temp%'
804 OR TABLE_NAME LIKE 'civicrm_report_temp%'
808 $params = array(1 => array($dao->database(), 'String'));
809 $tableDAO = CRM_Core_DAO
::executeQuery($query, $params);
811 while ($tableDAO->fetch()) {
812 $tables[] = $tableDAO->tableName
;
814 if (!empty($tables)) {
815 $table = implode(',', $tables);
816 // drop leftover temporary tables
817 CRM_Core_DAO
::executeQuery("DROP TABLE $table");
822 * function to check if running in upgrade mode
824 static function isUpgradeMode($path = NULL) {
825 if (defined('CIVICRM_UPGRADE_ACTIVE')) {
830 // note: do not re-initialize config here, since this function is part of
831 // config initialization itself
833 if (defined('CIVICRM_UF') && CIVICRM_UF
== 'Joomla') {
837 $path = CRM_Utils_Array
::value($urlVar, $_GET);
840 if ($path && preg_match('/^civicrm\/upgrade(\/.*)?$/', $path)) {
848 * Wrapper function to allow unit tests to switch user framework on the fly
850 public function setUserFramework($userFramework = NULL) {
851 $this->userFramework
= $userFramework;
852 $this->_setUserFrameworkConfig($userFramework);
856 * Is back office credit card processing enabled for this site - ie are there any installed processors that support
860 static function isEnabledBackOfficeCreditCardPayments() {
861 // restrict to type=1 (credit card) payment processor payment_types and only include billing mode types 1 and 3
862 $processors = CRM_Core_PseudoConstant
::paymentProcessor(FALSE, FALSE,
863 "billing_mode IN ( 1, 3 ) AND payment_type = 1"
865 if (count($processors) > 0) {
871 // end CRM_Core_Config