Skip to content
Snippets Groups Projects
Commit eb40b5a4 authored by eileen's avatar eileen
Browse files

fix failing settings test by allowing more cache clearing

interim commit setting test passing but regression on api test
parent 5b887f26
No related branches found
No related tags found
No related merge requests found
......@@ -101,6 +101,7 @@ class CRM_Core_BAO_Domain extends CRM_Core_DAO_Domain {
static function setDomain($domainID){
CRM_Core_Config::domainID($domainID);
self::getDomain($domainID);
CRM_Core_Config::singleton(TRUE, TRUE);
}
/**
......
......@@ -75,31 +75,45 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
* @static
* @access public
*/
static function inCache($group,
static function inCache(
$group,
$name,
$componentID = NULL,
$contactID = NULL,
$load = FALSE,
$domainID = NULL
$domainID = NULL,
$force = FALSE
) {
if (!isset(self::$_cache)) {
self::$_cache = array();
}
$cacheKey = "CRM_Setting_{$group}_{$componentID}_{$contactID}_{$domainID}";
if ($load &&
!isset(self::$_cache[$cacheKey])
($force || !isset(self::$_cache[$cacheKey]))
) {
// check in civi cache if present (typically memcache)
$globalCache = CRM_Utils_Cache::singleton();
$result = $globalCache->get($cacheKey);
if ($result) {
self::$_cache[$cacheKey] = $result;
}
}
return isset(self::$_cache[$cacheKey]) ? $cacheKey : NULL;
}
/**
* Allow key o be cleared
* @param string $cacheKey
*/
static function flushCache($cacheKey){
unset(self::$_cache[$cacheKey]);
$globalCache = CRM_Utils_Cache::singleton();
$globalCache->delete($cacheKey);
}
static function setCache($values,
$group,
......@@ -200,7 +214,6 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
$cacheKey = self::setCache($values, $group, $componentID, $contactID, $domainID);
}
return $name ? CRM_Utils_Array::value($name, self::$_cache[$cacheKey], $defaultValue) : self::$_cache[$cacheKey];
}
......@@ -234,6 +247,12 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
$result[$domainID] = array();
foreach ($fieldsToGet as $name => $value) {
if(!empty($fields['values'][$name]['prefetch'])){
if(isset($params['filters']) && isset($params['filters']['prefetch'])
&& $params['filters']['prefetch'] == 0){
// we are filtering out the prefetches from the return array
// so we will skip
continue;
}
$configKey = CRM_Utils_Array::value('config_key', $fields['values'][$name], $name);
if(isset($config->$configKey)){
$setting = $config->$configKey;
......@@ -245,7 +264,7 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
$fields['values'][$name]['group_name'],
$name,
CRM_Utils_Array::value('component_id', $params),
CRM_Utils_Array::value('default_value', $params),
null,
CRM_Utils_Array::value('contact_id', $params),
$domainID
);
......@@ -283,7 +302,6 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
$createdID = NULL,
$domainID = NULL
) {
if (empty($domainID)) {
$domainID = CRM_Core_Config::domainID();
}
......@@ -635,8 +653,10 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
$apiParams = array(
'version' => 3,
'domain_id' => 'all',
'filters' => array('prefetch' => 0),
);
$existing = civicrm_api('setting', 'get', $apiParams);
if (!empty($existing['values'])) {
$allSettings = civicrm_api('setting', 'getfields', array('version' => 3));
foreach ($existing['values'] as $domainID => $domainSettings) {
......@@ -657,6 +677,8 @@ class CRM_Core_BAO_Setting extends CRM_Core_DAO_Setting {
* Note that where the key name is being changed the 'legacy_key' will give us the old name
*/
static function convertConfigToSetting($name, $domainID = null) {
// we have to force this here in case more than one domain is in play.
// whenever there is a possibility of more than one domain we must force it
$config = CRM_Core_Config::singleton();
if (empty($domainID)) {
$domainID= CRM_Core_Config::domainID();
......
......@@ -121,19 +121,30 @@ class CRM_Core_BAO_SettingTest extends CiviUnitTestCase {
*
**/
function testConvertAndFillSettings() {
$sql = " DELETE FROM civicrm_setting WHERE name = 'max_attachments'";
CRM_Core_DAO::executeQuery($sql);
$settings = array('maxAttachments' => 6);
CRM_Core_BAO_ConfigSetting::add($settings);
$config = CRM_Core_Config::singleton(TRUE, TRUE);
$this->assertEquals(6, $config->maxAttachments);
$checkSQL = "SELECT count(*) FROM civicrm_domain WHERE config_backend LIKE '%Max%' AND id = 1
$checkSQL = "SELECT count(*) FROM civicrm_domain WHERE config_backend LIKE '%\"maxAttachments\";i:6%' AND id = 1
";
$checkresult = CRM_Core_DAO::singleValueQuery($checkSQL);
$this->assertEquals(1, $checkresult, "Check that maxAttachments has been saved to database not just stored in config");
$sql = " DELETE FROM civicrm_setting WHERE name = 'max_attachments'";
$currentDomain = CRM_Core_Config::domainID();
<<<<<<< Updated upstream
CRM_Core_DAO::executeQuery($sql);
CRM_Core_BAO_Setting::inCache('CiviCRM Preferences', 'max_attachments', NULL, NULL, TRUE, $currentDomain, TRUE);
CRM_Core_BAO_Setting::updateSettingsFromMetaData();
=======
>>>>>>> Stashed changes
CRM_Core_DAO::executeQuery($sql);
// we are setting up an artificial situation here as we are trying to drive out
// previous memory of this setting so we need to flush it out
$cachekey = CRM_Core_BAO_Setting::inCache('CiviCRM Preferences', 'max_attachments', NULL, NULL, TRUE, $currentDomain);
CRM_Core_BAO_Setting::flushCache($cachekey);
CRM_Core_BAO_Setting::updateSettingsFromMetaData();
//check current domain
$value = civicrm_api('setting', 'getvalue', array(
'version' => 3,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment