예제 #1
0
 private function createRelationship($lhs_module, $rhs_module = null, $relationship_type = 'one-to-many')
 {
     $rhs_module = $rhs_module == null ? $lhs_module : $rhs_module;
     // Adding relation between products and users
     $this->relationships = new DeployedRelationships($lhs_module);
     $definition = array('lhs_module' => $lhs_module, 'relationship_type' => $relationship_type, 'rhs_module' => $rhs_module, 'lhs_label' => $lhs_module, 'rhs_label' => $rhs_module, 'rhs_subpanel' => 'default');
     $this->relationship = RelationshipFactory::newRelationship($definition);
     $this->relationships->add($this->relationship);
     $this->relationships->save();
     $this->relationships->build();
     LanguageManager::clearLanguageCache($lhs_module);
     // Updating $dictionary by created relation
     global $dictionary;
     $moduleInstaller = new ModuleInstaller();
     $moduleInstaller->silent = true;
     $moduleInstaller->rebuild_tabledictionary();
     require 'modules/TableDictionary.php';
     // Updating vardefs
     VardefManager::$linkFields = array();
     VardefManager::clearVardef();
     VardefManager::refreshVardefs($lhs_module, BeanFactory::getObjectName($lhs_module));
     if ($lhs_module != $rhs_module) {
         VardefManager::refreshVardefs($rhs_module, BeanFactory::getObjectName($rhs_module));
     }
     SugarRelationshipFactory::rebuildCache();
 }
 /**
  * Create a relationship
  *
  * Params should be passed in as this:
  *
  * array(
  *       'relationship_type' => 'one-to-many',
  *       'lhs_module' => 'Accounts',
  *       'rhs_module' => 'Accounts',
  *   )
  *
  * @static
  * @param array $relationship_def
  * @return ActivitiesRelationship|bool|ManyToManyRelationship|ManyToOneRelationship|OneToManyRelationship|OneToOneRelationship
  */
 public static function createRelationship(array $relationship_def)
 {
     if (!self::checkRequiredFields($relationship_def)) {
         return false;
     }
     $relationships = new DeployedRelationships($relationship_def['lhs_module']);
     if (!isset($relationship_def['view_module'])) {
         $relationship_def['view_module'] = $relationship_def['lhs_module'];
     }
     $REQUEST_Backup = $_REQUEST;
     $_REQUEST = $relationship_def;
     $relationship = $relationships->addFromPost();
     $relationships->save();
     $relationships->build();
     LanguageManager::clearLanguageCache($relationship_def['lhs_module']);
     SugarRelationshipFactory::rebuildCache();
     // rebuild the dictionary to make sure that it has the new relationship in it
     SugarTestHelper::setUp('dictionary');
     // reset the link fields since we added one
     VardefManager::$linkFields = array();
     $_REQUEST = $REQUEST_Backup;
     unset($REQUEST_Backup);
     self::$_relsAdded[] = $relationship->getDefinition();
     return $relationship;
 }
예제 #3
0
 /**
  * @static
  * @param  $module
  * @param  $object
  * @return array|bool  returns a list of all fields in the module of type 'link'.
  */
 protected static function getLinkFieldsForModule($module, $object)
 {
     global $dictionary;
     //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;
     }
     if (empty($dictionary[$object])) {
         self::loadVardef($module, $object, false, array('ignore_rel_calc_fields' => true));
     }
     if (empty($dictionary[$object])) {
         $GLOBALS['log']->debug("Failed to load vardefs for {$module}:{$object} in linkFieldsForModule<br/>");
         return false;
     }
     //Cache link fields for this call in a static variable
     if (!isset(self::$linkFields)) {
         self::$linkFields = array();
     }
     if (isset(self::$linkFields[$object])) {
         return self::$linkFields[$object];
     }
     $vardef = $dictionary[$object];
     $links = array();
     foreach ($vardef['fields'] as $name => $def) {
         //Look through all link fields for related modules that have calculated fields that use that relationship
         if (!empty($def['type']) && $def['type'] == 'link' && !empty($def['relationship'])) {
             $links[$name] = $def;
         }
     }
     self::$linkFields[$object] = $links;
     return $links;
 }
예제 #4
0
 /**
  * Doing the same things like setUp but for initialized list of modules
  *
  * @static
  * @return bool are caches refreshed or not
  */
 protected static function tearDown_relation()
 {
     SugarRelationshipFactory::deleteCache();
     $modules = array_unique(self::$cleanModules);
     foreach ($modules as $module) {
         LanguageManager::clearLanguageCache($module);
     }
     self::tearDown('dictionary');
     VardefManager::$linkFields = array();
     VardefManager::clearVardef();
     foreach ($modules as $module) {
         VardefManager::refreshVardefs($module, BeanFactory::getBeanName($module));
     }
     SugarRelationshipFactory::rebuildCache();
     self::$cleanModules = array();
     return true;
 }
예제 #5
0
 /**
  * @static
  * @param  $module
  * @param  $object
  * @return array|bool  returns a list of all fields in the module of type 'link'.
  */
 protected static function getLinkFieldsForModule($module, $object)
 {
     global $dictionary;
     if ($object == 'aCase') {
         $object = 'Case';
     }
     if (empty($dictionary[$object])) {
         self::loadVardef($module, $object, false, array('ignore_rel_calc_fields' => true));
     }
     if (empty($dictionary[$object])) {
         $GLOBALS['log']->debug("Failed to load vardefs for {$module}:{$object} in linkFieldsForModule<br/>");
         return false;
     }
     //Cache link fields for this call in a static variable
     if (!isset(self::$linkFields)) {
         self::$linkFields = array();
     }
     if (isset(self::$linkFields[$object])) {
         return self::$linkFields[$object];
     }
     $vardef = $dictionary[$object];
     $links = array();
     foreach ($vardef['fields'] as $name => $def) {
         //Look through all link fields for related modules that have calculated fields that use that relationship
         if (!empty($def['type']) && $def['type'] == 'link' && !empty($def['relationship'])) {
             $links[$name] = $def;
         }
     }
     return $links;
 }