'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; } /** * Remove all created relationships * * @static */ public static function removeAllCreatedRelationships() { foreach(self::$_relsAdded as $rel) { $relationships = new DeployedRelationships($rel['lhs_module']); $relationships->delete($rel['relationship_name']); $relationships->save(); $relationships->build(); LanguageManager::clearLanguageCache($rel['lhs_module']); require_once("data/Relationships/RelationshipFactory.php"); SugarRelationshipFactory::deleteCache(); SugarRelationshipFactory::rebuildCache(); } // since we are creating a relationship we need to unset this global var if(isset($GLOBALS['reload_vardefs'])) { unset($GLOBALS['reload_vardefs']); } } /** * Make sure we have at least the required keys * * @static * @param array $relationship_def * @return bool */ protected static function checkRequiredFields(array $relationship_def) { foreach(self::$_relRequiredKeys as $key) { if(!array_key_exists($key, $relationship_def)) { return false; } } return true; } } ?>