/** * @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'); }
public static function delete_cache() { $filename = Relationship::cache_file_dir() . '/' . Relationship::cache_file_name_only(); if (file_exists($filename)) { unlink($filename); } require_once "data/Relationships/RelationshipFactory.php"; SugarRelationshipFactory::deleteCache(); }
function install_relationships() { if (isset($this->installdefs['relationships'])) { $this->log(translate('LBL_MI_IN_RELATIONSHIPS')); $str = "<?php \n //WARNING: The contents of this file are auto-generated\n"; $save_table_dictionary = false; if (!file_exists("custom/Extension/application/Ext/TableDictionary")) { mkdir_recursive("custom/Extension/application/Ext/TableDictionary", true); } foreach ($this->installdefs['relationships'] as $key => $relationship) { $filename = basename($relationship['meta_data']); $this->copy_path($relationship['meta_data'], 'custom/metadata/' . $filename); $this->install_relationship('custom/metadata/' . $filename); $save_table_dictionary = true; if (!empty($relationship['module_vardefs'])) { $relationship['module_vardefs'] = str_replace('<basepath>', $this->base_dir, $relationship['module_vardefs']); $this->install_vardef($relationship['module_vardefs'], $relationship['module']); } if (!empty($relationship['module_layoutdefs'])) { $relationship['module_layoutdefs'] = str_replace('<basepath>', $this->base_dir, $relationship['module_layoutdefs']); $this->install_layoutdef($relationship['module_layoutdefs'], $relationship['module']); } $relName = strpos($filename, "MetaData") !== false ? substr($filename, 0, strlen($filename) - 12) : $filename; $out = sugar_fopen("custom/Extension/application/Ext/TableDictionary/{$relName}.php", 'w'); fwrite($out, $str . "include('custom/metadata/{$filename}');\n\n?>"); fclose($out); } Relationship::delete_cache(); $this->rebuild_vardefs(); $this->rebuild_layoutdefs(); if ($save_table_dictionary) { $this->rebuild_tabledictionary(); } require_once "data/Relationships/RelationshipFactory.php"; SugarRelationshipFactory::deleteCache(); } }
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); } }
function action_DeleteRelationship() { if (isset($_REQUEST['relationship_name'])) { if (empty($_REQUEST['view_package'])) { require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php'; if (!empty($_REQUEST['remove_tables'])) { $GLOBALS['mi_remove_tables'] = $_REQUEST['remove_tables']; } $relationships = new DeployedRelationships($_REQUEST['view_module']); } else { $mb = new ModuleBuilder(); $module =& $mb->getPackageModule($_REQUEST['view_package'], $_REQUEST['view_module']); require_once 'modules/ModuleBuilder/parsers/relationships/UndeployedRelationships.php'; $relationships = new UndeployedRelationships($module->getModuleDir()); } $relationships->delete($_REQUEST['relationship_name']); $relationships->save(); require_once "data/Relationships/RelationshipFactory.php"; SugarRelationshipFactory::deleteCache(); } $this->view = 'relationships'; }
/** * 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; }
public function action_DeleteRelationship() { if (isset($_REQUEST['relationship_name'])) { if (empty($_REQUEST['view_package'])) { if (!empty($_REQUEST['remove_tables'])) { $GLOBALS['mi_remove_tables'] = $_REQUEST['remove_tables']; } $relationships = new DeployedRelationships($_REQUEST['view_module']); } else { $mb = new ModuleBuilder(); $module =& $mb->getPackageModule($_REQUEST['view_package'], $_REQUEST['view_module']); $relationships = new UndeployedRelationships($module->getModuleDir()); } $relationships->delete($_REQUEST['relationship_name']); $relationships->save(); SugarRelationshipFactory::deleteCache(); } $this->view = 'relationships'; }
public static function delete_cache() { $filename = Relationship::cache_file_dir() . '/' . Relationship::cache_file_name_only(); if (file_exists($filename)) { unlink($filename); } SugarRelationshipFactory::deleteCache(); // Delete the internal cache as well self::$relCacheInternal = array(); }
/** * Find links with wrong relationship. * @param DefinitionObject $fieldDefs * @param SugarBean $seed * @return array Wrong relationships. */ protected function checkFieldsRelationships($fieldDefs, $seed) { $wrongRelations = array(); foreach ($fieldDefs as $fieldnm => $field) { // Check for bad links if ($field['type'] == 'link') { $seed->load_relationship($field['name']); $wRel = false; if (empty($seed->{$field}['name'])) { $wRel = true; } else { if ($this->checkRelationshipDef($field['name'], $seed)) { // Need to delete cache of TableDictionary to avoid inclusion of deleted files. if (file_exists('custom/application/Ext/TableDictionary/tabledictionary.ext.php')) { SugarAutoLoader::unlink('custom/application/Ext/TableDictionary/tabledictionary.ext.php'); } SugarRelationshipFactory::deleteCache(); SugarRelationshipFactory::rebuildCache(); unset($seed->{$field}['name']); $seed->load_relationship($field['name']); } $relModule = $seed->{$field}['name']->getRelatedModuleName(); $relBean = $this->getBean($relModule); if (empty($relBean)) { $wRel = true; } } if ($wRel) { if (!empty($field['relationship'])) { $wrongRelations[] = $field['relationship']; } $fieldDefs->setWrongDef($fieldnm); } } } return $wrongRelations; }
/** * 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']); } }