/** * Workflow: Check module builder modules for "moduleList" and "moduleListSingular" * labels and translations. Create or append fixed content to package * language file to make it compatible with Studio or ModuleBuilder for future changes */ public function run() { if (empty($this->upgrader->state['MBModules'])) { // No MB modules - nothing to do return; } $app_list_strings = return_app_list_strings_language("en_us"); $changes = array(); $packages = $this->getPackages(); foreach ($this->upgrader->state['MBModules'] as $MBModule) { // All custom modules will have package key in module name $keys = explode('_', $MBModule); $packageKey = $keys[0]; if (!isset($packages[$packageKey])) { $this->upgrader->log('FixSingularList: can\'t find package for module: key - ' . $packageKey . '. Script will use current key as package name'); $packages[$packageKey] = $packageKey; } $changes[$packageKey] = isset($changes[$packageKey]) ? $changes[$packageKey] : array(); // Try to add custom module to moduleList if (!isset($app_list_strings['moduleList'][$MBModule])) { $langFile = $this->getLanguageFilePath($MBModule); if (file_exists($langFile)) { $mod_strings = array(); require $langFile; $moduleName = isset($mod_strings['LBL_MODULE_NAME']) ? $mod_strings['LBL_MODULE_NAME'] : false; if ($moduleName) { $app_list_strings['moduleList'][$MBModule] = $moduleName; $changes[$packageKey]['moduleList'][$MBModule] = $moduleName; } else { $this->upgrader->log('FixSingularList: warning - module ' . $MBModule . ' do not have module name translation'); } } } if (!isset($app_list_strings['moduleListSingular'][$MBModule]) && !empty($app_list_strings['moduleList'][$MBModule])) { $changes[$packageKey]['moduleListSingular'][$MBModule] = $app_list_strings['moduleList'][$MBModule]; } } $rebuildLang = false; foreach ($changes as $packageKey => $content) { // if no changes - continue if (empty($content)) { continue; } $packageName = $packages[$packageKey]; $fileName = $this->getPackageLangFile($packageName); $values = $this->mergeCustomTranslations($fileName, $content); $header = file_get_contents('modules/ModuleBuilder/MB/header.php'); $file = $header; foreach ($values as $key => $array) { $file .= override_value_to_string_recursive2('app_list_strings', $key, $array); } $this->upgrader->putFile($fileName, $file); $rebuildLang = true; } if ($rebuildLang) { $mi = new ModuleInstaller(); $mi->silent = true; $mi->rebuild_languages(array('en_us' => 'en_us')); } }
function install_gmaps() { require_once 'ModuleInstall/ModuleInstaller.php'; $ModuleInstaller = new ModuleInstaller(); $ModuleInstaller->install_custom_fields(getCustomFields()); installJJWHooks(); }
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() { SugarTestUserUtilities::removeAllCreatedAnonymousUsers(); unset($GLOBALS['current_user']); require_once 'ModuleInstall/ModuleInstaller.php'; $moduleInstaller = new ModuleInstaller(); $moduleInstaller->silent = true; // make sure that the ModuleInstaller->log() function doesn't echo while rebuilding the layoutdefs $moduleInstaller->rebuild_layoutdefs(); }
function UWrebuild() { global $log; global $db; $log->info('Deleting Relationship Cache. Relationships will automatically refresh.'); echo "\n\t<div id='rrresult'></div>\n\t<script>\n\t\tvar xmlhttp=false;\n\t\t/*@cc_on @*/\n\t\t/*@if (@_jscript_version >= 5)\n\t\t// JScript gives us Conditional compilation, we can cope with old IE versions.\n\t\t// and security blocked creation of the objects.\n\t\t try {\n\t\t xmlhttp = new ActiveXObject(\"Msxml2.XMLHTTP\");\n\t\t } catch (e) {\n\t\t try {\n\t\t xmlhttp = new ActiveXObject(\"Microsoft.XMLHTTP\");\n\t\t } catch (E) {\n\t\t xmlhttp = false;\n\t\t }\n\t\t }\n\t\t@end @*/\n\t\tif (!xmlhttp && typeof XMLHttpRequest!='undefined') {\n\t\t\ttry {\n\t\t\t\txmlhttp = new XMLHttpRequest();\n\t\t\t} catch (e) {\n\t\t\t\txmlhttp = false;\n\t\t\t}\n\t\t}\n\t\tif (!xmlhttp && window.createRequest) {\n\t\t\ttry {\n\t\t\t\txmlhttp = window.createRequest();\n\t\t\t} catch (e) {\n\t\t\t\txmlhttp = false;\n\t\t\t}\n\t\t}\n\t\txmlhttp.onreadystatechange = function() {\n\t\t if(xmlhttp.readyState == 4) {\n\t\t document.getElementById('rrresult').innerHTML = xmlhttp.responseText;\n\t\t }\n\t\t }\n\t\txmlhttp.open('GET', 'index.php?module=Administration&action=RebuildRelationship&to_pdf=true', true);\n\t\txmlhttp.send(null);\n\t\t</script>"; $log->info('Rebuilding everything.'); require_once 'ModuleInstall/ModuleInstaller.php'; $mi = new ModuleInstaller(); $mi->rebuild_all(); }
/** * {@inheritdoc} */ public function run() { $hooksModules = $this->findHookFiles(); //Check modules hooks. foreach ($hooksModules['hooks'] as $file) { $this->testHooks($file); } //Check extension hooks. foreach ($hooksModules['ext'] as $file) { $this->testHooks($file); } if (!empty($hooksModules['ext'])) { $mi = new ModuleInstaller(); $mi->rebuild_logichooks(); } }
public function run() { if (!$this->toFlavor('pro')) { return; } require_once 'ModuleInstall/ModuleInstaller.php'; $this->putFile($this->cacheDir('config.js'), ModuleInstaller::getJSConfig(ModuleInstaller::getBaseConfig())); }
public function run() { if (!$this->toFlavor('ent')) { return; } require_once 'ModuleInstall/ModuleInstaller.php'; $this->putFile('portal2/config.js', ModuleInstaller::getJSConfig(ModuleInstaller::getPortalConfig())); }
/** * Rebuild changes languages for module * * @param $languages * @param $module */ protected function rebuildLanguages($languages, $module) { if (!$this->mi) { $this->mi = new ModuleInstaller(); $this->mi->silent = true; } $this->mi->rebuild_languages($languages, array($module)); }
/** * A Static method to Build the display for the package manager * * @param String form1 - the form to display for manual downloading * @param String hidden_fields - the hidden fields related to downloading a package * @param String form_action - the form_action to be used when downloading from the server * @param String types - the types of objects we will request from the server * @param String active_form - the form to display first * @return String - a string of html which will be used to display the forms */ function buildPackageDisplay($form1, $hidden_fields, $form_action, $types = array('module'), $active_form = 'form1', $install = false) { global $current_language, $app_strings; $app_strings = return_application_language($current_language); $ss = new Sugar_Smarty(); $ss->assign('APP_STRINGS', $app_strings); $ss->assign('FORM_1_PLACE_HOLDER', $form1); $ss->assign('form_action', $form_action); $ss->assign('hidden_fields', $hidden_fields); $result = PackageManagerDisplay::getHeader(); $isAlive = $result['isAlive']; $mi = new ModuleInstaller(); $mi_errors = $mi->getErrors(); $error_html = ""; if (!empty($mi_errors)) { $error_html = "<div style='margin:0px 10px 10px 10px;'>"; foreach ($mi_errors as $error) { $error_html .= "<font color='red'>" . $error . "</font><br>"; } $error_html .= "</div>"; } $tree = PackageManagerDisplay::buildTreeView('treeview', $isAlive); $tree->tree_style = 'vendor/ytree/TreeView/css/check/tree.css'; $ss->assign('TREEHEADER', $tree->generate_header()); $ss->assign('installation', $install ? 'true' : 'false'); $mod_strings = return_module_language($current_language, "Administration"); $ss->assign('MOD', $mod_strings); $ss->assign('module_load', 'true'); if (UploadStream::getSuhosinStatus() == false) { $ss->assign('ERR_SUHOSIN', true); } else { $ss->assign('scripts', PackageManagerDisplay::getDisplayScript($install)); } $show_login = false; //hiding install from sugar $ss->assign('MODULE_SELECTOR', PackageManagerDisplay::buildGridOutput($tree, $mod_strings, $isAlive, $show_login)); $ss->assign('INSTALL_ERRORS', $error_html); $ss->assign('MOD', $mod_strings); $descItemsInstalled = $mod_strings['LBL_UW_DESC_MODULES_INSTALLED']; $ss->assign('INSTALLED_PACKAGES_HOLDER', PackageManagerDisplay::buildInstalledGrid($mod_strings, $types)); $str = $ss->fetch('ModuleInstall/PackageManager/tpls/PackageForm.tpl'); return $str; }
function UWrebuild() { global $db; Log::info('Deleting Relationship Cache. Relationships will automatically refresh.'); echo "\n\t<div id='rrresult'></div>\n\t<script>\n\t\tvar xmlhttp=false;\n\t\t/*@cc_on @*/\n\t\t/*@if (@_jscript_version >= 5)\n\t\t// JScript gives us Conditional compilation, we can cope with old IE versions.\n\t\t// and security blocked creation of the objects.\n\t\t try {\n\t\t xmlhttp = new ActiveXObject(\"Msxml2.XMLHTTP\");\n\t\t } catch (e) {\n\t\t try {\n\t\t xmlhttp = new ActiveXObject(\"Microsoft.XMLHTTP\");\n\t\t } catch (E) {\n\t\t xmlhttp = false;\n\t\t }\n\t\t }\n\t\t@end @*/\n\t\tif (!xmlhttp && typeof XMLHttpRequest!='undefined') {\n\t\t\ttry {\n\t\t\t\txmlhttp = new XMLHttpRequest();\n\t\t\t} catch (e) {\n\t\t\t\txmlhttp = false;\n\t\t\t}\n\t\t}\n\t\tif (!xmlhttp && window.createRequest) {\n\t\t\ttry {\n\t\t\t\txmlhttp = window.createRequest();\n\t\t\t} catch (e) {\n\t\t\t\txmlhttp = false;\n\t\t\t}\n\t\t}\n\t\txmlhttp.onreadystatechange = function() {\n\t\t if(xmlhttp.readyState == 4) {\n\t\t document.getElementById('rrresult').innerHTML = xmlhttp.responseText;\n\t\t }\n\t\t }\n\t\txmlhttp.open('GET', 'index.php?module=Administration&action=RebuildRelationship&to_pdf=true', true);\n\t\txmlhttp.send(null);\n\t\t</script>"; Log::info('Rebuilding everything.'); require_once 'ModuleInstall/ModuleInstaller.php'; $mi = new ModuleInstaller(); $mi->rebuild_all(); $query = "DELETE FROM versions WHERE name='Rebuild Extensions'"; Log::info($query); $db->query($query); // insert a new database row to show the rebuild extensions is done $id = create_guid(); $gmdate = TimeDate::getInstance()->nowDb(); $date_entered = db_convert("'{$gmdate}'", 'datetime'); $query = 'INSERT INTO versions (id, deleted, date_entered, date_modified, modified_user_id, created_by, name, file_version, db_version) ' . "VALUES ('{$id}', '0', {$date_entered}, {$date_entered}, '1', '1', 'Rebuild Extensions', '4.0.0', '4.0.0')"; Log::info($query); $db->query($query); }
/** * Rebuilds extensions and language files for this language and module * * @param string $language The language to rebuild extensions for * @param string $moduleName The name of the module whose extensions are being rebuilt */ protected static function rebuildLanguageExtensions($language, $moduleName) { if (empty(self::$moduleInstaller)) { self::$moduleInstaller = new ModuleInstaller(); self::$moduleInstaller->silent = true; } self::$moduleInstaller->rebuild_extensions(array($moduleName), array('languages')); // While this *is* called from rebuild_extensions, it doesn't do anything // there because there is no language or module provided to it. This fixes // that. self::$moduleInstaller->rebuild_languages(array($language => $language), array($moduleName)); }
/** * This method checks to see if the configuration file exists and, if not, creates one by default * */ public function preDisplay() { global $app_strings; //Rebuild config file if it doesn't exist if (!file_exists($this->configFile)) { ModuleInstaller::handleBaseConfig(); } $this->ss->assign("configFile", $this->configFile); $config = ModuleInstaller::getBaseConfig(); $this->ss->assign('configHash', md5(serialize($config))); $sugarSidecarPath = ensureJSCacheFilesExist(); $this->ss->assign("sugarSidecarPath", $sugarSidecarPath); // TODO: come up with a better way to deal with the various JS files // littered in sidecar.tpl. $voodooFile = 'custom/include/javascript/voodoo.js'; if (SugarAutoLoader::fileExists($voodooFile)) { $this->ss->assign('voodooFile', $voodooFile); } //Load sidecar theme css $theme = new SidecarTheme(); $this->ss->assign("css_url", $theme->getCSSURL()); $this->ss->assign("developerMode", inDeveloperMode()); //Loading label $this->ss->assign('LBL_LOADING', $app_strings['LBL_ALERT_TITLE_LOADING']); $this->ss->assign('LBL_ENABLE_JAVASCRIPT', $app_strings['LBL_ENABLE_JAVASCRIPT']); $slFunctionsPath = inDeveloperMode() ? "cache/Expressions/functions_cache_debug.js" : "cache/Expressions/functions_cache.js"; if (!is_file($slFunctionsPath)) { $GLOBALS['updateSilent'] = true; include "include/Expressions/updatecache.php"; } $this->ss->assign("SLFunctionsPath", $slFunctionsPath); if (!empty($this->authorization)) { $this->ss->assign('appPrefix', $config['env'] . ":" . $config['appId'] . ":"); $this->ss->assign('authorization', $this->authorization); } }
function performUninstall($name) { $uh = new UpgradeHistory(); $uh->name = $name; $uh->id_name = $name; $found = $uh->checkForExisting($uh); if ($found != null) { global $sugar_config; global $mod_strings; global $current_language; $base_upgrade_dir = sugar_cached("/upgrades"); $base_tmp_upgrade_dir = "{$base_upgrade_dir}/temp"; if (!isset($GLOBALS['mi_remove_tables'])) { $GLOBALS['mi_remove_tables'] = true; } $unzip_dir = mk_temp_dir($base_tmp_upgrade_dir); unzip($found->filename, $unzip_dir); $mi = new ModuleInstaller(); $mi->silent = true; $mi->uninstall("{$unzip_dir}"); $found->delete(); unlink(remove_file_extension($found->filename) . '-manifest.php'); unlink($found->filename); } }
/** * A Static method to Build the display for the package manager * * @param String form1 - the form to display for manual downloading * @param String hidden_fields - the hidden fields related to downloading a package * @param String form_action - the form_action to be used when downloading from the server * @param String types - the types of objects we will request from the server * @param String active_form - the form to display first * @return String - a string of html which will be used to display the forms */ function buildPackageDisplay($form1, $hidden_fields, $form_action, $types = array('module'), $active_form = 'form1', $install = false) { global $current_language; $mod_strings = return_module_language($current_language, "Administration"); global $app_strings; global $sugar_version, $sugar_config; $app_strings = return_application_language($current_language); $ss = new Sugar_Smarty(); $ss->assign('FORM_1_PLACE_HOLDER', $form1); $ss->assign('form_action', $form_action); $ss->assign('hidden_fields', $hidden_fields); $result = PackageManagerDisplay::getHeader(); $header_text = $result['text']; $isAlive = $result['isAlive']; $show_login = $result['show_login']; $mi_errors = ModuleInstaller::getErrors(); $error_html = ""; if (!empty($mi_errors)) { $error_html = "<tr><td><span>"; foreach ($mi_errors as $error) { $error_html .= "<font color='red'>" . $error . "</font><br>"; } $error_html .= "</span></td></tr>"; } $form2 = "<table class='tabForm' width='100%' cellpadding='0' cellspacing='0' width='100%' border='0'>"; $form2 .= $error_html; if (!$isAlive) { $form2 .= "<tr><td><span id='span_display_html'>" . $header_text . "</span></td></tr>"; } $form2 .= "</table>"; $tree = null; //if($isAlive){ $tree = PackageManagerDisplay::buildTreeView('treeview', $isAlive); $tree->tree_style = 'include/ytree/TreeView/css/check/tree.css'; $ss->assign('TREEHEADER', $tree->generate_header()); //} //$form2 .= PackageManagerDisplay::buildLoginPanel($mod_strings); $form2 .= "<table class='tabForm' cellpadding='0' cellspacing='0' width='100%' border='0'>"; $form2 .= "<tr><td></td><td align='left'>"; if ($isAlive) { $form2 .= "<input type='button' id='modifCredentialsBtn' class='button' onClick='PackageManager.showLoginDialog(true);' value='" . $mod_strings['LBL_MODIFY_CREDENTIALS'] . "'>"; } else { $form2 .= "<input type='button' id='modifCredentialsBtn' class='button' onClick='PackageManager.showLoginDialog(true);' value='" . $mod_strings['LBL_MODIFY_CREDENTIALS'] . "'style='display:none;'>"; } $form2 .= "</td><td align='left'><div id='workingStatusDiv' style='display:none;'>" . SugarThemeRegistry::current()->getImage("sqsWait", "border='0' align='bottom'", null, null, '.gif', "Loading") . "</div></td><td align='right'>"; if ($isAlive) { $form2 .= "<slot><a class=\"listViewTdToolsS1\" id='href_animate' onClick=\"PackageManager.toggleDiv('span_animate_server_div', 'catview');\"><span id='span_animate_server_div'><img src='" . SugarThemeRegistry::current()->getImageURL('basic_search.gif') . "' width='8' height='8' border='0'> Collapse</span></a></slot>"; } else { $form2 .= "<slot><a class=\"listViewTdToolsS1\" id='href_animate' onClick=\"PackageManager.toggleDiv('span_animate_server_div', 'catview');\"><span id='span_animate_server_div' style='display:none;'><img src='" . SugarThemeRegistry::current()->getImageURL('basic_search.gif') . "' width='8' height='8' border='0'> Collapse</span></a></slot>"; } $form2 .= "</td></tr></table>"; $form2 = ''; //Commenting out the form as part of sugar depot hiding. $ss->assign('installation', $install ? 'true' : 'false'); $mod_strings = return_module_language($current_language, "Administration"); $ss->assign('MOD', $mod_strings); $ss->assign('module_load', 'true'); $ss->assign('scripts', PackageManagerDisplay::getDisplayScript($install)); $show_login = false; //hiding install from sugar $ss->assign('MODULE_SELECTOR', PackageManagerDisplay::buildGridOutput($tree, $mod_strings, $isAlive, $show_login)); $ss->assign('FORM_2_PLACE_HOLDER', $form2); $ss->assign('MOD', $mod_strings); $descItemsInstalled = $mod_strings['LBL_UW_DESC_MODULES_INSTALLED']; $ss->assign('INSTALLED_PACKAGES_HOLDER', PackageManagerDisplay::buildInstalledGrid($mod_strings, $types)); $str = $ss->fetch('ModuleInstall/PackageManager/tpls/PackageForm.tpl'); return $str; }
/** * upgradeTeamColumn * Helper function to create a team_set_id column and also set team_set_id column * to have the value of the $column_name parameter * * @param $bean SugarBean which we are adding team_set_id column to * @param $column_name The name of the column containing the default team_set_id value */ function upgradeTeamColumn($bean, $column_name) { //first let's check to ensure that the team_set_id field is defined, if not it could be the case that this is an older //module that does not use the SugarObjects if (empty($bean->field_defs['team_set_id']) && $bean->module_dir != 'Trackers') { //at this point we could assume that since we have a team_id defined and not a team_set_id that we need to //add that field and the corresponding relationships $object = $bean->object_name; $module = $bean->module_dir; $object_name = $object; $_object_name = strtolower($object_name); if (!empty($GLOBALS['dictionary'][$object]['table'])) { $table_name = $GLOBALS['dictionary'][$object]['table']; } else { $table_name = strtolower($module); } $path = 'include/SugarObjects/implements/team_security/vardefs.php'; require $path; //go through each entry in the vardefs from team_security and unset anything that is already set in the core module //this will ensure we have the proper ordering. $fieldDiff = array_diff_assoc($vardefs['fields'], $GLOBALS['dictionary'][$bean->object_name]['fields']); $file = 'custom/Extension/modules/' . $bean->module_dir . '/Ext/Vardefs/teams.php'; $contents = "<?php\n"; if (!empty($fieldDiff)) { foreach ($fieldDiff as $key => $val) { $contents .= "\n\$GLOBALS['dictionary']['" . $object . "']['fields']['" . $key . "']=" . var_export_helper($val) . ";"; } } $relationshipDiff = array_diff_assoc($vardefs['relationships'], $GLOBALS['dictionary'][$bean->object_name]['relationships']); if (!empty($relationshipDiff)) { foreach ($relationshipDiff as $key => $val) { $contents .= "\n\$GLOBALS['dictionary']['" . $object . "']['relationships']['" . $key . "']=" . var_export_helper($val) . ";"; } } $indexDiff = array_diff_assoc($vardefs['indices'], $GLOBALS['dictionary'][$bean->object_name]['indices']); if (!empty($indexDiff)) { foreach ($indexDiff as $key => $val) { $contents .= "\n\$GLOBALS['dictionary']['" . $object . "']['indices']['" . $key . "']=" . var_export_helper($val) . ";"; } } if ($fh = @sugar_fopen($file, 'wt')) { fputs($fh, $contents); fclose($fh); } //we have written out the teams.php into custom/Extension/modules/{$module_dir}/Ext/Vardefs/teams.php' //now let's merge back into vardefs.ext.php require_once 'ModuleInstall/ModuleInstaller.php'; $mi = new ModuleInstaller(); $mi->merge_files('Ext/Vardefs/', 'vardefs.ext.php'); VardefManager::loadVardef($bean->module_dir, $bean->object_name, true); $bean->field_defs = $GLOBALS['dictionary'][$bean->object_name]['fields']; } if (isset($bean->field_defs['team_set_id'])) { //Create the team_set_id column $FieldArray = $GLOBALS['db']->helper->get_columns($bean->table_name); if (!isset($FieldArray['team_set_id'])) { $GLOBALS['db']->addColumn($bean->table_name, $bean->field_defs['team_set_id']); } $indexArray = $GLOBALS['db']->helper->get_indices($bean->table_name); $indexName = getValidDBName('idx_' . strtolower($bean->table_name) . '_tmst_id', true, 34); $indexDef = array(array('name' => $indexName, 'type' => 'index', 'fields' => array('team_set_id'))); if (!isset($indexArray[$indexName])) { $GLOBALS['db']->addIndexes($bean->table_name, $indexDef); } //Update the table's team_set_id column to have the same values as team_id $GLOBALS['db']->query("UPDATE {$bean->table_name} SET team_set_id = {$column_name}"); } }
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 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; }
function saveSubPanelDefOverride($panel, $subsection, $override) { global $layout_defs, $beanList; //save the new subpanel $name = "subpanel_layout['list_fields']"; //bugfix: load looks for moduleName/metadata/subpanels, not moduleName/subpanels $path = 'custom/modules/' . $panel->_instance_properties['module'] . '/metadata/subpanels'; //bug# 40171: "Custom subpanels not working as expected" //each custom subpanel needs to have a unique custom def file $filename = $panel->parent_bean->object_name . "_subpanel_" . $panel->name; //bug 42262 (filename with $panel->_instance_properties['get_subpanel_data'] can create problem if had word "function" in it) $oldName1 = '_override' . $panel->parent_bean->object_name . $panel->_instance_properties['module'] . $panel->_instance_properties['subpanel_name']; $oldName2 = '_override' . $panel->parent_bean->object_name . $panel->_instance_properties['get_subpanel_data']; if (file_exists('custom/Extension/modules/' . $panel->parent_bean->module_dir . "/Ext/Layoutdefs/{$oldName1}.php")) { unlink('custom/Extension/modules/' . $panel->parent_bean->module_dir . "/Ext/Layoutdefs/{$oldName1}.php"); } if (file_exists('custom/Extension/modules/' . $panel->parent_bean->module_dir . "/Ext/Layoutdefs/{$oldName2}.php")) { unlink('custom/Extension/modules/' . $panel->parent_bean->module_dir . "/Ext/Layoutdefs/{$oldName2}.php"); } $extname = '_override' . $filename; //end of bug# 40171 mkdir_recursive($path, true); write_array_to_file($name, $override, $path . '/' . $filename . '.php'); //save the override for the layoutdef //tyoung 10.12.07 pushed panel->name to lowercase to match case in subpaneldefs.php files - //gave error on bad index 'module' as this override key didn't match the key in the subpaneldefs $name = "layout_defs['" . $panel->parent_bean->module_dir . "']['subpanel_setup']['" . strtolower($panel->name) . "']"; // $GLOBALS['log']->debug('SubPanel.php->saveSubPanelDefOverride(): '.$name); $newValue = override_value_to_string($name, 'override_subpanel_name', $filename); mkdir_recursive('custom/Extension/modules/' . $panel->parent_bean->module_dir . '/Ext/Layoutdefs', true); $fp = sugar_fopen('custom/Extension/modules/' . $panel->parent_bean->module_dir . "/Ext/Layoutdefs/{$extname}.php", 'w'); fwrite($fp, "<?php\n//auto-generated file DO NOT EDIT\n{$newValue}\n?>"); fclose($fp); require_once 'ModuleInstall/ModuleInstaller.php'; $moduleInstaller = new ModuleInstaller(); $moduleInstaller->silent = true; // make sure that the ModuleInstaller->log() function doesn't echo while rebuilding the layoutdefs $moduleInstaller->rebuild_layoutdefs(); if (file_exists('modules/' . $panel->parent_bean->module_dir . '/layout_defs.php')) { include 'modules/' . $panel->parent_bean->module_dir . '/layout_defs.php'; } if (file_exists('custom/modules/' . $panel->parent_bean->module_dir . '/Ext/Layoutdefs/layoutdefs.ext.php')) { include 'custom/modules/' . $panel->parent_bean->module_dir . '/Ext/Layoutdefs/layoutdefs.ext.php'; } }
function add_social_field($module, $field_name) { $field = array(array('name' => $field_name, 'label' => 'LBL_' . strtoupper($field_name), 'type' => 'varchar', 'module' => $module, 'ext1' => 'LIST', 'default_value' => '', 'mass_update' => false, 'required' => false, 'reportable' => false, 'audited' => false, 'importable' => 'false', 'duplicate_merge' => false)); $layout[$module] = $field_name; require_once 'ModuleInstall/ModuleInstaller.php'; $moduleInstaller = new ModuleInstaller(); $moduleInstaller->install_custom_fields($field); //$moduleInstaller->addFieldsToLayout($layout); $this->create_panel_on_view('detailview', $field, $module, 'LBL_PANEL_SOCIAL_FEED'); /* now add it to the edit view. */ $this->create_panel_on_view('editview', $field, $module, 'LBL_PANEL_SOCIAL_FEED'); }
/** * Registration of $dictionary in global scope * * @static * @return bool is variable setuped or not */ protected static function setUp_dictionary() { self::setUp('beanFiles'); self::setUp('beanList'); self::$registeredVars['dictionary'] = true; global $dictionary; $dictionary = array(); $moduleInstaller = new ModuleInstaller(); $moduleInstaller->silent = true; $moduleInstaller->rebuild_tabledictionary(); require 'modules/TableDictionary.php'; foreach ($GLOBALS['beanList'] as $k => $v) { VardefManager::loadVardef($k, $v); } return true; }
function performUninstall($name) { $uh = new UpgradeHistory(); $uh->name = $name; $uh->id_name = $name; $found = $uh->checkForExisting($uh); if ($found != null) { global $sugar_config; global $mod_strings; global $current_language; $base_upgrade_dir = $this->upload_dir . '/upgrades'; $base_tmp_upgrade_dir = "{$base_upgrade_dir}/temp"; if (is_file($found->filename)) { if (!isset($GLOBALS['mi_remove_tables'])) { $GLOBALS['mi_remove_tables'] = true; } $unzip_dir = mk_temp_dir($base_tmp_upgrade_dir); unzip($found->filename, $unzip_dir); $mi = new ModuleInstaller(); $mi->silent = true; $mi->uninstall("{$unzip_dir}"); $found->delete(); unlink(remove_file_extension($found->filename) . '-manifest.php'); unlink($found->filename); } else { //file(s_ have been deleted or are not found in the directory, allow database delete to happen but no need to change filesystem $found->delete(); } } }
// Give the install ample time to finish set_time_limit(3600); // Implicitly set character set to skip browser buffer sniffing header('Content-Type: text/html; charset=UTF-8'); // Bypass output buffering if enforced by FastCGI implementation header('X-Accel-Buffering: no'); // Flush after each output so the user can see the progress in real-time ob_implicit_flush(); // When output_buffering is enabled - which is recommended in production - // make sure we flush the current output buffer(s) otherwise we are still // buffering at this point and real-time updates wont make it to the screen. while (@ob_end_flush()) { } require_once 'install/install_utils.php'; // since we need to make sure we have even the custom tabledictionary items in there $mi = new ModuleInstaller(); $mi->silent = true; $mi->rebuild_tabledictionary(); $mi->rebuild_vardefs(); require_once 'include/MetaDataManager/MetaDataManager.php'; MetaDataManager::disableCache(); include "modules/Trackers/tracker_perfMetaData.php"; include "modules/Trackers/tracker_queriesMetaData.php"; include "modules/Trackers/tracker_sessionsMetaData.php"; include "modules/Trackers/tracker_tracker_queriesMetaData.php"; require_once 'modules/TableDictionary.php'; $trackerManager = TrackerManager::getInstance(); $trackerManager->pause(); $cache_dir = sugar_cached(""); $line_entry_format = "     <b>"; $line_exit_format = "...   </b>";
public function rebuildExtensions() { global $mod_strings; if ($this->show_output) { echo $mod_strings['LBL_QR_REBUILDEXT']; } global $current_user; require_once 'ModuleInstall/ModuleInstaller.php'; $mi = new ModuleInstaller(); $mi->rebuild_all(!$this->show_output); // Remove the "Rebuild Extensions" red text message on admin logins if ($this->show_output) { echo $mod_strings['LBL_REBUILD_REL_UPD_WARNING']; } // clear the database row if it exists (just to be sure) $query = "DELETE FROM versions WHERE name='Rebuild Extensions'"; $GLOBALS['log']->info($query); $GLOBALS['db']->query($query); // insert a new database row to show the rebuild extensions is done $id = create_guid(); $gmdate = gmdate('Y-m-d H:i:s'); $date_entered = db_convert("'{$gmdate}'", 'datetime'); $query = 'INSERT INTO versions (id, deleted, date_entered, date_modified, modified_user_id, created_by, name, file_version, db_version) ' . "VALUES ('{$id}', '0', {$date_entered}, {$date_entered}, '1', '1', 'Rebuild Extensions', '4.0.0', '4.0.0')"; $GLOBALS['log']->info($query); $GLOBALS['db']->query($query); // unset the session variable so it is not picked up in DisplayWarnings.php if (isset($_SESSION['rebuild_extensions'])) { unset($_SESSION['rebuild_extensions']); } }
function rebuildExtensions() { global $mod_strings; if ($this->show_output) { echo $mod_strings['LBL_QR_REBUILDEXT']; } global $current_user; require_once 'ModuleInstall/ModuleInstaller.php'; $mi = new ModuleInstaller(); $mi->rebuild_all(!$this->show_output); }
/** * Add a search index * * @param string $module The module wherin will be searched. * @param int $otherId The id of the record. * @param array $fields A key/value pair of fields to index. * @param string[optional] $language The frontend language for this entry. */ protected function addSearchIndex($module, $otherId, array $fields, $language) { // get db $db = $this->getDB(); // validate cache if (empty(self::$modules)) { // get all modules self::$modules = (array) $db->getColumn('SELECT m.name FROM modules AS m'); } // module exists? if (!in_array('search', self::$modules)) { return; } // no fields? if (empty($fields)) { return; } // insert search index foreach ($fields as $field => $value) { // reformat value $value = strip_tags((string) $value); // insert in db $db->execute('INSERT INTO search_index (module, other_id, language, field, value, active) VALUES (?, ?, ?, ?, ?, ?) ON DUPLICATE KEY UPDATE value = ?, active = ?', array((string) $module, (int) $otherId, (string) $language, (string) $field, $value, 'Y', $value, 'Y')); } // invalidate the cache for search foreach (SpoonFile::getList(FRONTEND_CACHE_PATH . '/search/') as $file) { SpoonFile::delete(FRONTEND_CACHE_PATH . '/search/' . $file); } }
function commitModules($unlink = false, $type = 'module') { require_once 'ModuleInstall/ModuleInstaller.php'; require_once 'include/entryPoint.php'; global $mod_strings; global $base_upgrade_dir; global $base_tmp_upgrade_dir; global $db; $GLOBALS['db'] = $db; $errors = array(); $files = array(); global $current_user; $current_user = new User(); $current_user->is_admin = '1'; $old_mod_strings = $mod_strings; if (is_dir(sugar_cached("upload/upgrades"))) { $files = findAllFiles(sugar_cached("upload/upgrades/{$type}"), $files); $mi = new ModuleInstaller(); $mi->silent = true; $mod_strings = return_module_language('en', "Administration"); foreach ($files as $file) { if (!preg_match('#.*\\.zip\\$', $file)) { continue; } $lic_name = 'accept_lic_' . str_replace('.', '_', urlencode(basename($file))); $can_install = true; if (isset($_REQUEST[$lic_name])) { if ($_REQUEST[$lic_name] == 'yes') { $can_install = true; } else { $can_install = false; } } if ($can_install) { // handle manifest.php $target_manifest = remove_file_extension($file) . '-manifest.php'; if ($type == 'langpack') { $_REQUEST['manifest'] = $target_manifest; $_REQUEST['zipFile'] = $file; commitLanguagePack(); continue; } include $target_manifest; $unzip_dir = mk_temp_dir($base_tmp_upgrade_dir); unzip($file, $unzip_dir); $_REQUEST['install_file'] = $file; $mi->install($unzip_dir); $new_upgrade = new UpgradeHistory(); $new_upgrade->filename = $file; $new_upgrade->md5sum = md5_file($file); $new_upgrade->type = $manifest['type']; $new_upgrade->version = $manifest['version']; $new_upgrade->status = "installed"; // $new_upgrade->author = $manifest['author']; $new_upgrade->name = $manifest['name']; $new_upgrade->description = $manifest['description']; $new_upgrade->id_name = isset($installdefs['id_name']) ? $installdefs['id_name'] : ''; $serial_manifest = array(); $serial_manifest['manifest'] = isset($manifest) ? $manifest : ''; $serial_manifest['installdefs'] = isset($installdefs) ? $installdefs : ''; $serial_manifest['upgrade_manifest'] = isset($upgrade_manifest) ? $upgrade_manifest : ''; $new_upgrade->manifest = base64_encode(serialize($serial_manifest)); $new_upgrade->save(); //unlink($file); } //fi } //rof } //fi $mod_strings = $old_mod_strings; }
/** * 系统模块管理功能,用于从商店自动部署模块、移除模块 */ public function Item() { $this->rest(["model" => "System/ModuleItem", "post" => function ($res) { $zip = "{$res["request"]["module"]}.zip"; $path = APP_PATH . $res["request"]["module"]; if (!APP_DEBUG) { /*从服务器下载模块压缩包*/ \Org\Util\Downloader::transfer(C("ENTERTILE") . C("ENTERTILE_STORE_PATH") . $zip, TEMP_PATH . $zip); /*创建模块目录*/ \Org\Util\Directory::create($path); /*解压ZIP文件*/ \Org\Util\Zip::extract(TEMP_PATH . $zip, $path); } /*加载模块配置类并初始化*/ include "{$path}/install.php"; $moduleInstaller = new \ModuleInstaller(); $config = $moduleInstaller->config; /*准备配置数据(格式化处理)*/ $rules = []; for ($i = 0, $l = count($config["menus"]); $i < $l; $i++) { $menu = $config["menus"][$i]; $menu["rules"] = []; for ($j = 0, $m = count($menu["permits"]); $j < $m; $j++) { $permit = $menu["permits"][$j]; for ($k = 0, $n = count($permit["methods"]); $k < $n; $k++) { $rule = strtolower("{$permit["methods"][$k]}{$permit["path"]}"); $rules[] = $menu["rules"][] = $rule; } } $config["menus"][$i] = $menu; } /*增加模块信息*/ $config["id"] = D("System/ModuleItem")->add(["name" => $config["name"], "title" => $config["title"], "abstract" => $config["abstract"]]); /*增加相关权限规则(如果已存在,则不添加)*/ //读取当前规则信息 $modelPermits = D("System/AuthenticationPermit")->select(); //移除已经存在的权限规则 $rules = join($rules, ";"); for ($i = 0, $l = count($modelPermits); $i < $l; $i++) { $rules = str_replace($modelPermits[$i]["name"], "", $rules); } $rules = preg_replace("/^;|;\$/", "", preg_replace("/;{2,}/", ";", $rules)); //解析新增RULE并保存到数据库 if ($rules !== "") { $rules = '[{"name":"' . str_replace(";", '"},{"name":"', $rules) . '"}]'; } D("System/AuthenticationPermit")->addAll(json_decode($rules, true)); /*将规则信息与菜单相关联*/ //读取最新规则信息 $rules = []; $modelPermits = D("System/AuthenticationPermit")->select(); for ($i = 0, $l = count($modelPermits); $i < $l; $i++) { $rules[$modelPermits[$i]["name"]] = $modelPermits[$i]["id"]; } //关联菜单权限 for ($i = 0, $l = count($config["menus"]); $i < $l; $i++) { $tPermits = []; $menu = $config["menus"][$i]; //添加菜单页面可访问权限 $menu["rules"][] = ["path" => $menu["page"], "methods" => ["GET"]]; for ($j = 0, $m = count($menu["rules"]); $j < $m; $j++) { $tPermits[] = $rules[$menu["rules"][$j]]; } //创建菜单记录 unset($config["menus"][$i]["permits"]); unset($config["menus"][$i]["rules"]); $config["menus"][$i]["title"] = $menu["menu"]; $config["menus"][$i]["module_id"] = $config["id"]; $config["menus"][$i]["rule_ids"] = join($tPermits, ","); } D("SystemModuleMenu")->addAll($config["menus"]); /*运行自定义安装脚本*/ $moduleInstaller->install(); /*返回输出*/ $res["response"] = $config; return $res; }, "delete" => function ($res) { $path = APP_PATH . $res["request"]["module"]; //执行自定义卸载脚本 include "{$path}/install.php"; $moduleInstaller = new \ModuleInstaller(); $moduleInstaller->uninstall(); /*移除模块相关文件及记录*/ $mod = new \Think\Model(); //移除对应菜单项 $mod->execute("delete from think_system_module_menu where module_id in(select id from think_system_module_item where name='%s')", [$res["request"]["module"]]); //移除模块主体 $mod->execute("delete from think_system_module_item where name='%s'", [$res["request"]["module"]]); if (!APP_DEBUG) { //移除代码 \Org\Util\Directory::unlink($path); } /*返回输出*/ return $res; }]); }
private function uninstallLabels($labelDefinitions) { $oModuleInstaller = new ModuleInstaller(); $oModuleInstaller->uninstallLabels('custom/Extension/modules/relationships/language/', $labelDefinitions); }
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; }