Esempio 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();
 }
 protected function repairDictionary()
 {
     $this->df->buildCache($this->modulename);
     VardefManager::clearVardef();
     VardefManager::refreshVardefs($this->modulename, $this->objectname);
     $this->seed->field_defs = $GLOBALS['dictionary'][$this->objectname]['fields'];
 }
Esempio n. 3
0
 public function tearDown()
 {
     global $dictionary, $bean_list;
     $dictionary = $this->old_dictionary;
     $bean_list = $this->old_bean_list;
     VardefManager::clearVardef('Accounts', 'Account');
     VardefManager::refreshVardefs('Accounts', 'Account');
 }
 public function setUp()
 {
     $beanList = array();
     $beanFiles = array();
     require 'include/modules.php';
     $GLOBALS['beanList'] = $beanList;
     $GLOBALS['beanFiles'] = $beanFiles;
     $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
     $GLOBALS['current_user']->status = 'Active';
     $GLOBALS['current_user']->is_admin = 1;
     $GLOBALS['current_user']->save();
     $this->field = get_widget('varchar');
     $this->field->id = 'Accountstest_custom_c';
     $this->field->name = 'test_custom_c';
     $this->field->vanme = 'LBL_TEST_CUSTOM_C';
     $this->field->comments = NULL;
     $this->field->help = NULL;
     $this->field->custom_module = 'Accounts';
     $this->field->type = 'varchar';
     $this->field->label = 'LBL_TEST_CUSTOM_C';
     $this->field->len = 255;
     $this->field->required = 0;
     $this->field->default_value = NULL;
     $this->field->date_modified = '2009-09-14 02:23:23';
     $this->field->deleted = 0;
     $this->field->audited = 0;
     $this->field->massupdate = 0;
     $this->field->duplicate_merge = 0;
     $this->field->reportable = 1;
     $this->field->importable = 'true';
     $this->field->ext1 = NULL;
     $this->field->ext2 = NULL;
     $this->field->ext3 = NULL;
     $this->field->ext4 = NULL;
     $this->df = new DynamicField('Accounts');
     $this->mod = new Account();
     $this->df->setup($this->mod);
     $this->df->addFieldObject($this->field);
     $this->df->buildCache('Accounts');
     VardefManager::clearVardef();
     VardefManager::refreshVardefs('Accounts', 'Account');
     $this->mod->field_defs = $GLOBALS['dictionary']['Account']['fields'];
     $this->_contact = SugarTestContactUtilities::createContact();
     $this->_account = SugarTestAccountUtilities::createAccount();
     $this->_contact->load_relationship('accounts');
     $this->_contact->accounts->add($this->_account->id);
     $this->_account->test_custom_c = 'Custom Field';
     $this->_account->save();
     $GLOBALS['db']->commit();
     // Making sure we commit any changes
 }
Esempio n. 5
0
    public function createCustom()
    {
        //create new varchar widget and associate with Accounts
        $this->custField = get_widget('varchar');
        $this->custField->id = 'Accounts' . $this->custFieldName;
        $this->custField->name = $this->custFieldName;
        $this->custField->type = 'varchar';
        $this->custField->label = 'LBL_' . strtoupper($this->custFieldName);
        $this->custField->vname = 'LBL_' . strtoupper($this->custFieldName);
        $this->custField->len = 255;
        $this->custField->custom_module = 'Accounts';
        $this->custField->required = 0;
        $this->custField->default = 'goofy';
        $this->acc = new Account();
        $this->df = new DynamicField('Accounts');
        $this->df->setup($this->acc);
        $this->df->addFieldObject($this->custField);
        $this->df->buildCache('Accounts');
        $this->custField->save($this->df);
        VardefManager::clearVardef();
        VardefManager::refreshVardefs('Accounts', 'Account');
        //Now create the meta files to make this a Calculated Field.
        $fn = $this->custFieldName;
        $extensionContent = <<<EOQ
<?php
\$dictionary['Account']['fields']['{$fn}']['duplicate_merge_dom_value']=0;
\$dictionary['Account']['fields']['{$fn}']['calculated']='true';
\$dictionary['Account']['fields']['{$fn}']['formula']='related(\$assigned_user_link,"name")';
\$dictionary['Account']['fields']['{$fn}']['enforced']='true';
\$dictionary['Account']['fields']['{$fn}']['dependency']='';
\$dictionary['Account']['fields']['{$fn}']['type']='varchar';
\$dictionary['Account']['fields']['{$fn}']['name']='{$fn}';


EOQ;
        //create custom field file
        $this->custFileDirPath = create_custom_directory($this->custFileDirPath);
        $fileLoc = $this->custFileDirPath . 'sugarfield_' . $this->custFieldName . '.php';
        file_put_contents($fileLoc, $extensionContent);
        //run repair and clear to make sure the meta gets picked up
        $_REQUEST['repair_silent'] = 1;
        $rc = new RepairAndClear();
        $rc->repairAndClearAll(array("clearAll", "rebuildExtensions"), array("Accounts"), false, false);
        $fn = $this->custFieldName;
    }
