$object_name){ VardefManager::_clearCache($module_dir, $object_name); } } } /** * PRIVATE function used within clearVardefCache so we do not repeat logic * @param string module_dir the module_dir to clear * @param string object_name the name of the object we are clearing this is for sugar_cache */ static function _clearCache($module_dir = '', $object_name = ''){ if(!empty($module_dir) && !empty($object_name)){ if($object_name == 'aCase') { $object_name = 'Case'; } $file = $GLOBALS['sugar_config']['cache_dir'].'modules/'.$module_dir.'/' . $object_name . 'vardefs.php'; if(file_exists($file)){ unlink($file); $key = "VardefManager.$module_dir.$object_name"; sugar_cache_clear($key); } } } /** * Given a module, search all of the specified locations, and any others as specified * in order to refresh the cache file * * @param string $module the given module we want to load the vardefs for * @param string $object the given object we wish to load the vardefs for * @param array $additional_search_paths an array which allows a consumer to pass in additional vardef locations to search */ static function refreshVardefs($module, $object, $additional_search_paths = null, $cacheCustom = true){ // Some of the vardefs do not correctly define dictionary as global. Declare it first. global $dictionary; $vardef_paths = array( 'modules/'.$module.'/vardefs.php', 'custom/modules/'.$module.'/Ext/Vardefs/vardefs.ext.php', 'custom/Extension/modules/'.$module.'/Ext/Vardefs/vardefs.php' ); // Add in additional search paths if they were provided. if(!empty($additional_search_paths) && is_array($additional_search_paths)) { $vardef_paths = array_merge($vardef_paths, $additional_search_paths); } //search a predefined set of locations for the vardef files foreach($vardef_paths as $path){ if(file_exists($path)){ require($path); } } //load custom fields into the vardef cache if($cacheCustom){ require_once("modules/DynamicFields/DynamicField.php"); $df = new DynamicField ($module) ; $df->buildCache($module); } //great! now that we have loaded all of our vardefs. //let's go save them to the cache file. if(!empty($GLOBALS['dictionary'][$object])) { VardefManager::saveCache($module, $object); } } /** * apply global "account_required" setting if possible * @param array $vardef * @return array updated $vardef */ static function applyGlobalAccountRequirements($vardef) { if (isset($GLOBALS['sugar_config']['require_accounts'])) { if (isset($vardef['fields']) && isset($vardef['fields']['account_name']) && isset($vardef['fields']['account_name']['required'])) { $vardef['fields']['account_name']['required'] = $GLOBALS['sugar_config']['require_accounts']; } } return $vardef; } /** * load the vardefs for a given module and object * @param string $module the given module we want to load the vardefs for * @param string $object the given object we wish to load the vardefs for * @param bool $refresh whether or not we wish to refresh the cache file. */ static function loadVardef($module, $object, $refresh=false){ //here check if the cache file exists, if it does then load it, if it doesn't //then call refreshVardef //if either our session or the system is set to developerMode then refresh is set to true if(!empty($GLOBALS['sugar_config']['developerMode']) || !empty($_SESSION['developerMode'])){ $refresh = true; } // Retrieve the vardefs from cache. $key = "VardefManager.$module.$object"; if(!$refresh) { $return_result = sugar_cache_retrieve($key); $return_result = self::applyGlobalAccountRequirements($return_result); if(!empty($return_result)) { $GLOBALS['dictionary'][$object] = $return_result; return; } } // Some of the vardefs do not correctly define dictionary as global. Declare it first. global $dictionary; if(empty($GLOBALS['dictionary'][$object]) || $refresh){ //if the consumer has demanded a refresh or the cache/modules... file //does not exist, then we should do out and try to reload things if($refresh || !file_exists($GLOBALS['sugar_config']['cache_dir'].'modules/'. $module . '/' . $object . 'vardefs.php')){ VardefManager::refreshVardefs($module, $object); } //at this point we should have the cache/modules/... file //which was created from the refreshVardefs so let's try to load it. if(file_exists($GLOBALS['sugar_config']['cache_dir'].'modules/'. $module . '/' . $object . 'vardefs.php')) { if ( is_readable($GLOBALS['sugar_config']['cache_dir'].'modules/'. $module . '/' . $object . 'vardefs.php') ) { include_once($GLOBALS['sugar_config']['cache_dir'].'modules/'. $module . '/' . $object . 'vardefs.php'); } // now that we hae loaded the data from disk, put it in the cache. if(!empty($GLOBALS['dictionary'][$object])) { $GLOBALS['dictionary'][$object] = self::applyGlobalAccountRequirements($GLOBALS['dictionary'][$object]); sugar_cache_put($key,$GLOBALS['dictionary'][$object]); } } } } }