public function run() { // this always needs to be ran // get the get_widget helper and the StandardField Helper require_once 'modules/DynamicFields/FieldCases.php'; require_once 'modules/ModuleBuilder/parsers/StandardField.php'; // we are working with opportunities $bean = BeanFactory::getBean('Opportunities'); // get the field defs $field_defs = $bean->getFieldDefinition('sales_stage'); // load the field type up $f = get_widget($field_defs['type']); // populate the row from the vardefs that were loaded $f->populateFromRow($field_defs); $this->log('Current Sales Stage Default is: ' . var_export($f->default, true)); // lets always make sure that the default is in the list of options if (isset($f->options) && isset($GLOBALS['app_list_strings'][$f->options])) { if (!in_array($f->default, array_keys($GLOBALS['app_list_strings'][$f->options]))) { $this->log(var_export($f->default, true) . ' Is Not In The List Of Options'); $f->default = array_shift(array_keys($GLOBALS['app_list_strings'][$f->options])); $f->default_value = array_shift(array_keys($GLOBALS['app_list_strings'][$f->options])); $this->log('New Sales Stage Default Is: ' . var_export($f->default, true)); // save the changes to the field $df = new StandardField($bean->module_name); $df->setup($bean); $f->module = $bean; $f->save($df); } } }
protected function fixRollupFormulas() { $oldFormula = 'rollupCurrencySum($revenuelineitems, "{{field}}")'; $newFormula = 'rollupConditionalSum($revenuelineitems, "{{field}}", "sales_stage", forecastSalesStages(true, false))'; // the field set we need $fields = array('best_case' => 'best_case', 'amount' => 'likely_case', 'worst_case' => 'worst_case'); // get the get_widget helper and the StandardField Helper SugarAutoLoader::load('modules/DynamicFields/FieldCases.php'); SugarAutoLoader::load('modules/ModuleBuilder/parsers/StandardField.php'); // we are working with opportunities $bean = BeanFactory::getBean('Opportunities'); // loop over each field foreach ($fields as $field => $rollup_field) { // get the field defs $field_defs = $bean->getFieldDefinition($field); // load the field type up $f = get_widget($field_defs['type']); // populate the row from the vardefs that were loaded $f->populateFromRow($field_defs); if ($f->formula == str_replace('{{field}}', $rollup_field, $oldFormula)) { $f->formula = str_replace('{{field}}', $rollup_field, $newFormula); // now lets save, since these are OOB field, we use StandardField $df = new StandardField($bean->module_name); $df->setup($bean); $f->module = $bean; $f->save($df); } } // lets fix up the data now to excluded closed lost $this->fixRollupAmountsToExcludeClosedLostValues(); }
public function run() { if (!$this->toFlavor('ent') && !$this->toFlavor('ult') || !version_compare($this->from_version, '7.0', '<')) { return; } $settings = Opportunity::getSettings(); if ($settings['opps_view_by'] !== 'RevenueLineItems') { $this->log('Not using Revenue Line Items; Skipping Upgrade Script'); return; } // get the get_widget helper and the StandardField Helper require_once 'modules/DynamicFields/FieldCases.php'; require_once 'modules/ModuleBuilder/parsers/StandardField.php'; // we are working with opportunities $module = 'Opportunities'; $bean = BeanFactory::getBean('Opportunities'); // the field set we need $fields = array('best_case', 'amount', 'worst_case', 'date_closed'); // loop over each field foreach ($fields as $field) { // get the field defs $field_defs = $bean->getFieldDefinition($field); // load the field type up $f = get_widget($field_defs['type']); // populate the row from the vardefs that were loaded $f->populateFromRow($field_defs); // lets make sure that the calculated is true $f->calculated = true; // now lets save, since these are OOB field, we use StandardField $df = new StandardField($module); $df->setup($bean); $f->module = $bean; $f->save($df); } }
function action_saveSugarField() { global $mod_strings; require_once 'modules/DynamicFields/FieldCases.php'; $field = get_widget($_REQUEST['type']); $_REQUEST['name'] = trim($_POST['name']); $field->populateFromPost(); require_once 'modules/ModuleBuilder/parsers/StandardField.php'; $module = $_REQUEST['view_module']; // Need to map Employees -> Users if ($module == 'Employees') { $module = 'Users'; } $df = new StandardField($module); $mod = BeanFactory::getBean($module); $class_name = $GLOBALS['beanList'][$module]; $df->setup($mod); $field->module = $mod; $field->save($df); $this->action_SaveLabel(); $MBmodStrings = $mod_strings; $GLOBALS['mod_strings'] = return_module_language('', 'Administration'); include_once 'modules/Administration/QuickRepairAndRebuild.php'; $GLOBALS['mod_strings']['LBL_ALL_MODULES'] = 'all_modules'; $_REQUEST['execute_sql'] = true; require_once 'ModuleInstall/ModuleInstaller.php'; $mi = new ModuleInstaller(); $mi->silent = true; $mi->rebuild_extensions(); $repair = new RepairAndClear(); $repair->repairAndClearAll(array('clearVardefs', 'clearTpls'), array($class_name), true, false); //#28707 ,clear all the js files in cache $repair->module_list = array(); $repair->clearJsFiles(); // now clear the cache so that the results are immediately visible include_once 'include/TemplateHandler/TemplateHandler.php'; TemplateHandler::clearCache($module); if ($module == 'Users') { TemplateHandler::clearCache('Employees'); } $GLOBALS['mod_strings'] = $MBmodStrings; }
/** * @param DynamicField $df */ function delete($df) { //If a dropdown uses the field that is being delted as a parent dropdown, we need to remove that dependency $seed = BeanFactory::getBean($df->getModuleName()); if ($seed) { $fields = $seed->field_defs; foreach ($fields as $field => $def) { if (!empty($def['visibility_grid']['trigger']) && $def['visibility_grid']['trigger'] == $this->name) { $field = get_widget($def['type']); unset($def['visibility_grid']); $field->populateFromRow($def); if (isset($def['source']) && $def['source'] == "custom_fields") { $field->save($df); } else { //Out of the box field that we need to use a StandardField rather than DynamicFIeld object to save require_once 'modules/ModuleBuilder/parsers/StandardField.php'; $sf = new StandardField($df->getModuleName()); $sf->setup($seed); $field->module = $seed; $field->save($sf); } } } } parent::delete($df); }
public function action_saveSugarField() { global $mod_strings; $field = get_widget($_REQUEST['type']); $_REQUEST['name'] = trim($_POST['name']); $field->populateFromPost(); $module = $_REQUEST['view_module']; $df = new StandardField($module); $mod = BeanFactory::getBean($module); $obj = BeanFactory::getObjectName($module); $df->setup($mod); $field->module = $mod; $field->save($df); $this->action_SaveLabel(); $MBmodStrings = $mod_strings; $GLOBALS['mod_strings'] = return_module_language('', 'Administration'); include_once 'modules/Administration/QuickRepairAndRebuild.php'; $GLOBALS['mod_strings']['LBL_ALL_MODULES'] = 'all_modules'; $_REQUEST['execute_sql'] = true; $mi = new ModuleInstaller(); $mi->silent = true; $mi->rebuild_extensions(); $repair = new RepairAndClear(); $repair->repairAndClearAll(array('clearVardefs', 'clearTpls', 'clearSearchCache'), array($module), true, false); //#28707 ,clear all the js files in cache $repair->module_list = array(); $repair->clearJsFiles(); //Ensure the vardefs are up to date for this module before we rebuild the cache now. VardefManager::loadVardef($module, $obj, true); //Make sure to clear the vardef for related modules as well $relatedMods = array(); if (!empty($field->dependency)) { $relatedMods = array_merge($relatedMods, VardefManager::getLinkedModulesFromFormula($mod, $field->dependency)); } if (!empty($field->formula)) { $relatedMods = array_merge($relatedMods, VardefManager::getLinkedModulesFromFormula($mod, $field->formula)); } foreach ($relatedMods as $mName => $oName) { $repair->repairAndClearAll(array('clearVardefs', 'clearTpls'), array($mName), true, false); VardefManager::clearVardef($mName, $oName); } // now clear the cache so that the results are immediately visible TemplateHandler::clearCache($module); if ($module == 'Users') { TemplateHandler::clearCache('Employees'); } // Bug 59210 // Clear the metadata cache so this change can be reflected // immediately. $repair->module_list = array($module); // Sending false will only rebuild the $module section of the cache $repair->repairMetadataAPICache(false); $GLOBALS['mod_strings'] = $MBmodStrings; }
/** * Process the field vardefs as setup by the extending classes */ protected function processFields() { // get the get_widget helper and the StandardField Helper SugarAutoLoader::load('modules/DynamicFields/FieldCases.php'); SugarAutoLoader::load('modules/ModuleBuilder/parsers/StandardField.php'); foreach ($this->field_vardef_setup as $field => $new_defs) { // get the field defs $field_defs = $this->bean->getFieldDefinition($field); // load the field type up $f = get_widget($field_defs['type']); $diff = array(); foreach ($new_defs as $k => $v) { if (!isset($field_defs[$k])) { switch ($k) { case 'massupdate': case 'studio': case 'reportable': case 'workflow': if (!$v) { $diff[$k] = $v; } break; default: if ($v) { $diff[$k] = $v; } } } elseif ($field_defs[$k] != $v) { $diff[$k] = $v; } } if (empty($diff)) { continue; } // populate the row from the vardefs that were loaded and the new_defs $f->populateFromRow(array_merge($field_defs, $diff)); // now lets save, since these are OOB field, we use StandardField $df = new StandardField($this->bean->module_name); $df->setup($this->bean); $f->module = $this->bean; // StandardField considers only the attributes which can be edited in Studio, // while the "studio" attribute is not one of them. we need to change the vardef map temporarily here, // because changing it permanently will make the "studio" attribute always overridden with empty value, // after the field has been saved in Studio if (!isset($f->vardef_map['studio'])) { $f->vardef_map['studio'] = 'studio'; } $f->save($df); } }