Esempio n. 6
0
 public function tearDown()
 {
     $GLOBALS['db']->dropTableName($this->_tablename . '_cstm');
     $GLOBALS['db']->query("DELETE FROM fields_meta_data WHERE id in ('Accountsbug34993_test_c', 'Accountsbug34993_test2_c')");
     if (isset($this->_old_installing)) {
         $GLOBALS['installing'] = $this->_old_installing;
     } else {
         unset($GLOBALS['installing']);
     }
     if (file_exists('custom/Extension/modules/Accounts/Ext/Vardefs/sugarfield_bug34993_test_c.php')) {
         unlink('custom/Extension/modules/Accounts/Ext/Vardefs/sugarfield_bug34993_test_c.php');
     }
     if (file_exists('custom/Extension/modules/Accounts/Ext/Vardefs/sugarfield_bug34993_test2_c.php')) {
         unlink('custom/Extension/modules/Accounts/Ext/Vardefs/sugarfield_bug34993_test2_c.php');
     }
     VardefManager::clearVardef('Accounts', 'Account');
     VardefManager::refreshVardefs('Accounts', 'Account');
 }
Esempio n. 7
0
 public function setUp()
 {
     $this->_soapURL = $GLOBALS['sugar_config']['site_url'] . '/service/v2/soap.php';
     SugarTestHelper::setUp('beanFiles');
     SugarTestHelper::setUp('beanList');
     SugarTestHelper::setUp('current_user', array(true, 1));
     $this->field = get_widget('varchar');
     $this->field->id = 'Accountstest_custom_c';
     $this->field->name = 'test_custom_c';
     $this->field->vanme = 'LBL_TEST_CUSTOM_C';
     $this->field->comments = NULL;
     $this->field->help = NULL;
     $this->field->custom_module = 'Accounts';
     $this->field->type = 'varchar';
     $this->field->label = 'LBL_TEST_CUSTOM_C';
     $this->field->len = 255;
     $this->field->required = 0;
     $this->field->default_value = NULL;
     $this->field->date_modified = '2009-09-14 02:23:23';
     $this->field->deleted = 0;
     $this->field->audited = 0;
     $this->field->massupdate = 0;
     $this->field->duplicate_merge = 0;
     $this->field->reportable = 1;
     $this->field->importable = 'true';
     $this->field->ext1 = NULL;
     $this->field->ext2 = NULL;
     $this->field->ext3 = NULL;
     $this->field->ext4 = NULL;
     $this->df = new DynamicField('Accounts');
     $this->mod = new Account();
     $this->df->setup($this->mod);
     $this->df->addFieldObject($this->field);
     $this->df->buildCache('Accounts');
     VardefManager::clearVardef();
     VardefManager::refreshVardefs('Accounts', 'Account');
     $this->mod->field_defs = $GLOBALS['dictionary']['Account']['fields'];
     $this->_account = SugarTestAccountUtilities::createAccount();
     $this->_account->test_custom_c = 'Custom Field';
     $this->_account->save();
     $GLOBALS['db']->commit();
     // Making sure we commit any changes
     parent::setUp();
 }
Esempio n. 8
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     global $beanList;
     foreach ($beanList as $bean => $class) {
         $this->modules[strtolower($bean)] = $bean;
     }
     $needClearCache = false;
     foreach ($beanList as $bean => $class) {
         VardefManager::refreshVardefs($bean, $class);
         $seed = BeanFactory::getBean($bean);
         if ($seed instanceof SugarBean) {
             if (!$this->checkBean($seed)) {
                 SugarRelationshipFactory::rebuildCache();
                 $needClearCache = true;
             }
         }
     }
     if ($needClearCache) {
         $this->cleanCache();
     }
 }
