private function deleteRelationship($lhs_module, $rhs_module = null, $rel_name = null) { $rhs_module = $rhs_module == null ? $lhs_module : $rhs_module; $this->relationships = new DeployedRelationships($lhs_module); $this->relationships->delete($rel_name !== null ? $rel_name : $this->relationship->getName()); $this->relationships->save(); SugarRelationshipFactory::deleteCache(); LanguageManager::clearLanguageCache($lhs_module); if ($lhs_module != $rhs_module) { LanguageManager::clearLanguageCache($rhs_module); } }
/** * @group 45339 */ public function testGetExtensionsList() { // Create new relationship between Leads and Accounts $_REQUEST['view_module'] = "Leads"; $_REQUEST['lhs_module'] = "Leads"; $_REQUEST['rhs_module'] = "Accounts"; $_REQUEST['lhs_label'] = "Leads"; $_REQUEST['rhs_label'] = "Accounts"; $deployedRelation = new DeployedRelationships($_REQUEST['view_module']); $relationLeadAccount = $deployedRelation->addFromPost(); $deployedRelation->save(); $deployedRelation->build(); //create expected file paths from custom extensions $accountContactRelInAccountVardefExtensions = sprintf('custom%1$sExtension%1$smodules%1$sAccounts%1$sExt%1$sVardefs%1$s' . $this->relationAccountContact->getName() . '_Accounts.php', DIRECTORY_SEPARATOR); $contactAccountRelInAccountVardefExtensions = sprintf('custom%1$sExtension%1$smodules%1$sAccounts%1$sExt%1$sVardefs%1$s' . $this->relationContactAccount->getName() . '_Accounts.php', DIRECTORY_SEPARATOR); $leadAccountRelInAccountVardefExtensions = sprintf('custom%1$sExtension%1$smodules%1$sAccounts%1$sExt%1$sVardefs%1$s' . $relationLeadAccount->getName() . '_Accounts.php', DIRECTORY_SEPARATOR); $sugarfieldAccountVardefExtensions = sprintf('custom%1$sExtension%1$smodules%1$sAccounts%1$sExt%1$sVardefs%1$s' . 'sugarfield_' . $this->field->name . '.php', DIRECTORY_SEPARATOR); //call mbPackage to retrieve arrays of Files to be exported using different test parameters $accountAllExtensions = $this->mbPackage->getExtensionsListTest('Accounts', array('Accounts', 'Contacts', 'Leads')); $accountExtContacts = $this->mbPackage->getExtensionsListTest('Accounts', array('Accounts', 'Contacts')); $accountExtOnly = $this->mbPackage->getExtensionsListTest('Accounts', array('Accounts')); $contactExtWithWrongRelationship = $this->mbPackage->getExtensionsListTest('Contacts', array('')); $wrongModuleName = $this->mbPackage->getExtensionsListTest('Wrong_module_name'); // Remove relationship $deployedRelation->delete($relationLeadAccount->getName()); $deployedRelation->save(); SugarRelationshipFactory::deleteCache(); //assert that contact rels are exported when all rels were defined $this->assertContains($accountContactRelInAccountVardefExtensions, $accountAllExtensions, 'Contact Relationship should have been exported when accounts and contacts modules are exported'); //assert that contact rels are not exported when contact is not defined $this->assertNotContains($accountContactRelInAccountVardefExtensions, $accountExtOnly, 'Contact Relationship should NOT have been exported when exporting accounts only'); //assert that non relationship change is exported when no related module is defined $this->assertContains($sugarfieldAccountVardefExtensions, $accountExtOnly, 'Sugarfield change should have been exported when exporting Accounts only'); //assert only contact and Account modules are present when both contact and Accounts are defined $this->assertContains($accountContactRelInAccountVardefExtensions, $accountExtContacts, 'Accounts rels should be present when exporting Contacts and Accounts'); $this->assertContains($contactAccountRelInAccountVardefExtensions, $accountExtContacts, 'Contacts rels should be present when exporting Contacts and Accounts'); $this->assertNotContains($leadAccountRelInAccountVardefExtensions, $accountExtContacts, 'Leads rels should NOT be present when exporting Contacts and Accounts'); //assert that requesting a wrong relationship returns an empty array $this->assertInternalType('array', $contactExtWithWrongRelationship, 'array type should be returned when no relationships are exported, and no other changes exist'); $this->assertEmpty($contactExtWithWrongRelationship, 'An empty array should be returned when no relationships are exported, and no other changes exist'); //assert that requesting a wrong module name returns an empty array $this->assertInternalType('array', $wrongModuleName, 'An array type should be returned when a bad module is requested for export'); $this->assertEmpty($wrongModuleName, 'An empty array should be returned when a bad module is requested for export'); }
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); }
/** * Removes all custom relationships containing this module * * @return html output record of the files deleted */ function removeCustomRelationships() { require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php'; $out = ""; $madeChanges = false; $relationships = new DeployedRelationships($this->module); foreach ($relationships->getRelationshipList() as $relationshipName) { $rel = $relationships->get($relationshipName)->getDefinition(); if ($rel['is_custom'] || isset($rel['from_studio']) && $rel['from_studio']) { $relationships->delete($relationshipName); $out .= "Removed relationship {$relationshipName}<br/>"; } } if ($madeChanges) { $relationships->save(); } return $out; }
/** * 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']); } }