* @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,
$cacheKey = self::setCache($values, $group, $componentID, $contactID, $domainID);
}
-
return $name ? CRM_Utils_Array::value($name, self::$_cache[$cacheKey], $defaultValue) : self::$_cache[$cacheKey];
}
$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;
$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
);
$createdID = NULL,
$domainID = NULL
) {
-
if (empty($domainID)) {
$domainID = CRM_Core_Config::domainID();
}
$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) {
* 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();
*
**/
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,