Esempio n. 9
0
/**
 * fix_dropdown_list
 * This method attempts to fix dropdown lists that were incorrectly named.
 * There were versions of SugarCRM that did not enforce naming convention rules
 * for the dropdown list field name.  This method attempts to resolve that by
 * fixing the language files that may have been affected and then updating the
 * fields_meta_data table accordingly.  It also refreshes any vardefs that may
 * have been affected.
 *
 */
function fix_dropdown_list()
{
    if (file_exists('custom/include/language')) {
        $files = array();
        $affected_modules = array();
        $affected_keys = array();
        getFiles($files, 'custom/include/language', '/\\.php$/i');
        foreach ($files as $file) {
            if (file_exists($file . '.bak')) {
                $bak_mod_time = filemtime($file . '.bak');
                $php_mod_time = filemtime($file);
                //We're saying if the .php file was modified 30 seconds no more than php.bak file then we
                //run these additional cleanup checks
                if ($php_mod_time - $bak_mod_time < 30) {
                    $app_list_strings = array();
                    $GLOBALS['app_list_strings'] = array();
                    require $file . '.bak';
                    $bak_app_list_strings = array_merge($app_list_strings, $GLOBALS['app_list_strings']);
                    $app_list_strings = array();
                    $GLOBALS['app_list_strings'] = array();
                    require $file;
                    $php_app_list_strings = array_merge($app_list_strings, $GLOBALS['app_list_strings']);
                    //Get the file contents
                    $contents = file_get_contents($file);
                    //Now simulate a fix for the file before we compare w/ the .php file
                    //we also append to the $contents
                    foreach ($bak_app_list_strings as $key => $entry) {
                        if (preg_match('/([^A-Za-z_])/', $key, $matches) && is_array($entry)) {
                            $new_key = preg_replace('/[^A-Za-z_]/', '_', $key);
                            $bak_app_list_strings[$new_key] = $bak_app_list_strings[$key];
                            unset($bak_app_list_strings[$key]);
                            //Now if the entry doesn't exists in the .php file, then add to contents
                            if (!isset($php_app_list_strings[$new_key])) {
                                $contents .= "\n\$GLOBALS['app_list_strings']['{$new_key}'] = " . var_export_helper($bak_app_list_strings[$new_key]) . ";";
                            }
                        }
                        //if
                    }
                    //foreach
                    //Now load the .php file to do the comparison
                    foreach ($php_app_list_strings as $key => $entry) {
                        if (isset($bak_app_list_strings[$key])) {
                            $diff = array_diff($bak_app_list_strings[$key], $entry);
                            if (!empty($diff)) {
                                //There is a difference, so copy the $bak_app_list_strings version into the .php file
                                $contents .= "\n\$GLOBALS['app_list_strings']['{$key}'] = " . var_export_helper($bak_app_list_strings[$key]) . ";";
                            }
                            //if
                        }
                        //if
                    }
                    //foreach
                    //Now write out the file contents
                    //Create backup just in case
                    copy($file, $file . '.php_bak');
                    $fp = @sugar_fopen($file, 'w');
                    if ($fp) {
                        fwrite($fp, $contents);
                        fclose($fp);
                    } else {
                        $GLOBALS['log']->error("Unable to update file contents in fix_dropdown_list for {$file}");
                    }
                    //if-else
                }
            }
            unset($GLOBALS['app_strings']);
            unset($GLOBALS['app_list_strings']);
            $app_list_strings = array();
            require $file;
            $touched = false;
            $contents = file_get_contents($file);
            if (!isset($GLOBALS['app_list_strings'])) {
                $GLOBALS['app_list_strings'] = $app_list_strings;
            } else {
                $GLOBALS['app_list_strings'] = array_merge($app_list_strings, $GLOBALS['app_list_strings']);
            }
            if (isset($GLOBALS['app_list_strings']) && is_array($GLOBALS['app_list_strings'])) {
                foreach ($GLOBALS['app_list_strings'] as $key => $entry) {
                    if (preg_match('/([^A-Za-z_])/', $key, $matches) && is_array($entry)) {
                        $result = $GLOBALS['db']->query("SELECT custom_module FROM fields_meta_data WHERE ext1 = '{$key}'");
                        if (!empty($result)) {
                            while ($row = $GLOBALS['db']->fetchByAssoc($result)) {
                                $custom_module = $row['custom_module'];
                                if (!empty($GLOBALS['beanList'][$custom_module])) {
                                    $affected_modules[$custom_module] = $GLOBALS['beanList'][$custom_module];
                                }
                            }
                            //while
                        }
                        //Replace all invalid characters with '_' character
                        $new_key = preg_replace('/[^A-Za-z_]/', '_', $key);
                        $affected_keys[$key] = $new_key;
                        $GLOBALS['app_list_strings'][$new_key] = $GLOBALS['app_list_strings'][$key];
                        unset($GLOBALS['app_list_strings'][$key]);
                        $pattern_match = "/(\\[\\s*\\'{$key}\\'\\s*\\])/";
                        $new_key = "['{$new_key}']";
                        $out = preg_replace($pattern_match, $new_key, $contents);
                        $contents = $out;
                        $touched = true;
                    }
                    //if
                }
                //foreach
                //This is a check for g => h instances where the file contents were incorrectly written
                //and also fixes the scenario where via a UI upgrade, the app_list_strings were incorrectly
                //merged with app_list_strings variables declared elsewhere
                if (!$touched) {
                    if (preg_match('/\\$GLOBALS\\s*\\[\\s*[\\"|\']app_list_strings[\\"|\']\\s*\\]\\s*=\\s*array\\s*\\(/', $contents)) {
                        //Now also remove all the non-custom labels that were added
                        if (preg_match('/language\\/([^\\.]+)\\.lang\\.php$/', $file, $matches)) {
                            $language = $matches[1];
                            $app_list_strings = array();
                            if (file_exists("include/language/{$language}.lang.php")) {
                                include "include/language/{$language}.lang.php";
                            }
                            if (file_exists("include/language/{$language}.lang.override.php")) {
                                $app_list_strings = _mergeCustomAppListStrings("include/language/{$language}.lang.override.php", $app_list_strings);
                            }
                            if (file_exists("custom/application/Ext/Language/{$language}.ext.lang.php")) {
                                $app_list_strings = _mergeCustomAppListStrings("custom/application/Ext/Language/{$language}.ext.lang.php", $app_list_strings);
                            }
                            if (file_exists("custom/application/Ext/Language/{$language}.lang.ext.php")) {
                                $app_list_strings = _mergeCustomAppListStrings("custom/application/Ext/Language/{$language}.lang.ext.php", $app_list_strings);
                            }
                            $all_non_custom_include_language_strings = $app_strings;
                            $all_non_custom_include_language_list_strings = $app_list_strings;
                            $unset_keys = array();
                            if (!empty($GLOBALS['app_list_strings'])) {
                                foreach ($GLOBALS['app_list_strings'] as $key => $value) {
                                    $diff = array();
                                    if (isset($all_non_custom_include_language_list_strings[$key])) {
                                        $diff = array_diff($all_non_custom_include_language_list_strings[$key], $GLOBALS['app_list_strings'][$key]);
                                    }
                                    if (!empty($all_non_custom_include_language_list_strings[$key]) && empty($diff)) {
                                        $unset_keys[] = $key;
                                    }
                                }
                            }
                            foreach ($unset_keys as $key) {
                                unset($GLOBALS['app_list_strings'][$key]);
                            }
                            if (!empty($GLOBALS['app_strings'])) {
                                foreach ($GLOBALS['app_strings'] as $key => $value) {
                                    if (!empty($all_non_custom_include_language_strings[$key])) {
                                        unset($GLOBALS['app_strings'][$key]);
                                    }
                                }
                            }
                        }
                        //if(preg_match...)
                        $out = "<?php \n";
                        if (!empty($GLOBALS['app_strings'])) {
                            foreach ($GLOBALS['app_strings'] as $key => $entry) {
                                $out .= "\n\$GLOBALS['app_strings']['{$key}']=" . var_export_helper($entry) . ";";
                            }
                        }
                        foreach ($GLOBALS['app_list_strings'] as $key => $entry) {
                            $out .= "\n\$GLOBALS['app_list_strings']['{$key}']=" . var_export_helper($entry) . ";";
                        }
                        //foreach
                        $touched = true;
                    }
                    //if(preg_match...)
                }
                //if(!$touched)
                if ($touched) {
                    //Create a backup just in case
                    copy($file, $file . '.bak');
                    $fp = @sugar_fopen($file, 'w');
                    if ($fp) {
                        fwrite($fp, $out);
                        fclose($fp);
                    } else {
                        //If we can't update the file, just return
                        $GLOBALS['log']->error("Unable to update file contents in fix_dropdown_list.");
                        return;
                    }
                }
                //if($touched)
            }
            //if
        }
        //foreach($files)
        //Update db entries (the order matters here... need to process database changes first)
        if (!empty($affected_keys)) {
            foreach ($affected_keys as $old_key => $new_key) {
                $GLOBALS['db']->query("UPDATE fields_meta_data SET ext1 = '{$new_key}' WHERE ext1 = '{$old_key}'");
            }
        }
        //Update vardef files for affected modules
        if (!empty($affected_modules)) {
            foreach ($affected_modules as $module => $object) {
                VardefManager::refreshVardefs($module, $object);
            }
        }
    }
}
Esempio n. 10
0
 /**
  * load the vardefs for a given module and object
  * @param string $module the given module we want to load the vardefs for
  * @param string $object the given object we wish to load the vardefs for
  * @param bool   $refresh whether or not we wish to refresh the cache file.
  */
 static function loadVardef($module, $object, $refresh = false, $params = array())
 {
     //here check if the cache file exists, if it does then load it, if it doesn't
     //then call refreshVardef
     //if either our session or the system is set to developerMode then refresh is set to true
     if (inDeveloperMode() || !empty($_SESSION['developerMode'])) {
         $refresh = true;
     }
     // Retrieve the vardefs from cache.
     $key = "VardefManager.{$module}.{$object}";
     if (!$refresh) {
         $return_result = sugar_cache_retrieve($key);
         $return_result = self::applyGlobalAccountRequirements($return_result);
         if (!empty($return_result)) {
             $GLOBALS['dictionary'][$object] = $return_result;
             return;
         }
     }
     // Some of the vardefs do not correctly define dictionary as global.  Declare it first.
     global $dictionary;
     if (empty($GLOBALS['dictionary'][$object]) || $refresh) {
         //if the consumer has demanded a refresh or the cache/modules... file
         //does not exist, then we should do out and try to reload things
         $cachedfile = sugar_cached('modules/') . $module . '/' . $object . 'vardefs.php';
         if ($refresh || !file_exists($cachedfile)) {
             VardefManager::refreshVardefs($module, $object, null, true, $params);
         }
         //at this point we should have the cache/modules/... file
         //which was created from the refreshVardefs so let's try to load it.
         if (file_exists($cachedfile)) {
             if (is_readable($cachedfile)) {
                 include $cachedfile;
             }
             // now that we hae loaded the data from disk, put it in the cache.
             if (!empty($GLOBALS['dictionary'][$object])) {
                 $GLOBALS['dictionary'][$object] = self::applyGlobalAccountRequirements($GLOBALS['dictionary'][$object]);
                 sugar_cache_put($key, $GLOBALS['dictionary'][$object]);
             }
         }
     }
 }
