Ejemplo n.º 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();
 }
Ejemplo n.º 2
0
 /**
  * @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');
 }
Ejemplo n.º 3
0
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);
}
 /**
  * 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']);
     }
 }