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(); }
function repair_long_relationship_names($path = '') { logThis("Begin repair_long_relationship_names", $path); require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php'; $GLOBALS['mi_remove_tables'] = false; $touched = array(); foreach ($GLOBALS['moduleList'] as $module) { $relationships = new DeployedRelationships($module); foreach ($relationships->getRelationshipList() as $rel_name) { if (strlen($rel_name) > 27 && empty($touched[$rel_name])) { logThis("Rebuilding relationship fields for {$rel_name}", $path); $touched[$rel_name] = true; $rel_obj = $relationships->get($rel_name); $rel_obj->setReadonly(false); $relationships->delete($rel_name); $relationships->save(); $relationships->add($rel_obj); $relationships->save(); $relationships->build(); } } } logThis("End repair_long_relationship_names", $path); }