Esempio n. 11
0
 /**
  * Deletes the field from fields_meta_data and drops the database column then it rebuilds the cache
  * Use the widgets get_db_modify_alter_table() method to get the table sql - some widgets do not need any custom table modifications
  * @param STRING $name - field name
  */
 function deleteField($widget)
 {
     require_once 'modules/DynamicFields/templates/Fields/TemplateField.php';
     global $beanList;
     if (!$widget instanceof TemplateField) {
         $field_name = $widget;
         $widget = new TemplateField();
         $widget->name = $field_name;
     }
     $object_name = $beanList[$this->module];
     //Some modules like cases have a bean name that doesn't match the object name
     if (empty($GLOBALS['dictionary'][$object_name])) {
         $newName = BeanFactory::getObjectName($this->module);
         $object_name = $newName != false ? $newName : $object_name;
     }
     $GLOBALS['db']->query("DELETE FROM fields_meta_data WHERE id='" . $this->module . $widget->name . "'");
     $sql = $widget->get_db_delete_alter_table($this->bean->table_name . "_cstm");
     if (!empty($sql)) {
         $GLOBALS['db']->query($sql);
     }
     $this->removeVardefExtension($widget);
     VardefManager::clearVardef();
     VardefManager::refreshVardefs($this->module, $object_name);
 }
