예제 #1
0
 /**
  * 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
  */
 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);
     }
 }
예제 #2
0
 /**
  * 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, $params = array())
 {
     // Some of the vardefs do not correctly define dictionary as global.  Declare it first.
     global $dictionary, $beanList;
     $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);
     }
     $found = false;
     //search a predefined set of locations for the vardef files
     foreach ($vardef_paths as $path) {
         if (file_exists($path)) {
             require $path;
             $found = true;
         }
     }
     //Some modules have multiple beans, we need to see if this object has a module_dir that is different from its module_name
     if (!$found) {
         $temp = BeanFactory::newBean($module);
         if ($temp) {
             $object_name = BeanFactory::getObjectName($temp->module_dir);
             if ($temp && $temp->module_dir != $temp->module_name && !empty($object_name)) {
                 self::refreshVardefs($temp->module_dir, $object_name, $additional_search_paths, $cacheCustom);
             }
         }
     }
     //Some modules like cases have a bean name that doesn't match the object name
     if (empty($dictionary[$object])) {
         $newName = BeanFactory::getObjectName($module);
         $object = $newName != false ? $newName : $object;
     }
     //load custom fields into the vardef cache
     if ($cacheCustom) {
         require_once "modules/DynamicFields/DynamicField.php";
         $df = new DynamicField($module);
         $df->buildCache($module, false);
     }
     //great! now that we have loaded all of our vardefs.
     //let's go save them to the cache file.
     if (!empty($dictionary[$object])) {
         VardefManager::saveCache($module, $object);
     }
 }
예제 #3
0
 /**
  * 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, $params = array())
 {
     // Some of the vardefs do not correctly define dictionary as global.  Declare it first.
     global $dictionary, $beanList;
     // some tests do new SugarBean(), we can't do much with it here.
     if (empty($module)) {
         return;
     }
     $guard_name = "{$module}:{$object}";
     if (isset(self::$inReload[$guard_name])) {
         self::$inReload[$guard_name]++;
         if (self::$inReload[$guard_name] > 2) {
             return;
         }
     } else {
         self::$inReload[$guard_name] = 1;
     }
     $vardef_paths = array('modules/' . $module . '/vardefs.php', SugarAutoLoader::loadExtension("vardefs", $module), '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);
     }
     $found = false;
     //search a predefined set of locations for the vardef files
     foreach (SugarAutoLoader::existing($vardef_paths) as $path) {
         require $path;
         $found = true;
     }
     if (!empty($params['bean'])) {
         $bean = $params['bean'];
     } else {
         if (!empty($dictionary[$object])) {
             // to avoid extra refresh - we'll fill it in later
             if (!isset($GLOBALS['dictionary'][$object]['related_calc_fields'])) {
                 $GLOBALS['dictionary'][$object]['related_calc_fields'] = array();
             }
         }
         // we will instantiate here even though dictionary may not be there,
         // since in case somebody calls us with wrong module name we need bean
         // to get $module_dir. This may cause a loop but since the second call will
         // have the right module name the loop should be short.
         $bean = BeanFactory::newBean($module);
     }
     //Some modules have multiple beans, we need to see if this object has a module_dir that is different from its module_name
     if (!$found) {
         if ($bean instanceof SugarBean) {
             $object_name = BeanFactory::getObjectName($bean->module_dir);
             if ($bean->module_dir != $bean->module_name && !empty($object_name)) {
                 unset($params["bean"]);
                 // don't pass this bean down - it may be wrong bean for that module
                 self::refreshVardefs($bean->module_dir, $object_name, $additional_search_paths, $cacheCustom, $params);
             }
         }
     }
     //Some modules like cases have a bean name that doesn't match the object name
     if (empty($dictionary[$object])) {
         $newName = BeanFactory::getObjectName($module);
         if (!empty($newName)) {
             $object = $newName;
         }
     }
     //load custom fields into the vardef cache
     if ($cacheCustom && !empty($GLOBALS['dictionary'][$object]['fields'])) {
         require_once "modules/DynamicFields/DynamicField.php";
         $df = new DynamicField($module);
         $df->buildCache($module, false);
     }
     // if we are currently rebuilding the relationships, we don't want `updateRelCFModules` to be called
     // as it will fail when trying to look up relationships as they my have not been loaded into the
     // cache yet
     $rebuildingRelationships = isset($GLOBALS['buildingRelCache']) && $GLOBALS['buildingRelCache'] === true;
     if (empty($params['ignore_rel_calc_fields']) && $rebuildingRelationships === false) {
         self::updateRelCFModules($module, $object);
     }
     // Put ACLStatic into vardefs for beans supporting ACLs
     if (!empty($bean) && $bean instanceof SugarBean && !empty($dictionary[$object]) && !isset($dictionary[$object]['acls']['SugarACLStatic']) && $bean->bean_implements('ACL')) {
         $dictionary[$object]['acls']['SugarACLStatic'] = true;
     }
     //great! now that we have loaded all of our vardefs.
     //let's go save them to the cache file
     if (!empty($dictionary[$object])) {
         VardefManager::saveCache($module, $object);
         SugarBean::clearLoadedDef($object);
     }
     if (isset(self::$inReload[$guard_name])) {
         if (self::$inReload[$guard_name] > 1) {
             self::$inReload[$guard_name]--;
         } else {
             unset(self::$inReload[$guard_name]);
         }
     }
 }