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']; }
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(); }
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 }
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; }
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'); }
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(); }
function build() { $basepath = "custom/Extension/modules"; $this->activitiesToAdd = false; // and mark all as built so that the next time we come through we'll know and won't build again foreach ($this->relationships as $name => $relationship) { $definition = $relationship->getDefinition(); // activities will always appear on the rhs only - lhs will be always be this module in MB if (strtolower($definition['rhs_module']) == 'activities') { $this->activitiesToAdd = true; $relationshipName = $definition['relationship_name']; foreach (self::$activities as $activitiesSubModuleLower => $activitiesSubModuleName) { $definition['rhs_module'] = $activitiesSubModuleName; $definition['for_activities'] = true; $definition['relationship_name'] = $relationshipName . '_' . $activitiesSubModuleLower; $this->relationships[$definition['relationship_name']] = RelationshipFactory::newRelationship($definition); } unset($this->relationships[$name]); } } $GLOBALS['log']->info(get_class($this) . "->build(): installing relationships"); $MBModStrings = $GLOBALS['mod_strings']; $adminModStrings = return_module_language('', 'Administration'); // required by ModuleInstaller foreach ($this->relationships as $name => $relationship) { $relationship->setFromStudio(); $GLOBALS['mod_strings'] = $MBModStrings; $installDefs = parent::build($basepath, "<basepath>", array($name => $relationship)); // and mark as built so that the next time we come through we'll know and won't build again $relationship->setReadonly(); $this->relationships[$name] = $relationship; // now install the relationship - ModuleInstaller normally only does this as part of a package load where it installs the relationships defined in the manifest. However, we don't have a manifest or a package, so... // If we were to chose to just use the Extension mechanism, without using the ModuleInstaller install_...() methods, we must : // 1) place the information for each side of the relationship in the appropriate Ext directory for the module, which means specific $this->save...() methods for DeployedRelationships, and // 2) we must also manually add the relationship into the custom/application/Ext/TableDictionary/tabledictionary.ext.php file as install_relationship doesn't handle that (install_relationships which requires the manifest however does) // Relationships must be in tabledictionary.ext.php for the Admin command Rebuild Relationships to reliably work: // Rebuild Relationships looks for relationships in the modules vardefs.php, in custom/modules/<modulename>/Ext/vardefs/vardefs.ext.php, and in modules/TableDictionary.php and custom/application/Ext/TableDictionary/tabledictionary.ext.php // if the relationship is not defined in one of those four places it could be deleted during a rebuilt, or during a module installation (when RebuildRelationships.php deletes all entries in the Relationships table) // So instead of doing this, we use common save...() methods between DeployedRelationships and UndeployedRelationships that will produce installDefs, // and rather than building a full manifest file to carry them, we manually add these installDefs to the ModuleInstaller, and then // individually call the appropriate ModuleInstaller->install_...() methods to take our relationship out of our staging area and expand it out to the individual module Ext areas $GLOBALS['mod_strings'] = $adminModStrings; require_once 'ModuleInstall/ModuleInstaller.php'; $mi = new ModuleInstaller(); $mi->id_name = 'custom' . $name; // provide the moduleinstaller with a unique name for this relationship - normally this value is set to the package key... $mi->installdefs = $installDefs; $mi->base_dir = $basepath; $mi->silent = true; VardefManager::clearVardef(); $mi->install_relationships(); $mi->install_languages(); $mi->install_vardefs(); $mi->install_layoutdefs(); } // now clear all caches so that our changes are visible require_once 'modules/Administration/QuickRepairAndRebuild.php'; $rac = new RepairAndClear(); $rac->repairAndClearAll(array('clearAll'), array($GLOBALS['mod_strings']['LBL_ALL_MODULES']), true, false); $GLOBALS['mod_strings'] = $MBModStrings; // finally, restore the ModuleBuilder mod_strings // save out the updated definitions so that we keep track of the change in built status $this->save(); $GLOBALS['log']->info(get_class($this) . "->build(): finished relationship installation"); }
function repairDBForUpgrade($execute = false, $path = '') { global $current_user, $beanFiles; global $dictionary; set_time_limit(3600); $db =& DBManagerFactory::getInstance(); $sql = ''; VardefManager::clearVardef(); require_once 'include/ListView/ListView.php'; foreach ($beanFiles as $bean => $file) { require_once $file; $focus = new $bean(); $sql .= $db->repairTable($focus, $execute); } //echo $sql; $olddictionary = $dictionary; unset($dictionary); include 'modules/TableDictionary.php'; foreach ($dictionary as $meta) { $tablename = $meta['table']; $fielddefs = $meta['fields']; $indices = $meta['indices']; $sql .= $db->repairTableParams($tablename, $fielddefs, $indices, $execute); } $qry_str = ""; foreach (explode("\n", $sql) as $line) { if (!empty($line) && substr($line, -2) != "*/") { $line .= ";"; } $qry_str .= $line . "\n"; } $sql = str_replace(array("\n", '''), array('', "'"), preg_replace('#(/\\*.+?\\*/\\n*)#', '', $qry_str)); logThis("*******START EXECUTING DB UPGRADE QUERIES***************", $path); logThis($sql, $path); logThis("*******END EXECUTING DB UPGRADE QUERIES****************", $path); if (!$execute) { return $sql; } }
function install($base_dir, $is_upgrade = false, $previous_version = '') { if (defined('TEMPLATE_URL')) { SugarTemplateUtilities::disableCache(); } if (defined('MODULE_INSTALLER_PACKAGE_SCAN') && MODULE_INSTALLER_PACKAGE_SCAN || !empty($GLOBALS['sugar_config']['moduleInstaller']['packageScan'])) { $this->ms->scanPackage($base_dir); if ($this->ms->hasIssues()) { $this->ms->displayIssues(); sugar_cleanup(true); } } // workaround for bug 45812 - refresh vardefs cache before unpacking to avoid partial vardefs in cache global $beanList; foreach ($this->modules as $module_name) { if (!empty($beanList[$module_name])) { $objectName = BeanFactory::getObjectName($module_name); VardefManager::loadVardef($module_name, $objectName); } } global $app_strings, $mod_strings; $this->base_dir = $base_dir; $total_steps = 5; //minimum number of steps with no tasks $current_step = 0; $tasks = array('pre_execute', 'install_copy', 'install_extensions', 'install_images', 'install_dcactions', 'install_dashlets', 'install_connectors', 'install_layoutfields', 'install_relationships', 'enable_manifest_logichooks', 'post_execute', 'reset_opcodes'); $total_steps += count($tasks); if (file_exists($this->base_dir . '/manifest.php')) { if (!$this->silent) { $current_step++; display_progress_bar('install', $current_step, $total_steps); echo '<div id ="displayLoglink" ><a href="#" onclick="document.getElementById(\'displayLog\').style.display=\'\'">' . $app_strings['LBL_DISPLAY_LOG'] . '</a> </div><div id="displayLog" style="display:none">'; } include $this->base_dir . '/manifest.php'; if ($is_upgrade && !empty($previous_version)) { //check if the upgrade path exists if (!empty($upgrade_manifest)) { if (!empty($upgrade_manifest['upgrade_paths'])) { if (!empty($upgrade_manifest['upgrade_paths'][$previous_version])) { $installdefs = $upgrade_manifest['upgrade_paths'][$previous_version]; } else { $errors[] = 'No Upgrade Path Found in manifest.'; $this->abort($errors); } //fi } //fi } //fi } //fi $this->id_name = $installdefs['id']; $this->installdefs = $installdefs; if (!$this->silent) { $current_step++; update_progress_bar('install', $current_step, $total_steps); } foreach ($tasks as $task) { $this->{$task}(); if (!$this->silent) { $current_step++; update_progress_bar('install', $current_step, $total_steps); } } $this->install_beans($this->installed_modules); if (!$this->silent) { $current_step++; update_progress_bar('install', $total_steps, $total_steps); } if (isset($installdefs['custom_fields'])) { $this->log(translate('LBL_MI_IN_CUSTOMFIELD')); $this->install_custom_fields($installdefs['custom_fields']); } if (!$this->silent) { $current_step++; update_progress_bar('install', $current_step, $total_steps); echo '</div>'; } if (!$this->silent) { $current_step++; update_progress_bar('install', $current_step, $total_steps); echo '</div>'; } $selectedActions = array('clearTpls', 'clearJsFiles', 'clearDashlets', 'clearVardefs', 'clearJsLangFiles', 'rebuildAuditTables', 'repairDatabase'); VardefManager::clearVardef(); global $beanList, $beanFiles, $moduleList; if (file_exists('custom/application/Ext/Include/modules.ext.php')) { include 'custom/application/Ext/Include/modules.ext.php'; } require_once "modules/Administration/upgrade_custom_relationships.php"; upgrade_custom_relationships($this->installed_modules); $this->rebuild_all(true); require_once 'modules/Administration/QuickRepairAndRebuild.php'; $rac = new RepairAndClear(); $rac->repairAndClearAll($selectedActions, $this->installed_modules, true, false); $this->rebuild_relationships(); UpdateSystemTabs('Add', $this->tab_modules); //Clear out all the langauge cache files. clearAllJsAndJsLangFilesWithoutOutput(); $cache_key = 'app_list_strings.' . $GLOBALS['current_language']; sugar_cache_clear($cache_key); sugar_cache_reset(); //clear the unified_search_module.php file require_once 'modules/Home/UnifiedSearchAdvanced.php'; UnifiedSearchAdvanced::unlinkUnifiedSearchModulesFile(); $this->log('<br><b>' . translate('LBL_MI_COMPLETE') . '</b>'); } else { die("No \$installdefs Defined In {$this->base_dir}/manifest.php"); } }
function repairTables() { global $db; VardefManager::clearVardef(); $repairedTables = array(); include 'include/modules.php'; $GLOBALS['reload_vardefs'] = true; foreach ($beanList as $module => $bean) { if (empty($beanFiles[$bean])) { continue; } $file = $beanFiles[$bean]; $object = BeanFactory::getObjectName($module); writeLog("Repairing {$bean}:{$object}"); if (file_exists($file)) { require_once $file; unset($GLOBALS['dictionary'][$object]); $focus = new $bean(); if ($focus instanceof SugarBean && !isset($repairedTables[$focus->table_name])) { $db->repairTable($focus, true); $repairedTables[$focus->table_name] = true; } } } $GLOBALS['reload_vardefs'] = false; unset($dictionary); include 'modules/TableDictionary.php'; foreach ($dictionary as $meta) { if (!isset($meta['table']) || isset($repairedTables[$meta['table']])) { continue; } $tablename = $meta['table']; $fielddefs = $meta['fields']; $indices = $meta['indices']; $engine = isset($meta['engine']) ? $meta['engine'] : null; $db->repairTableParams($tablename, $fielddefs, $indices, true, $engine); $repairedTables[$tablename] = true; } }
/** * 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); }
function install($base_dir, $is_upgrade = false, $previous_version = '') { if (defined('TEMPLATE_URL')) { SugarTemplateUtilities::disableCache(); } if (!empty($GLOBALS['sugar_config']['moduleInstaller']['packageScan'])) { $this->ms->scanPackage($base_dir); if ($this->ms->hasIssues()) { $this->ms->displayIssues(); sugar_cleanup(true); } } global $app_strings, $mod_strings; $this->base_dir = $base_dir; $total_steps = 5; //minimum number of steps with no tasks $current_step = 0; $tasks = array('pre_execute', 'install_copy', 'install_images', 'install_menus', 'install_dcactions', 'install_userpage', 'install_dashlets', 'install_administration', 'install_connectors', 'install_vardefs', 'install_layoutdefs', 'install_layoutfields', 'install_relationships', 'install_languages', 'install_logichooks', 'post_execute', 'reset_opcodes'); $total_steps += count($tasks); if (file_exists($this->base_dir . '/manifest.php')) { if (!$this->silent) { $current_step++; display_progress_bar('install', $current_step, $total_steps); echo '<div id ="displayLoglink" ><a href="#" onclick="document.getElementById(\'displayLog\').style.display=\'\'">' . $app_strings['LBL_DISPLAY_LOG'] . '</a> </div><div id="displayLog" style="display:none">'; } include $this->base_dir . '/manifest.php'; if ($is_upgrade && !empty($previous_version)) { //check if the upgrade path exists if (!empty($upgrade_manifest)) { if (!empty($upgrade_manifest['upgrade_paths'])) { if (!empty($upgrade_manifest['upgrade_paths'][$previous_version])) { $installdefs = $upgrade_manifest['upgrade_paths'][$previous_version]; } else { $errors[] = 'No Upgrade Path Found in manifest.'; $this->abort($errors); } //fi } //fi } //fi } //fi $this->id_name = $installdefs['id']; $this->installdefs = $installdefs; $installed_modules = array(); $tab_modules = array(); if (isset($installdefs['beans'])) { $str = "<?php \n //WARNING: The contents of this file are auto-generated\n"; foreach ($installdefs['beans'] as $bean) { if (!empty($bean['module']) && !empty($bean['class']) && !empty($bean['path'])) { $module = $bean['module']; $class = $bean['class']; $path = $bean['path']; $str .= "\$beanList['{$module}'] = '{$class}';\n"; $str .= "\$beanFiles['{$class}'] = '{$path}';\n"; if ($bean['tab']) { $str .= "\$moduleList[] = '{$module}';\n"; $this->install_user_prefs($module, empty($bean['hide_by_default'])); $tab_modules[] = $module; } else { $str .= "\$modules_exempt_from_availability_check['{$module}'] = '{$module}';\n"; $str .= "\$modInvisList[] = '{$module}';\n"; } $installed_modules[] = $module; } else { $errors[] = 'Bean array not well defined.'; $this->abort($errors); } } $str .= "\n?>"; if (!file_exists("custom/Extension/application/Ext/Include")) { mkdir_recursive("custom/Extension/application/Ext/Include", true); } $out = sugar_fopen("custom/Extension/application/Ext/Include/{$this->id_name}.php", 'w'); fwrite($out, $str); fclose($out); $this->rebuild_modules(); } if (!$this->silent) { $current_step++; update_progress_bar('install', $current_step, $total_steps); } foreach ($tasks as $task) { $this->{$task}(); if (!$this->silent) { $current_step++; update_progress_bar('install', $current_step, $total_steps); } } $this->install_beans($installed_modules); if (!$this->silent) { $current_step++; update_progress_bar('install', $total_steps, $total_steps); } if (isset($installdefs['custom_fields'])) { $this->log(translate('LBL_MI_IN_CUSTOMFIELD')); $this->install_custom_fields($installdefs['custom_fields']); } if (!$this->silent) { $current_step++; update_progress_bar('install', $current_step, $total_steps); echo '</div>'; } if (!$this->silent) { $current_step++; update_progress_bar('install', $current_step, $total_steps); echo '</div>'; } $selectedActions = array('clearTpls', 'clearJsFiles', 'clearDashlets', 'clearVardefs', 'clearJsLangFiles', 'rebuildAuditTables', 'repairDatabase'); VardefManager::clearVardef(); global $beanList, $beanFiles, $moduleList; if (file_exists('custom/application/Ext/Include/modules.ext.php')) { include 'custom/application/Ext/Include/modules.ext.php'; } require_once "modules/Administration/upgrade_custom_relationships.php"; upgrade_custom_relationships($installed_modules); $this->rebuild_all(true); require_once 'modules/Administration/QuickRepairAndRebuild.php'; $rac = new RepairAndClear(); $rac->repairAndClearAll($selectedActions, $installed_modules, true, false); $this->rebuild_relationships(); UpdateSystemTabs('Add', $tab_modules); //clear the unified_search_module.php file require_once 'modules/Home/UnifiedSearchAdvanced.php'; UnifiedSearchAdvanced::unlinkUnifiedSearchModulesFile(); $this->log('<br><b>' . translate('LBL_MI_COMPLETE') . '</b>'); } else { die("No \$installdefs Defined In {$this->base_dir}/manifest.php"); } }
/** * 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); }
check_now(get_sugarbeat()); ob_end_clean(); logThis('End Updating the license ', $path); set_upgrade_progress('end', 'done'); logThis('Cleaning up the session. Goodbye.'); unlinkUWTempFiles(); logThis('Cleaning up the session. Goodbye.'); resetUwSession(); // flag to say upgrade has completed $_SESSION['upgrade_complete'] = true; //Clear any third party caches sugar_cache_reset_full(); //add the clean vardefs here if (!class_exists('VardefManager')) { } VardefManager::clearVardef(); require_once 'include/TemplateHandler/TemplateHandler.php'; TemplateHandler::clearAll(); //also add the cache cleaning here. if (function_exists('deleteCache')) { deleteCache(); } global $mod_strings; global $current_language; if (!isset($current_language) || $current_language == null) { $current_language = 'en_us'; } if (isset($GLOBALS['current_language']) && $GLOBALS['current_language'] != null) { $current_language = $GLOBALS['current_language']; } $mod_strings = return_module_language($current_language, 'UpgradeWizard');
/** * 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; }
function rebuild_vardefs($modules = array()) { $this->rebuildExt("Vardefs", 'vardefs.ext.php', null, null, $modules); if (!empty($modules)) { foreach ($modules as $module) { VardefManager::clearVardef($module); } } else { VardefManager::clearVardef(); } sugar_cache_reset(); }
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; }
function build() { $modulesToBuild = array(); if (!isset($this->relationships[$this->newRelationshipName])) { $GLOBALS['log']->fatal("Could not find a relationship by the name of {$this->newRelationshipName}, you will have to quick repair and rebuild to get the new relationship added."); } else { $newRel = $this->relationships[$this->newRelationshipName]; $newRelDef = $newRel->getDefinition(); $modulesToBuild[$newRelDef['rhs_module']] = true; $modulesToBuild[$newRelDef['lhs_module']] = true; } $basepath = "custom/Extension/modules"; $this->activitiesToAdd = false; // and mark all as built so that the next time we come through we'll know and won't build again foreach ($this->relationships as $name => $relationship) { if ($relationship->readonly()) { continue; } $definition = $relationship->getDefinition(); // activities will always appear on the rhs only - lhs will be always be this module in MB if (strtolower($definition['rhs_module']) == 'activities') { $this->activitiesToAdd = true; $relationshipName = $definition['relationship_name']; foreach (self::$activities as $activitiesSubModuleLower => $activitiesSubModuleName) { $definition['rhs_module'] = $activitiesSubModuleName; $definition['for_activities'] = true; $definition['relationship_name'] = $relationshipName . '_' . $activitiesSubModuleLower; $this->relationships[$definition['relationship_name']] = RelationshipFactory::newRelationship($definition); } unset($this->relationships[$name]); } } $GLOBALS['log']->info(get_class($this) . "->build(): installing relationships"); $MBModStrings = $GLOBALS['mod_strings']; $adminModStrings = return_module_language('', 'Administration'); // required by ModuleInstaller foreach ($this->relationships as $name => $relationship) { if ($relationship->readonly()) { continue; } $relationship->setFromStudio(); $GLOBALS['mod_strings'] = $MBModStrings; $installDefs = parent::build($basepath, "<basepath>", array($name => $relationship)); // and mark as built so that the next time we come through we'll know and won't build again $relationship->setReadonly(); $this->relationships[$name] = $relationship; // now install the relationship - ModuleInstaller normally only does this as part of a package load where it installs the relationships defined in the manifest. However, we don't have a manifest or a package, so... // If we were to chose to just use the Extension mechanism, without using the ModuleInstaller install_...() methods, we must : // 1) place the information for each side of the relationship in the appropriate Ext directory for the module, which means specific $this->save...() methods for DeployedRelationships, and // 2) we must also manually add the relationship into the custom/application/Ext/TableDictionary/tabledictionary.ext.php file as install_relationship doesn't handle that (install_relationships which requires the manifest however does) // Relationships must be in tabledictionary.ext.php for the Admin command Rebuild Relationships to reliably work: // Rebuild Relationships looks for relationships in the modules vardefs.php, in custom/modules/<modulename>/Ext/vardefs/vardefs.ext.php, and in modules/TableDictionary.php and custom/application/Ext/TableDictionary/tabledictionary.ext.php // if the relationship is not defined in one of those four places it could be deleted during a rebuilt, or during a module installation (when RebuildRelationships.php deletes all entries in the Relationships table) // So instead of doing this, we use common save...() methods between DeployedRelationships and UndeployedRelationships that will produce installDefs, // and rather than building a full manifest file to carry them, we manually add these installDefs to the ModuleInstaller, and then // individually call the appropriate ModuleInstaller->install_...() methods to take our relationship out of our staging area and expand it out to the individual module Ext areas $GLOBALS['mod_strings'] = $adminModStrings; require_once 'ModuleInstall/ModuleInstaller.php'; $mi = new ModuleInstaller(); $mi->id_name = 'custom' . $name; // provide the moduleinstaller with a unique name for this relationship - normally this value is set to the package key... $mi->installdefs = $installDefs; $mi->base_dir = $basepath; $mi->silent = true; VardefManager::clearVardef(); $mi->install_relationships(); $mi->install_languages(); $mi->install_vardefs(); $mi->install_layoutdefs(); $mi->install_extensions(); $mi->install_client_files(); } $GLOBALS['mod_strings'] = $MBModStrings; // finally, restore the ModuleBuilder mod_strings // Anything that runs in-process needs to reload their vardefs $GLOBALS['reload_vardefs'] = true; // save out the updated definitions so that we keep track of the change in built status // sending false so we don't rebuild relationshsips for a third time. $this->save(false); $mi = new ModuleInstaller(); $mi->silent = true; $mi->rebuild_relationships($modulesToBuild); // now clear all caches so that our changes are visible require_once 'modules/Administration/QuickRepairAndRebuild.php'; $rac = new RepairAndClear(); $rac->module_list = $modulesToBuild; $rac->clearJsFiles(); $rac->clearVardefs(); $rac->clearJsLangFiles(); $rac->clearLanguageCache(); $rac->rebuildExtensions(array_keys($modulesToBuild)); $rac->clearVardefs(); foreach ($rac->module_list as $moduleName => $ignore) { // Now rebuild the vardefs in memory $bean = BeanFactory::newBean($moduleName); VardefManager::loadVardef($bean->module_dir, $bean->object_name, true, array('bean' => $bean)); } foreach (array_keys($modulesToBuild) as $module) { unset($GLOBALS['dictionary'][BeanFactory::getObjectName($module)]); } SugarRelationshipFactory::rebuildCache(); MetaDataManager::refreshLanguagesCache(array($GLOBALS['current_language'])); MetaDataManager::refreshSectionCache(array(MetaDataManager::MM_RELATIONSHIPS)); MetaDataManager::refreshModulesCache(array_keys($modulesToBuild)); $GLOBALS['log']->info(get_class($this) . "->build(): finished relationship installation"); }
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); }
function repairTables() { global $db; VardefManager::clearVardef(); $repairedTables = array(); include 'include/modules.php'; foreach ($beanFiles as $bean => $file) { if (file_exists($file)) { require_once $file; unset($GLOBALS['dictionary'][$bean]); $focus = new $bean(); if ($focus instanceof SugarBean && !isset($repairedTables[$focus->table_name])) { $db->repairTable($focus, true); $repairedTables[$focus->table_name] = true; } } } unset($dictionary); include 'modules/TableDictionary.php'; foreach ($dictionary as $meta) { if (!isset($meta['table']) || isset($repairedTables[$meta['table']])) { continue; } $tablename = $meta['table']; $fielddefs = $meta['fields']; $indices = $meta['indices']; $engine = isset($meta['engine']) ? $meta['engine'] : null; $db->repairTableParams($tablename, $fielddefs, $indices, true, $engine); $repairedTables[$tablename] = true; } }