Esempio n. 12
0
 /**
  * Deletes the field from fields_meta_data and drops the database column then it rebuilds the cache
  * Use the widgets get_db_modify_alter_table() method to get the table sql - some widgets do not need any custom table modifications
  * @param STRING $name - field name
  */
 function deleteField($widget)
 {
     require_once 'modules/DynamicFields/templates/Fields/TemplateField.php';
     global $beanList;
     if (!$widget instanceof TemplateField) {
         $field_name = $widget;
         $widget = new TemplateField();
         $widget->name = $field_name;
     }
     $object_name = $beanList[$this->module];
     if ($object_name == 'aCase') {
         $object_name = 'Case';
     }
     $GLOBALS['db']->query("DELETE FROM fields_meta_data WHERE id='" . $this->module . $widget->name . "'");
     $sql = $widget->get_db_delete_alter_table($this->bean->table_name . "_cstm");
     if (!empty($sql)) {
         $GLOBALS['db']->query($sql);
     }
     $this->removeVardefExtension($widget);
     VardefManager::clearVardef();
     VardefManager::refreshVardefs($this->module, $object_name);
 }
Esempio n. 13
0
 /**
  * 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;
 }
Esempio n. 14
0
 /**
  * Refreshes vardefs for modules that are affected by a change during installation.
  *
  * @param array $modules List of modules to refresh vardefs for
  */
 protected function clearAffectedVardefsCache($modules = array())
 {
     foreach ($modules as $module) {
         $obj = BeanFactory::getObjectName($module);
         VardefManager::refreshVardefs($module, $obj);
     }
 }
Esempio n. 15
0
 public function setUp()
 {
     SugarTestHelper::setUp('current_user', array(true, 1));
     SugarTestHelper::setUp('beanFiles');
     SugarTestHelper::setUp('beanList');
     SugarTestHelper::setUp('app_list_strings');
     SugarTestHelper::setUp('app_strings');
     $_REQUEST = $this->keys;
     $_REQUEST['view_module'] = "Accounts";
     $_REQUEST['lhs_module'] = "Accounts";
     $_REQUEST['rhs_module'] = "Contacts";
     $_REQUEST['lhs_label'] = "Accounts";
     $_REQUEST['rhs_label'] = "Contacts";
     $relationAccountContact = new DeployedRelationships($_REQUEST['view_module']);
     $this->relationAccountContact = $relationAccountContact->addFromPost();
     $relationAccountContact->save();
     $relationAccountContact->build();
     $_REQUEST['view_module'] = "Contacts";
     $_REQUEST['lhs_module'] = "Contacts";
     $_REQUEST['rhs_module'] = "Accounts";
     $_REQUEST['lhs_label'] = "Contacts";
     $_REQUEST['rhs_label'] = "Accounts";
     $relationContactAccount = new DeployedRelationships($_REQUEST['view_module']);
     $this->relationContactAccount = $relationContactAccount->addFromPost();
     $relationContactAccount->save();
     $relationContactAccount->build();
     SugarTestHelper::setUp('relation', array('Contacts', 'Accounts'));
     //create a new field for accounts
     $this->field = get_widget('varchar');
     $this->field->id = 'Accountstest_45339333_c';
     $this->field->name = 'test_45339333_c';
     $this->field->vname = 'LBL_TEST_CUSTOM_C';
     $this->field->help = NULL;
     $this->field->custom_module = 'Accounts';
     $this->field->type = 'varchar';
     $this->field->label = 'LBL_TEST_CUSTOM_C';
     $this->field->len = 255;
     $this->field->required = 0;
     $this->field->default_value = NULL;
     $this->field->date_modified = '2012-10-31 02:23:23';
     $this->field->deleted = 0;
     $this->field->audited = 0;
     $this->field->massupdate = 0;
     $this->field->duplicate_merge = 0;
     $this->field->reportable = 1;
     $this->field->importable = 'true';
     $this->field->ext1 = NULL;
     $this->field->ext2 = NULL;
     $this->field->ext3 = NULL;
     $this->field->ext4 = NULL;
     //add field to metadata
     $this->df = new DynamicField('Accounts');
     $this->df->setup(new Account());
     $this->df->addFieldObject($this->field);
     $this->df->buildCache('Accounts');
     VardefManager::clearVardef();
     VardefManager::refreshVardefs('Accounts', 'Account');
     $this->mbPackage = new Bug45339MBPackageMock($this->packName);
 }
Esempio n. 16
0
/**
 * This function retrieves a module's language file and returns the array of strings included.
 *
 * @param string $language specific language to load
 * @param string $module module name to load strings for
 * @param bool $refresh optional, true if you want to rebuild the language strings
 * @return array lang strings
 */
function return_module_language($language, $module, $refresh = false)
{
    global $mod_strings;
    global $sugar_config;
    global $currentModule;
    // Jenny - Bug 8119: Need to check if $module is not empty
    if (empty($module)) {
        $stack = debug_backtrace();
        $GLOBALS['log']->warn("Variable module is not in return_module_language " . var_export($stack, true));
        return array();
    }
    if (!$refresh) {
        $cache_key = LanguageManager::getLanguageCacheKey($module, $language);
        // Check for cached value
        $cache_entry = sugar_cache_retrieve($cache_key);
        if (!empty($cache_entry)) {
            return $cache_entry;
        }
    }
    // Store the current mod strings for later
    $temp_mod_strings = $mod_strings;
    $loaded_mod_strings = array();
    $language_used = $language;
    $default_language = $sugar_config['default_language'];
    if (empty($language)) {
        $language = $default_language;
    }
    // Bug 21559 - So we can get all the strings defined in the template, refresh
    // the vardefs file if the cached language file doesn't exist.
    if (!file_exists($GLOBALS['sugar_config']['cache_dir'] . 'modules/' . $module . '/language/' . $language . '.lang.php') && !empty($GLOBALS['beanList'][$module])) {
        $object = $GLOBALS['beanList'][$module];
        if ($object == 'aCase') {
            $object = 'Case';
        }
        VardefManager::refreshVardefs($module, $object);
    }
    $loaded_mod_strings = LanguageManager::loadModuleLanguage($module, $language, $refresh);
    // cn: bug 6048 - merge en_us with requested language
    if ($language != $sugar_config['default_language']) {
        $loaded_mod_strings = sugarArrayMerge(LanguageManager::loadModuleLanguage($module, $sugar_config['default_language'], $refresh), $loaded_mod_strings);
    }
    // Load in en_us strings by default
    if ($language != 'en_us' && $sugar_config['default_language'] != 'en_us') {
        $loaded_mod_strings = sugarArrayMerge(LanguageManager::loadModuleLanguage($module, 'en_us', $refresh), $loaded_mod_strings);
    }
    // If we are in debug mode for translating, turn on the prefix now!
    if ($sugar_config['translation_string_prefix']) {
        foreach ($loaded_mod_strings as $entry_key => $entry_value) {
            $loaded_mod_strings[$entry_key] = $language_used . ' ' . $entry_value;
        }
    }
    $return_value = $loaded_mod_strings;
    if (!isset($mod_strings)) {
        $mod_strings = $return_value;
    } else {
        $mod_strings = $temp_mod_strings;
    }
    $cache_key = LanguageManager::getLanguageCacheKey($module, $language);
    sugar_cache_put($cache_key, $return_value);
    return $return_value;
}
Esempio n. 17
0
 /**
  * load the vardefs for a given module and object
  * @param string $module the given module we want to load the vardefs for
  * @param string $object the given object we wish to load the vardefs for
  * @param bool   $refresh whether or not we wish to refresh the cache file.
  */
 static function loadVardef($module, $object, $refresh = false, $params = array())
 {
     if (empty($module) || empty($object)) {
         return;
     }
     $GLOBALS['log']->debug("VardefManager::loadVardef called for module: {$module}");
     if (empty($params['ignore_rel_calc_fields']) && !empty($GLOBALS['dictionary'][$object]) && !isset($GLOBALS['dictionary'][$object]['related_calc_fields'])) {
         $refresh = true;
     }
     // Some of the vardefs do not correctly define dictionary as global.  Declare it first.
     global $dictionary;
     if (empty($GLOBALS['dictionary'][$object]) || $refresh || !isset($GLOBALS['dictionary'][$object]['fields'])) {
         //if the consumer has demanded a refresh or the cache/modules... file
         //does not exist, then we should do out and try to reload things
         $cachedfile = self::getCacheFileName($module, $object);
         if ($refresh || !file_exists($cachedfile)) {
             VardefManager::refreshVardefs($module, $object, null, true, $params);
         }
         //at this point we should have the cache/modules/... file
         //which was created from the refreshVardefs so let's try to load it.
         if (file_exists($cachedfile)) {
             @(include $cachedfile);
             // now that we have loaded the data from disk, load it in the global dictionary
             if (!empty($GLOBALS['dictionary'][$object])) {
                 $GLOBALS['dictionary'][$object] = self::applyGlobalAccountRequirements($GLOBALS['dictionary'][$object]);
             }
         }
     }
 }