/**
  * Load search fields defs from SearchFields.php
  * @return array
  */
 protected function loadSearchFields()
 {
     $filename = dirname($this->fullpath) . "/SearchFields.php";
     if (!file_exists($filename)) {
         // try without custom
         if (substr($filename, 0, 7) == 'custom/') {
             $filename = substr($filename, 7);
         }
         if (!file_exists($filename)) {
             // try going to module directly
             $filename = "modules/{$this->module}/metadata/SearchFields.php";
             if (!file_exists($filename)) {
                 // try template now
                 $sm = StudioModuleFactory::getStudioModule($this->module);
                 $moduleType = $sm->getType();
                 $filename = 'include/SugarObjects/templates/' . $moduleType . '/metadata/SearchFields.php';
                 if (!file_exists($filename)) {
                     // OK, I give up, no way I can find it, let's use basic ones
                     $filename = 'include/SugarObjects/templates/basic/metadata/SearchFields.php';
                 }
             }
         }
     }
     $searchFields = array();
     $module_name = $this->module;
     include $filename;
     return isset($searchFields[$module_name]) ? $searchFields[$module_name] : array();
 }
Example #2
0
 function loadRelatableModules()
 {
     $d = dir('modules');
     while ($e = $d->read()) {
         if (substr($e, 0, 1) == '.' || !is_dir('modules/' . $e)) {
             continue;
         }
         if (file_exists('modules/' . $e . '/metadata/studio.php') && isset($GLOBALS['beanList'][$e])) {
             $this->modules[$e] = StudioModuleFactory::getStudioModule($e);
         }
     }
 }
 /**
  * Ability to clean out the studio module cache.
  *
  * @param string $module
  * @return bool
  */
 public static function clearModuleCache($module = '')
 {
     if (empty($module)) {
         self::$loadedMods = array();
         return true;
     } else {
         if (isset(self::$loadedMods[$module])) {
             unset(self::$loadedMods[$module]);
             return true;
         }
     }
     return false;
 }
Example #4
0
 /** {@inheritDoc} */
 public function getPath()
 {
     $names = MetaDataFiles::getNames();
     //In a deployed module, we can check for a studio module with file name overrides.
     $sm = StudioModuleFactory::getStudioModule($this->module);
     foreach ($sm->sources as $file => $def) {
         if (!empty($def['view'])) {
             $names[$def['view']] = substr($file, 0, strlen($file) - 4);
         }
     }
     if (!isset($names[$this->view])) {
         sugar_die("View {$this->view} is not recognized");
     }
     return array('modules', $this->module, $names[$this->view]);
 }
Example #5
0
 function loadRelatableModules()
 {
     $d = dir('modules');
     while ($e = $d->read()) {
         if (isset($_REQUEST['view_module']) && $_REQUEST['view_module'] == 'Project' && $e == 'ProjectTask' && isset($_REQUEST['id']) && $_REQUEST['id'] == 'relEditor' && $_REQUEST['relationship_name'] == '') {
             continue;
         }
         //46141 - disabling creating custom relationship between Projects and ProjectTasks in studio
         if (substr($e, 0, 1) == '.' || !is_dir('modules/' . $e)) {
             continue;
         }
         if (SugarAutoLoader::existingCustomOne("modules/{$e}/metadata/studio.php") && isset($GLOBALS['beanList'][$e])) {
             $this->modules[$e] = StudioModuleFactory::getStudioModule($e);
         }
     }
 }
 function display()
 {
     $this->ss = new Sugar_Smarty();
     foreach ($this->vars as $var) {
         if (isset($_REQUEST[$var])) {
             $this->{$var} = $_REQUEST[$var];
             $this->ss->assign($var, $_REQUEST[$var]);
         }
     }
     $mapping = empty($_REQUEST['mapping']) ? array() : json_decode(html_entity_decode($_REQUEST['mapping']), true);
     $this->ss->assign("mapping", $mapping);
     if (empty($_REQUEST['package']) || $_REQUEST['package'] == 'studio') {
         $sm = StudioModuleFactory::getStudioModule($_REQUEST['targetModule']);
         $fields = $sm->getFields();
         if (!empty($fields[$this->parentList]) && !empty($fields[$this->parentList]['options'])) {
             $this->parentList = $fields[$this->parentList]['options'];
         }
         $parentOptions = translate($this->parentList);
         $childOptions = translate($this->childList);
     } else {
         $mb = new ModuleBuilder();
         $moduleName = $_REQUEST['targetModule'];
         $sm = $mb->getPackageModule($_REQUEST['package'], $moduleName);
         $sm->getVardefs();
         $fields = $sm->mbvardefs->vardefs['fields'];
         if (!empty($fields[$this->parentList]) && !empty($fields[$this->parentList]['options'])) {
             $this->parentList = $fields[$this->parentList]['options'];
         }
         $parentOptions = $this->getMBOptions($this->parentList, $sm);
         $childOptions = $this->getMBOptions($this->childList, $sm);
     }
     $this->ss->assign("parent_list_options", $parentOptions);
     $parentOptionsArray = array();
     foreach ($parentOptions as $value => $label) {
         $parentOptionsArray[] = array("value" => $value, "label" => $label);
     }
     $this->ss->assign("parentOptions", json_encode($parentOptions));
     $this->ss->assign("child_list_options", $childOptions);
     $childOptionsArray = array();
     foreach ($childOptions as $value => $label) {
         $childOptionsArray[] = array("value" => $value, "label" => $label);
     }
     $this->ss->assign("childOptions", json_encode($childOptionsArray));
     $this->ss->display("modules/ModuleBuilder/tpls/depdropdown.tpl");
 }
Example #7
0
 function ViewLayoutView()
 {
     $GLOBALS['log']->debug('in ViewLayoutView');
     $this->editModule = $_REQUEST['view_module'];
     $this->editLayout = $_REQUEST['view'];
     $this->package = null;
     $this->fromModuleBuilder = isset($_REQUEST['MB']) || !empty($_REQUEST['view_package']);
     if ($this->fromModuleBuilder) {
         $this->package = $_REQUEST['view_package'];
         $this->type = $this->editLayout;
     } else {
         global $app_list_strings;
         $moduleNames = array_change_key_case($app_list_strings['moduleList']);
         $this->translatedEditModule = $moduleNames[strtolower($this->editModule)];
         $this->sm = StudioModuleFactory::getStudioModule($this->editModule);
         $this->type = $this->sm->getViewType($this->editLayout);
     }
 }
 public function run()
 {
     // if we are not going to ent or ult, we need to kick out
     if (!in_array(strtolower($this->to_flavor), $this->validFlavors)) {
         return;
     }
     // to run this we must be coming any version of 7 before 7.6
     if (version_compare($this->from_version, '7.0', '>=') && version_compare($this->from_version, '7.6', '<')) {
         SugarAutoLoader::load('modules/Opportunities/include/OpportunityWithRevenueLineItem.php');
         SugarAutoLoader::load('modules/ModuleBuilder/Module/StudioModuleFactory.php');
         // clear out the studio module cache cause it will be wrong!
         StudioModuleFactory::clearModuleCache('Opportunities');
         // in the upgrade, we only want to do the metadata conversion
         $converter = new OpportunityWithRevenueLineItem();
         $converter->doMetadataConvert();
         // just on the off chance that the formula got put into a custom file, we need to make sure it contains
         // the new hotness
         $this->fixRollupFormulas();
         $admin = BeanFactory::getBean('Administration');
         $admin->saveSetting('Opportunities', 'opps_view_by', 'RevenueLineItems', 'base');
         Opportunity::getSettings(true);
     }
 }
Example #9
0
 function action_DeleteField()
 {
     require_once 'modules/DynamicFields/FieldCases.php';
     $field = get_widget($_REQUEST['type']);
     $field->name = $_REQUEST['name'];
     if (!isset($_REQUEST['view_package'])) {
         if (!empty($_REQUEST['name']) && !empty($_REQUEST['view_module'])) {
             require_once 'modules/DynamicFields/DynamicField.php';
             $moduleName = $_REQUEST['view_module'];
             // bug 51325 make sure we make this switch or delete will not work
             if ($moduleName == 'Employees') {
                 $moduleName = 'Users';
             }
             $class_name = $GLOBALS['beanList'][$moduleName];
             require_once $GLOBALS['beanFiles'][$class_name];
             $seed = new $class_name();
             $df = new DynamicField($moduleName);
             $df->setup($seed);
             //Need to load the entire field_meta_data for some field types
             $field = $df->getFieldWidget($moduleName, $field->name);
             $field->delete($df);
             $GLOBALS['mod_strings']['LBL_ALL_MODULES'] = 'all_modules';
             $_REQUEST['execute_sql'] = true;
             include_once 'modules/Administration/QuickRepairAndRebuild.php';
             $repair = new RepairAndClear();
             $repair->repairAndClearAll(array('rebuildExtensions', 'clearVardefs', 'clearTpls'), array($class_name), true, false);
             require_once 'modules/ModuleBuilder/Module/StudioModuleFactory.php';
             $module = StudioModuleFactory::getStudioModule($moduleName);
         }
     } else {
         $mb = new ModuleBuilder();
         $module =& $mb->getPackageModule($_REQUEST['view_package'], $_REQUEST['view_module']);
         $field = $module->getField($field->name);
         $field->delete($module);
         $mb->save();
     }
     $module->removeFieldFromLayouts($field->name);
     $this->view = 'modulefields';
     if (isset($GLOBALS['current_language']) && isset($_REQUEST['label']) && isset($_REQUEST['labelValue']) && isset($_REQUEST['view_module'])) {
         $this->DeleteLabel($GLOBALS['current_language'], $_REQUEST['label'], $_REQUEST['labelValue'], $_REQUEST['view_module']);
     }
 }
Example #10
0
 function processStudio($ajax)
 {
     $this->ajax->addCrumb(translate('LBL_STUDIO'), 'ModuleBuilder.main("studio")');
     if (!isset($this->editModule)) {
         //Studio Select Module Page
         $this->generateStudioModuleButtons();
         $this->question = translate('LBL_QUESTION_EDIT');
         $this->title = translate('LBL_STUDIO');
         global $current_user;
         if (is_admin($current_user)) {
             $this->actions = "<input class=\"button\" type=\"button\" id=\"exportBtn\" name=\"exportBtn\" onclick=\"ModuleBuilder.getContent('module=ModuleBuilder&action=exportcustomizations');\" value=\"" . translate('LBL_BTN_EXPORT') . '">';
         }
         $this->help = 'studioHelp';
     } else {
         $module = StudioModuleFactory::getStudioModule($this->editModule);
         $this->ajax->addCrumb($module->name, !empty($this->view) ? 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module=' . $this->editModule . '")' : '');
         switch ($this->view) {
             case 'layouts':
                 /* BEGIN - SECURITY GROUPS */
                 $groupLayout = "";
                 if (!empty($_REQUEST['grpLayout'])) {
                     $groupLayout = $_REQUEST['grpLayout'];
                 }
                 $groupName = "Default";
                 if (!isset($groupLayout) || empty($groupLayout)) {
                     $groupLayout = "";
                 } else {
                     //Get group name for display
                     require_once 'modules/SecurityGroups/SecurityGroup.php';
                     $groupFocus = new SecurityGroup();
                     $groupFocus->retrieve($groupLayout);
                     $groupName = $groupFocus->name;
                     $this->ajax->addCrumb($groupName, "");
                 }
                 /* END - SECURITY GROUPS */
                 //Studio Select Layout page
                 $this->buttons = $module->getLayouts();
                 $this->title = $module->name . " " . translate('LBL_LAYOUTS');
                 $this->question = translate('LBL_QUESTION_LAYOUT');
                 $this->help = 'layoutsHelp';
                 $this->ajax->addCrumb(translate('LBL_LAYOUTS'), '');
                 break;
             case 'subpanels':
                 //Studio Select Subpanel page.
                 $this->buttons = $module->getSubpanels();
                 $this->title = $module->name . " " . translate('LBL_SUBPANELS');
                 $this->question = translate('LBL_QUESTION_SUBPANEL');
                 $this->ajax->addCrumb(translate('LBL_SUBPANELS'), '');
                 $this->help = 'subpanelHelp';
                 break;
             case 'search':
                 /* BEGIN - SECURITY GROUPS */
                 $groupLayout = "";
                 if (!empty($_REQUEST['grpLayout'])) {
                     $groupLayout = $_REQUEST['grpLayout'];
                 }
                 $groupName = "Default";
                 if (!isset($groupLayout) || empty($groupLayout)) {
                     $groupLayout = "";
                 } else {
                     //Get group name for display
                     require_once 'modules/SecurityGroups/SecurityGroup.php';
                     $groupFocus = new SecurityGroup();
                     $groupFocus->retrieve($groupLayout);
                     $groupName = $groupFocus->name;
                     $this->ajax->addCrumb($groupName, "");
                 }
                 /* END - SECURITY GROUPS */
                 //Studio Select Search Layout page.
                 $this->buttons = $module->getSearch();
                 $this->title = $module->name . " " . translate('LBL_SEARCH');
                 $this->question = translate('LBL_QUESTION_SEARCH');
                 $this->ajax->addCrumb(translate('LBL_LAYOUTS'), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view=layouts&view_module=' . $this->editModule . '")');
                 $this->ajax->addCrumb(translate('LBL_SEARCH'), '');
                 $this->help = 'searchHelp';
                 break;
             case 'dashlet':
                 /* BEGIN - SECURITY GROUPS */
                 $groupLayout = "";
                 if (!empty($_REQUEST['grpLayout'])) {
                     $groupLayout = $_REQUEST['grpLayout'];
                 }
                 $groupName = "Default";
                 if (!isset($groupLayout) || empty($groupLayout)) {
                     $groupLayout = "";
                 } else {
                     //Get group name for display
                     require_once 'modules/SecurityGroups/SecurityGroup.php';
                     $groupFocus = new SecurityGroup();
                     $groupFocus->retrieve($groupLayout);
                     $groupName = $groupFocus->name;
                     $this->ajax->addCrumb($groupName, "");
                 }
                 /* END - SECURITY GROUPS */
                 $this->generateStudioDashletButtons();
                 $this->title = $this->editModule . " " . translate('LBL_DASHLET');
                 $this->question = translate('LBL_QUESTION_DASHLET');
                 $this->ajax->addCrumb(translate('LBL_LAYOUTS'), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view=layouts&view_module=' . $this->editModule . '")');
                 $this->ajax->addCrumb(translate('LBL_DASHLET'), '');
                 $this->help = 'dashletHelp';
                 break;
             case 'popup':
                 /* BEGIN - SECURITY GROUPS */
                 $groupLayout = "";
                 if (!empty($_REQUEST['grpLayout'])) {
                     $groupLayout = $_REQUEST['grpLayout'];
                 }
                 $groupName = "Default";
                 if (!isset($groupLayout) || empty($groupLayout)) {
                     $groupLayout = "";
                 } else {
                     //Get group name for display
                     require_once 'modules/SecurityGroups/SecurityGroup.php';
                     $groupFocus = new SecurityGroup();
                     $groupFocus->retrieve($groupLayout);
                     $groupName = $groupFocus->name;
                     $this->ajax->addCrumb($groupName, "");
                 }
                 /* END - SECURITY GROUPS */
                 $this->generateStudioPopupButtons();
                 $this->title = $this->editModule . " " . translate('LBL_POPUP');
                 $this->question = translate('LBL_QUESTION_POPUP');
                 $this->ajax->addCrumb(translate('LBL_LAYOUTS'), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view=layouts&view_module=' . $this->editModule . '")');
                 $this->ajax->addCrumb(translate('LBL_POPUP'), '');
                 $this->help = 'popupHelp';
                 break;
             default:
                 //Studio Edit Module Page
                 $this->buttons = $module->getModule();
                 $this->question = translate('LBL_QUESTION_MODULE');
                 $this->title = translate('LBL_EDIT') . " " . $module->name;
                 $this->help = 'moduleHelp';
                 global $current_user;
                 if (is_admin($current_user)) {
                     $this->actions = "<input class=\"button\" type=\"button\" id=\"exportBtn\" name=\"exportBtn\" " . "onclick=\"ModuleBuilder.getContent('module=ModuleBuilder&action=resetmodule&view_module={$this->editModule}');\" value=\"" . "Reset Module" . '">';
                 }
         }
     }
 }
Example #11
0
 /**
  * Removes the metadata files for all known studio layouts.
  * 
  * @return html output record of the files deleted
  */
 function removeCustomLayouts()
 {
     $module = StudioModuleFactory::getStudioModule($this->module);
     $sources = $module->getViewMetadataSources();
     $out = "";
     foreach ($sources as $view) {
         $file = DeployedMetaDataImplementation::getFileName($view['type'], $this->module);
         if (file_exists($file)) {
             unlink($file);
             $out .= "Removed layout {$view['type']}.php<br/>";
         }
     }
     // now clear the cache
     include_once 'include/TemplateHandler/TemplateHandler.php';
     TemplateHandler::clearCache($this->module);
     return $out;
 }
 function processStudio($ajax)
 {
     $this->ajax->addCrumb(translate('LBL_STUDIO'), 'ModuleBuilder.main("studio")');
     if (!isset($this->editModule)) {
         //Studio Select Module Page
         $this->generateStudioModuleButtons();
         $this->question = translate('LBL_QUESTION_EDIT');
         $this->title = translate('LBL_STUDIO');
         global $current_user;
         if (is_admin($current_user)) {
             $this->actions = "<input class=\"button\" type=\"button\" id=\"exportBtn\" name=\"exportBtn\" onclick=\"ModuleBuilder.getContent('module=ModuleBuilder&action=exportcustomizations');\" value=\"" . translate('LBL_BTN_EXPORT') . '">';
         }
         $this->help = 'studioHelp';
     } else {
         $module = StudioModuleFactory::getStudioModule($this->editModule);
         $this->ajax->addCrumb($module->name, !empty($this->view) ? 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view_module=' . $this->editModule . '")' : '');
         switch ($this->view) {
             case 'layouts':
                 //Studio Select Layout page
                 $this->buttons = $module->getLayouts();
                 $this->title = $module->name . " " . translate('LBL_LAYOUTS');
                 $this->question = translate('LBL_QUESTION_LAYOUT');
                 $this->help = 'layoutsHelp';
                 $this->ajax->addCrumb(translate('LBL_LAYOUTS'), '');
                 break;
             case 'subpanels':
                 //Studio Select Subpanel page.
                 $this->buttons = $module->getSubpanels();
                 $this->title = $module->name . " " . translate('LBL_SUBPANELS');
                 $this->question = translate('LBL_QUESTION_SUBPANEL');
                 $this->ajax->addCrumb(translate('LBL_SUBPANELS'), '');
                 $this->help = 'subpanelHelp';
                 break;
             case 'search':
                 //Studio Select Search Layout page.
                 $this->buttons = $module->getSearch();
                 $this->title = $module->name . " " . translate('LBL_SEARCH');
                 $this->question = translate('LBL_QUESTION_SEARCH');
                 $this->ajax->addCrumb(translate('LBL_LAYOUTS'), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view=layouts&view_module=' . $this->editModule . '")');
                 $this->ajax->addCrumb(translate('LBL_SEARCH'), '');
                 $this->help = 'searchHelp';
                 break;
             case 'dashlet':
                 $this->generateStudioDashletButtons();
                 $this->title = $this->editModule . " " . translate('LBL_DASHLET');
                 $this->question = translate('LBL_QUESTION_DASHLET');
                 $this->ajax->addCrumb(translate('LBL_LAYOUTS'), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view=layouts&view_module=' . $this->editModule . '")');
                 $this->ajax->addCrumb(translate('LBL_DASHLET'), '');
                 $this->help = 'dashletHelp';
                 break;
             case 'popup':
                 $this->generateStudioPopupButtons();
                 $this->title = $this->editModule . " " . translate('LBL_POPUP');
                 $this->question = translate('LBL_QUESTION_POPUP');
                 $this->ajax->addCrumb(translate('LBL_LAYOUTS'), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&view=layouts&view_module=' . $this->editModule . '")');
                 $this->ajax->addCrumb(translate('LBL_POPUP'), '');
                 $this->help = 'popupHelp';
                 break;
             default:
                 //Studio Edit Module Page
                 $this->buttons = $module->getModule();
                 $this->question = translate('LBL_QUESTION_MODULE');
                 $this->title = translate('LBL_EDIT') . " " . $module->name;
                 $this->help = 'moduleHelp';
                 global $current_user;
                 if (is_admin($current_user)) {
                     $this->actions = "<input class=\"button\" type=\"button\" id=\"exportBtn\" name=\"exportBtn\" " . "onclick=\"ModuleBuilder.getContent('module=ModuleBuilder&action=resetmodule&view_module={$this->editModule}');\" value=\"" . translate('LBL_RESET_MODULE') . '">';
                 }
         }
     }
 }
 public static function getFileName($view, $moduleName, $type = MB_CUSTOMMETADATALOCATION)
 {
     $pathMap = array(MB_BASEMETADATALOCATION => '', MB_CUSTOMMETADATALOCATION => 'custom/', MB_WORKINGMETADATALOCATION => 'custom/working/', MB_HISTORYMETADATALOCATION => 'custom/history/');
     $type = strtolower($type);
     $filenames = array(MB_DASHLETSEARCH => 'dashletviewdefs', MB_DASHLET => 'dashletviewdefs', MB_POPUPSEARCH => 'popupdefs', MB_POPUPLIST => 'popupdefs', MB_LISTVIEW => 'listviewdefs', MB_BASICSEARCH => 'searchdefs', MB_ADVANCEDSEARCH => 'searchdefs', MB_EDITVIEW => 'editviewdefs', MB_DETAILVIEW => 'detailviewdefs', MB_QUICKCREATE => 'quickcreatedefs');
     //In a deployed module, we can check for a studio module with file name overrides.
     $sm = StudioModuleFactory::getStudioModule($moduleName);
     foreach ($sm->sources as $file => $def) {
         if (!empty($def['view'])) {
             $filenames[$def['view']] = substr($file, 0, strlen($file) - 4);
         }
     }
     // BEGIN ASSERTIONS
     if (!isset($pathMap[$type])) {
         sugar_die("DeployedMetaDataImplementation->getFileName(): Type {$type} is not recognized");
     }
     if (!isset($filenames[$view])) {
         sugar_die("DeployedMetaDataImplementation->getFileName(): View {$view} is not recognized");
     }
     // END ASSERTIONS
     // Construct filename
     return $pathMap[$type] . 'modules/' . $moduleName . '/metadata/' . $filenames[$view] . '.php';
 }
Example #14
0
 /**
  * Removes all custom fields created in Studio
  *
  * @return array Names of removed fields
  */
 public function removeCustomFields()
 {
     $seed = BeanFactory::getBean($this->module);
     $df = new DynamicField($this->module);
     $df->setup($seed);
     $module = StudioModuleFactory::getStudioModule($this->module);
     $removedFields = array();
     foreach ($seed->field_defs as $def) {
         if (isset($def['custom_module']) && $def['custom_module'] === $this->module) {
             $field = $df->getFieldWidget($this->module, $def['name']);
             // the field may have already been deleted
             if ($field) {
                 $field->delete($df);
             }
             $module->removeFieldFromLayouts($def['name']);
             $removedFields[] = $def['name'];
         }
     }
     return $removedFields;
 }
Example #15
0
 public function action_DeleteField()
 {
     $field = get_widget($_REQUEST['type']);
     $field->name = $_REQUEST['name'];
     if (!isset($_REQUEST['view_package'])) {
         if (!empty($_REQUEST['name']) && !empty($_REQUEST['view_module'])) {
             $moduleName = $_REQUEST['view_module'];
             // bug 51325 make sure we make this switch or delete will not work
             if ($moduleName == 'Employees') {
                 $moduleName = 'Users';
             }
             $seed = BeanFactory::getBean($moduleName);
             $df = new DynamicField($moduleName);
             $df->setup($seed);
             //Need to load the entire field_meta_data for some field types
             $field = $df->getFieldWidget($moduleName, $field->name);
             $field->delete($df);
             $GLOBALS['mod_strings']['LBL_ALL_MODULES'] = 'all_modules';
             $_REQUEST['execute_sql'] = true;
             include_once 'modules/Administration/QuickRepairAndRebuild.php';
             $repair = new RepairAndClear();
             $repair->repairAndClearAll(array('rebuildExtensions', 'clearVardefs', 'clearTpls'), array($moduleName), true, false);
             require_once 'modules/ModuleBuilder/Module/StudioModuleFactory.php';
             $module = StudioModuleFactory::getStudioModule($moduleName);
         }
     } else {
         $mb = new ModuleBuilder();
         $module =& $mb->getPackageModule($_REQUEST['view_package'], $_REQUEST['view_module']);
         $field = $module->getField($field->name);
         $field->delete($module);
         $mb->save();
     }
     $module->removeFieldFromLayouts($field->name);
     $this->view = 'modulefields';
     if (isset($GLOBALS['current_language']) && isset($_REQUEST['label']) && isset($_REQUEST['labelValue']) && isset($_REQUEST['view_module'])) {
         $this->DeleteLabel($GLOBALS['current_language'], $_REQUEST['label'], $_REQUEST['labelValue'], $_REQUEST['view_module']);
         $this->metadataApiCacheCleared = true;
     }
     // Clear the metadata cache if it hasn't been done already
     if (!$this->metadataApiCacheCleared && !empty($moduleName)) {
         // This removes the labels associated with the field and rebuilds
         // the api cache for the module
         $repair->module_list = array($moduleName);
         $repair->repairMetadataAPICache('labels');
     }
 }
 public function __construct($view, $moduleName, $client = '', array $params = array())
 {
     // Set the deployed state to true
     $this->_deployed = true;
     // BEGIN ASSERTIONS
     if (!isset($GLOBALS['beanList'][$moduleName])) {
         sugar_die(get_class($this) . ": Modulename {$moduleName} is not a Deployed Module");
     }
     // END ASSERTIONS
     $this->_view = strtolower($view);
     $this->params = $params;
     $this->setViewClient($client);
     $this->_moduleName = $moduleName;
     $module = StudioModuleFactory::getStudioModule($moduleName);
     $this->module_dir = $module->seed->module_dir;
     $fielddefs = $module->getFields();
     //Load any custom views
     $sm = StudioModuleFactory::getStudioModule($moduleName);
     foreach ($sm->sources as $file => $def) {
         if (!empty($def['view'])) {
             $viewVar = "viewdefs";
             if (!empty($def['type']) && !empty($this->_fileVariables[$def["type"]])) {
                 $viewVar = $this->_fileVariables[$def["type"]];
             }
             $this->_fileVariables[$def['view']] = $viewVar;
         }
     }
     $loaded = null;
     foreach (array(MB_BASEMETADATALOCATION, MB_CUSTOMMETADATALOCATION, MB_WORKINGMETADATALOCATION, MB_HISTORYMETADATALOCATION) as $type) {
         $this->_sourceFilename = $this->getFileName($view, $moduleName, $type, $client);
         if ($view == MB_POPUPSEARCH || $view == MB_POPUPLIST) {
             global $current_language;
             $mod = return_module_language($current_language, $moduleName);
             $layout = $this->_loadFromPopupFile($this->_sourceFilename, $mod, $view);
         } else {
             $layout = $this->_loadFromFile($this->_sourceFilename);
         }
         if (null !== $layout) {
             if (MB_WORKINGMETADATALOCATION == $type) {
                 $this->_useWorkingFile = true;
             } elseif (MB_HISTORYMETADATALOCATION == $type && $this->_useWorkingFile) {
                 $this->_useWorkingFile = false;
             } elseif ($type === MB_BASEMETADATALOCATION) {
                 $this->baseViewdefs = $layout;
             }
             // merge in the fielddefs from this layout
             $this->_mergeFielddefs($fielddefs, $layout);
             $loaded = $layout;
         }
     }
     if ($loaded === null) {
         switch ($view) {
             case MB_QUICKCREATE:
                 // Special handling for QuickCreates - if we don't have a QuickCreate definition in the usual places, then use an EditView
                 $loaded = $this->_loadFromFile($this->getFileName(MB_EDITVIEW, $this->_moduleName, MB_BASEMETADATALOCATION));
                 if ($loaded === null) {
                     throw new Exception(get_class($this) . ": cannot convert from EditView to QuickCreate for Module {$this->_moduleName} - definitions for EditView are missing");
                 }
                 // Now change the array index
                 $temp = $loaded[GridLayoutMetaDataParser::$variableMap[MB_EDITVIEW]];
                 unset($loaded[GridLayoutMetaDataParser::$variableMap[MB_EDITVIEW]]);
                 $loaded[GridLayoutMetaDataParser::$variableMap[MB_QUICKCREATE]] = $temp;
                 // finally, save out our new definition so that we have a base record for the history to work from
                 $this->_sourceFilename = $this->getFileName(MB_QUICKCREATE, $this->_moduleName, MB_CUSTOMMETADATALOCATION);
                 $this->_saveToFile($this->_sourceFilename, $loaded);
                 $this->_mergeFielddefs($fielddefs, $loaded);
                 break;
             case MB_SIDECARLISTVIEW:
             case MB_RECORDVIEW:
             case MB_SIDECARPOPUPVIEW:
             case MB_SIDECARDUPECHECKVIEW:
             case MB_PORTALLISTVIEW:
             case MB_PORTALRECORDVIEW:
             case MB_WIRELESSEDITVIEW:
             case MB_WIRELESSDETAILVIEW:
             case MB_WIRELESSBASICSEARCH:
             case MB_WIRELESSADVANCEDSEARCH:
             case MB_WIRELESSLISTVIEW:
                 $_viewtype = 'mobile';
                 if (in_array($view, array(MB_RECORDVIEW, MB_SIDECARPOPUPVIEW, MB_SIDECARDUPECHECKVIEW, MB_SIDECARLISTVIEW))) {
                     $_viewtype = 'base';
                 }
                 // Set a view type (ie, portal, wireless)
                 if (in_array($view, array(MB_PORTALLISTVIEW, MB_PORTALRECORDVIEW, MB_PORTALSEARCHVIEW))) {
                     $_viewtype = 'portal';
                 }
                 // If we're missing a wireless view, we can create it easily from a template, sourced from SugarObjects
                 // First, need to identify which SugarObject template would be the best to use
                 $type = $module->getType();
                 $this->_sourceFilename = $this->getFileName($view, $moduleName, MB_CUSTOMMETADATALOCATION);
                 // Recurse through the various SugarObjects templates to get
                 // def we can use. At worst, this will end up at basic base
                 // Note: getDefsFromTemplate() returns an array, of which 'defs'
                 // is a member. If defs is empty (which it should never be)
                 // then the remainder of the array contains useful error information.
                 $loaded = $this->getDefsFromTemplate($module, $_viewtype);
                 if (empty($loaded['defs'])) {
                     $eMessage = get_class($this);
                     $eMessage .= ": cannot create {$_viewtype} view for module {$moduleName} - definitions for {$view} are missing.\n";
                     $eMessage .= "Attempted all types and clients and failed after {$loaded['type']} for {$loaded['client']} in {$loaded['file']}";
                     throw new Exception($eMessage);
                 }
                 $loaded = $this->replaceVariables($loaded['defs'], $module);
                 $this->_saveToFile($this->_sourceFilename, $loaded, false);
                 // write out without the placeholder module_name and object
                 $this->_mergeFielddefs($fielddefs, $loaded);
                 break;
             case MB_DASHLETSEARCH:
             case MB_DASHLET:
                 $type = $module->getType();
                 $this->_sourceFilename = $this->getFileName($view, $moduleName, MB_CUSTOMMETADATALOCATION);
                 $needSave = false;
                 if (file_exists("custom/modules/{$moduleName}/metadata/" . basename($this->_sourceFilename))) {
                     $loaded = $this->_loadFromFile("custom/modules/{$moduleName}/metadata/" . basename($this->_sourceFilename));
                 } elseif (file_exists("modules/{$moduleName}/Dashlets/My{$moduleName}Dashlet/My{$moduleName}Dashlet.data.php")) {
                     $loaded = $this->_loadFromFile("modules/{$moduleName}/Dashlets/My{$moduleName}Dashlet/My{$moduleName}Dashlet.data.php");
                 } else {
                     $loaded = $this->_loadFromFile("include/SugarObjects/templates/{$type}/metadata/" . basename($this->_sourceFilename));
                     $needSave = true;
                 }
                 if ($loaded === null) {
                     throw new Exception(get_class($this) . ": cannot create dashlet view for module {$moduleName} - definitions for {$view} are missing in the SugarObject template for type {$type}");
                 }
                 $loaded = $this->replaceVariables($loaded, $module);
                 $temp = $this->_moduleName;
                 if ($needSave) {
                     $this->_moduleName = $this->_moduleName . 'Dashlet';
                     $this->_saveToFile($this->_sourceFilename, $loaded, false);
                     // write out without the placeholder module_name and object
                     $this->_moduleName = $temp;
                     unset($temp);
                 }
                 $this->_mergeFielddefs($fielddefs, $loaded);
                 break;
             case MB_POPUPLIST:
             case MB_POPUPSEARCH:
                 $type = $module->getType();
                 $this->_sourceFilename = $this->getFileName($view, $moduleName, MB_CUSTOMMETADATALOCATION);
                 global $current_language;
                 $mod = return_module_language($current_language, $moduleName);
                 $loadedForWrite = $this->_loadFromPopupFile("include/SugarObjects/templates/{$type}/metadata/" . basename($this->_sourceFilename), $mod, $view, true);
                 if ($loadedForWrite === null) {
                     throw new Exception(get_class($this) . ": cannot create popup view for module {$moduleName} - definitions for {$view} are missing in the SugarObject template for type {$type}");
                 }
                 $loadedForWrite = $this->replaceVariables($loadedForWrite, $module);
                 $this->_saveToFile($this->_sourceFilename, $loadedForWrite, false, true);
                 // write out without the placeholder module_name and object
                 $loaded = $this->_loadFromPopupFile("include/SugarObjects/templates/{$type}/metadata/" . basename($this->_sourceFilename), $mod, $view);
                 $this->_mergeFielddefs($fielddefs, $loaded);
                 break;
             default:
         }
         if ($loaded === null) {
             throw new Exception(get_class($this) . ": view definitions for View {$this->_view} and Module {$this->_moduleName} are missing");
         }
     }
     $this->_viewdefs = $loaded;
     // Set the original Viewdefs - required to ensure we don't lose fields from the base layout
     // Check the base location first, then if nothing is there (which for example, will be the case for some QuickCreates, and some mobile layouts - see above)
     // we need to check the custom location where the derived layouts will be
     foreach (array(MB_BASEMETADATALOCATION, MB_CUSTOMMETADATALOCATION) as $type) {
         $sourceFilename = $this->getFileName($view, $moduleName, $type);
         if ($view == MB_POPUPSEARCH || $view == MB_POPUPLIST) {
             global $current_language;
             $mod = return_module_language($current_language, $moduleName);
             $layout = $this->_loadFromPopupFile($sourceFilename, $mod, $view);
         } else {
             $layout = $this->_loadFromFile($sourceFilename);
         }
         if (null !== $layout) {
             $this->_originalViewdefs = $layout;
             break;
         }
     }
     //For quick create viewdefs, if there is no quickcreatedefs.php under MB_BASEMETADATALOCATION, the original defs is editview defs.
     if ($view == MB_QUICKCREATE) {
         foreach (array(MB_QUICKCREATE, MB_EDITVIEW) as $v) {
             $sourceFilename = $this->getFileName($v, $moduleName, MB_BASEMETADATALOCATION);
             if (file_exists($sourceFilename)) {
                 $layout = $this->_loadFromFile($sourceFilename);
                 if (null !== $layout && isset($layout[GridLayoutMetaDataParser::$variableMap[$v]])) {
                     $layout = array(GridLayoutMetaDataParser::$variableMap[MB_QUICKCREATE] => $layout[GridLayoutMetaDataParser::$variableMap[$v]]);
                     break;
                 }
             }
         }
         if (null === $layout) {
             $sourceFilename = $this->getFileName($view, $moduleName, MB_CUSTOMMETADATALOCATION);
             $layout = $this->_loadFromFile($sourceFilename);
         }
         if (null !== $layout) {
             $this->_originalViewdefs = $layout;
         }
     }
     $this->_fielddefs = $fielddefs;
     // Set the panel defs (the old field defs)
     $this->setPanelDefsFromViewDefs();
     // Make sure the paneldefs are proper if there are any
     if (is_array($this->_paneldefs) && !is_numeric(key($this->_paneldefs))) {
         $this->_paneldefs = array($this->_paneldefs);
     }
     $this->_history = new History($this->getFileNameNoDefault($view, $moduleName, MB_HISTORYMETADATALOCATION));
 }
 function __construct($view, $moduleName)
 {
     // BEGIN ASSERTIONS
     if (!isset($this->_fileVariables[$view])) {
         sugar_die(get_class($this) . ": View {$view} is not supported");
     }
     if (!isset($GLOBALS['beanList'][$moduleName])) {
         sugar_die(get_class($this) . ": Modulename {$moduleName} is not a Deployed Module");
     }
     // END ASSERTIONS
     $this->_view = strtolower($view);
     $this->_moduleName = $moduleName;
     $module = StudioModuleFactory::getStudioModule($moduleName);
     $this->module_dir = $module->seed->module_dir;
     $fielddefs = $module->getFields();
     $loaded = null;
     foreach (array(MB_BASEMETADATALOCATION, MB_CUSTOMMETADATALOCATION, MB_WORKINGMETADATALOCATION, MB_HISTORYMETADATALOCATION) as $type) {
         $this->_sourceFilename = $this->getFileName($view, $moduleName, $type);
         if ($view == MB_POPUPSEARCH || $view == MB_POPUPLIST) {
             global $current_language;
             $mod = return_module_language($current_language, $moduleName);
             $layout = $this->_loadFromPopupFile($this->_sourceFilename, $mod, $view);
         } else {
             $layout = $this->_loadFromFile($this->_sourceFilename);
         }
         if (null !== $layout) {
             // merge in the fielddefs from this layout
             $this->_mergeFielddefs($fielddefs, $layout);
             $loaded = $layout;
         }
     }
     if ($loaded === null) {
         switch ($view) {
             case MB_QUICKCREATE:
                 // Special handling for QuickCreates - if we don't have a QuickCreate definition in the usual places, then use an EditView
                 $loaded = $this->_loadFromFile($this->getFileName(MB_EDITVIEW, $this->_moduleName, MB_BASEMETADATALOCATION));
                 if ($loaded === null) {
                     throw new Exception(get_class($this) . ": cannot convert from EditView to QuickCreate for Module {$this->_moduleName} - definitions for EditView are missing");
                 }
                 // Now change the array index
                 $temp = $loaded[GridLayoutMetaDataParser::$variableMap[MB_EDITVIEW]];
                 unset($loaded[GridLayoutMetaDataParser::$variableMap[MB_EDITVIEW]]);
                 $loaded[GridLayoutMetaDataParser::$variableMap[MB_QUICKCREATE]] = $temp;
                 // finally, save out our new definition so that we have a base record for the history to work from
                 $this->_sourceFilename = self::getFileName(MB_QUICKCREATE, $this->_moduleName, MB_CUSTOMMETADATALOCATION);
                 $this->_saveToFile($this->_sourceFilename, $loaded);
                 $this->_mergeFielddefs($fielddefs, $loaded);
                 break;
             case MB_DASHLETSEARCH:
             case MB_DASHLET:
                 $type = $module->getType();
                 $this->_sourceFilename = self::getFileName($view, $moduleName, MB_CUSTOMMETADATALOCATION);
                 $needSave = false;
                 if (file_exists("custom/modules/{$moduleName}/metadata/" . basename($this->_sourceFilename))) {
                     $loaded = $this->_loadFromFile("custom/modules/{$moduleName}/metadata/" . basename($this->_sourceFilename));
                 } elseif (file_exists("modules/{$moduleName}/Dashlets/My{$moduleName}Dashlet/My{$moduleName}Dashlet.data.php")) {
                     $loaded = $this->_loadFromFile("modules/{$moduleName}/Dashlets/My{$moduleName}Dashlet/My{$moduleName}Dashlet.data.php");
                 } else {
                     $loaded = $this->_loadFromFile("include/SugarObjects/templates/{$type}/metadata/" . basename($this->_sourceFilename));
                     $needSave = true;
                 }
                 if ($loaded === null) {
                     throw new Exception(get_class($this) . ": cannot create dashlet view for module {$moduleName} - definitions for {$view} are missing in the SugarObject template for type {$type}");
                 }
                 $loaded = $this->replaceVariables($loaded, $module);
                 $temp = $this->_moduleName;
                 if ($needSave) {
                     $this->_moduleName = $this->_moduleName . 'Dashlet';
                     $this->_saveToFile($this->_sourceFilename, $loaded, false);
                     // write out without the placeholder module_name and object
                     $this->_moduleName = $temp;
                     unset($temp);
                 }
                 $this->_mergeFielddefs($fielddefs, $loaded);
                 break;
             case MB_POPUPLIST:
             case MB_POPUPSEARCH:
                 $type = $module->getType();
                 $this->_sourceFilename = self::getFileName($view, $moduleName, MB_CUSTOMMETADATALOCATION);
                 // Now we can copy the wireless view from the template
                 global $current_language;
                 $mod = return_module_language($current_language, $moduleName);
                 $loadedForWrite = $this->_loadFromPopupFile("include/SugarObjects/templates/{$type}/metadata/" . basename($this->_sourceFilename), $mod, $view, true);
                 if ($loadedForWrite === null) {
                     throw new Exception(get_class($this) . ": cannot create popup view for module {$moduleName} - definitions for {$view} are missing in the SugarObject template for type {$type}");
                 }
                 $loadedForWrite = $this->replaceVariables($loadedForWrite, $module);
                 $this->_saveToFile($this->_sourceFilename, $loadedForWrite, false, true);
                 // write out without the placeholder module_name and object
                 $loaded = $this->_loadFromPopupFile("include/SugarObjects/templates/{$type}/metadata/" . basename($this->_sourceFilename), $mod, $view);
                 $this->_mergeFielddefs($fielddefs, $loaded);
                 break;
             default:
         }
         if ($loaded === null) {
             throw new Exception(get_class($this) . ": view definitions for View {$this->_view} and Module {$this->_moduleName} are missing");
         }
     }
     $this->_viewdefs = $loaded;
     // Set the original Viewdefs - required to ensure we don't lose fields from the base layout
     // Check the base location first, then if nothing is there (which for example, will be the case for some QuickCreates, and some mobile layouts - see above)
     // we need to check the custom location where the derived layouts will be
     foreach (array(MB_BASEMETADATALOCATION, MB_CUSTOMMETADATALOCATION) as $type) {
         $sourceFilename = $this->getFileName($view, $moduleName, $type);
         if ($view == MB_POPUPSEARCH || $view == MB_POPUPLIST) {
             global $current_language;
             $mod = return_module_language($current_language, $moduleName);
             $layout = $this->_loadFromPopupFile($sourceFilename, $mod, $view);
         } else {
             $layout = $this->_loadFromFile($sourceFilename);
         }
         if (null !== $layout) {
             $this->_originalViewdefs = $layout;
             break;
         }
     }
     //For quick create viewdefs, if there is no quickcreatedefs.php under MB_BASEMETADATALOCATION, the original defs is editview defs.
     if ($view == MB_QUICKCREATE) {
         foreach (array(MB_QUICKCREATE, MB_EDITVIEW) as $v) {
             $sourceFilename = $this->getFileName($v, $moduleName, MB_BASEMETADATALOCATION);
             if (file_exists($sourceFilename)) {
                 $layout = $this->_loadFromFile($sourceFilename);
                 if (null !== $layout && isset($layout[GridLayoutMetaDataParser::$variableMap[$v]])) {
                     $layout = array(GridLayoutMetaDataParser::$variableMap[MB_QUICKCREATE] => $layout[GridLayoutMetaDataParser::$variableMap[$v]]);
                     break;
                 }
             }
         }
         if (null === $layout) {
             $sourceFilename = $this->getFileName($view, $moduleName, MB_CUSTOMMETADATALOCATION);
             $layout = $this->_loadFromFile($sourceFilename);
         }
         if (null !== $layout) {
             $this->_originalViewdefs = $layout;
         }
     }
     $this->_fielddefs = $fielddefs;
     $this->_history = new History($this->getFileName($view, $moduleName, MB_HISTORYMETADATALOCATION));
 }
Example #18
0
 /**
  * Removes the metadata files for all known studio layouts.
  *
  * @return html output record of the files deleted
  */
 function removeCustomLayouts()
 {
     $module = StudioModuleFactory::getStudioModule($this->module);
     $sources = $module->getViewMetadataSources();
     $out = "";
     // list of existing platforms including BWC
     $platforms = MetaDataManager::getPlatformList();
     array_unshift($platforms, '');
     // Flag to tell the autoloader whether to save itself or not when done
     $saveMap = false;
     foreach ($sources as $view) {
         foreach ($platforms as $platform) {
             $file = MetaDataFiles::getDeployedFileName($view['type'], $this->module, MB_CUSTOMMETADATALOCATION, $platform);
             // Ensure we are working on files that the autoloader knows about
             if (SugarAutoLoader::fileExists($file)) {
                 // Since we are in a loop inside of a loop do NOT send the
                 // save flag as true to unlink() but be sure to save the file
                 // map after the process is finished so that all changes to
                 // the map are saved.
                 SugarAutoLoader::unlink($file);
                 $out .= "Removed layout {$view['type']}.php<br/>";
                 // Tell the autoloader to save itself
                 $saveMap = true;
             }
         }
     }
     // now clear the cache
     include_once 'include/TemplateHandler/TemplateHandler.php';
     TemplateHandler::clearCache($this->module);
     // If the file map needs saving, handle that now
     if ($saveMap) {
         SugarAutoLoader::saveMap();
     }
     return $out;
 }
Example #19
0
 protected static function checkForStudioParserOverride($view, $moduleName, $packageName)
 {
     require_once 'modules/ModuleBuilder/Module/StudioModuleFactory.php';
     $sm = StudioModuleFactory::getStudioModule($moduleName);
     foreach ($sm->sources as $file => $def) {
         if (!empty($def['view']) && $def['view'] == strtolower($view) && !empty($def['parser'])) {
             $pName = $def['parser'];
             $path = "modules/ModuleBuilder/parsers/views/{$pName}.php";
             if (file_exists("custom/{$path}")) {
                 require_once "custom/{$path}";
             } else {
                 if (file_exists($path)) {
                     require_once $path;
                 }
             }
             if (class_exists($pName)) {
                 return new $pName($view, $moduleName, $packageName);
             }
             //If it wasn't defined directly, check for a generic parser name for the view
             $parser = self::checkForParserClass($view, $moduleName, $packageName);
             if ($parser) {
                 return $parser;
             }
         }
     }
     return false;
 }
 /**
  * Processes the entire upgrade process of old to new metadata styles
  */
 public function upgrade()
 {
     include "ModuleInstall/extensions.php";
     $this->extensions = $extensions;
     // Set the upgrade file list
     $this->logUpgradeStatus('Setting upgrade file list...');
     $this->setFilesToUpgrade();
     // Traverse the files and start parsing and moving
     $this->logUpgradeStatus('Beginning metadata upgrade process...');
     foreach ($this->files as $file) {
         // Get the appropriate upgrade class name for this view type
         $class = $this->getUpgraderClass($file['viewtype']);
         if ($class) {
             if (!class_exists($class, false)) {
                 $classfile = $class . '.php';
                 require_once $classfile;
             }
             $upgrader = new $class($this, $file);
             // If the upgrade worked for this file, add it to the remove stack
             $this->logUpgradeStatus("Delegating upgrade to {$class} for {$file['fullpath']}...");
             if ($upgrader->upgrade()) {
                 if (!empty($upgrader->deleteOld) && !in_array($file['fullpath'], self::$filesForRemoval)) {
                     self::$filesForRemoval[] = $file['fullpath'];
                 }
             } else {
                 $this->registerFailure($file);
             }
             $this->logUpgradeStatus("{$class} :: upgrade() complete...");
         }
     }
     $this->logUpgradeStatus('Metadata upgrade process complete.');
     $this->logUpgradeStatus('Mobile/portal metadata upgrade process complete.');
     foreach ($this->getModulesList() as $module) {
         // if this is not a BWC module remove the old subpaneldefs layout
         if (!isModuleBWC($module)) {
             self::$filesForRemoval[] = "modules/{$module}/metadata/subpaneldefs.php";
         }
         // make sure team_name is not on the layout in case it doesn't exist in the module
         // (even if defined in template's layout)
         $sm = StudioModuleFactory::getStudioModule($module);
         $fields = $sm->getFields();
         if (is_array($fields) && !isset($fields['team_name'])) {
             $sm->removeFieldFromLayouts('team_name');
         }
     }
     // Add the rest of the OOTB module wireless metadata files to the stack
     $this->cleanupLegacyFiles();
 }
Example #21
0
 /**
  * This returns an UNFILTERED list of custom relationships by module name.  You will have to filter the relationships
  * by the modules being exported after calling this method
  * @param string $moduleName
  * @param bool $lhs Return relationships where $moduleName - left module in join.
  * @return mixed Array or false when module name is wrong.
  */
 protected function getCustomRelationshipsByModuleName($moduleName, $lhs = false)
 {
     if (BeanFactory::getBeanName($moduleName) === false) {
         return false;
     }
     $result = array();
     $relation = null;
     $module = StudioModuleFactory::getStudioModule($moduleName);
     /* @var $rel DeployedRelationships */
     $rel = $module->getRelationships();
     $relList = $rel->getRelationshipList();
     foreach ($relList as $relationshipName) {
         $relation = $rel->get($relationshipName);
         if ($relation->getFromStudio()) {
             if ($lhs && $relation->getLhsModule() != $moduleName) {
                 continue;
             }
             $result[$relationshipName] = $relation;
         }
     }
     return $result;
 }
Example #22
0
 function uninstall_beans($beans)
 {
     foreach ($beans as $bean) {
         $this->log(translate('LBL_MI_UN_BEAN') . " {$bean}");
         $mod = BeanFactory::getBean($bean);
         if (!empty($mod) && $mod instanceof SugarBean) {
             $GLOBALS['log']->debug("Drop Tables : {$bean}");
             if (isset($GLOBALS['mi_remove_tables']) && $GLOBALS['mi_remove_tables']) {
                 // remove custom fields before dropping tables
                 // in order to let DynamicField drop custom columns first
                 $studioModule = StudioModuleFactory::getStudioModule($bean);
                 $studioModule->removeCustomFields();
                 $mod->drop_tables();
             }
         }
     }
 }
Example #23
0
 /**
  * Gets a metadata directory path for a module from its SugarObject template type
  *
  * @static
  * @param string $module The name of the module to get metadata for
  * @param string $client The client making this request
  * @param string $component Layout or view
  * @return string
  */
 public static function getSugarObjectFileDir($module, $client = '', $component = self::COMPONENTVIEW, $seed = null)
 {
     require_once 'modules/ModuleBuilder/Module/StudioModule.php';
     $sm = StudioModuleFactory::getStudioModule($module, $seed);
     $dirname = 'include/SugarObjects/templates/' . $sm->getType();
     if (!empty($client)) {
         $dirname .= '/clients/' . $client . '/' . $component . 's';
     } else {
         $dirname .= '/metadata';
     }
     return $dirname;
 }
    /**
     * Load current Sugar metadata for this module
     * 
     * @return array
     */
    protected function loadDefaultMetadata()
    {
        $client = $this->client == 'wireless' ? 'mobile' : $this->client;
        // The new defs array - this should contain OOTB defs for the module
        $newdefs = $viewdefs = array();
        $viewname = MetaDataFiles::getName($this->viewtype);
        if (!$viewname) {
            $viewname = $this->viewtype;
        }
        // Bug 55568 - new metadata was not included for custom metadata
        // conversion from pre-6.6 installations.
        // Grab the new metadata for this module. For undeployed modules we
        // need to get the metadata from the SugarObject type.
        // If there are defs for this module, grab them
        $this->defsfile = 'modules/' . $this->module . '/clients/' . $client . '/views/' . $viewname . '/' . $viewname . '.php';
        if (file_exists($this->defsfile)) {
            require $this->defsfile;
            if (isset($viewdefs[$this->module][$client]['view'][$viewname])) {
                $newdefs = $viewdefs[$this->module][$client]['view'][$viewname];
            }
        }
        // Fallback to the object type if there were no defs found
        // Bug 57216 - Upgrade wizard was dying on undeployed modules getType
        if (empty($newdefs)) {
            if ($this->deployed) {
                require_once 'modules/ModuleBuilder/Module/StudioModuleFactory.php';
                $sm = StudioModuleFactory::getStudioModule($this->module);
                $moduleType = $sm->getType();
            } elseif ($this->package) {
                require_once 'modules/ModuleBuilder/MB/ModuleBuilder.php';
                $mb = new ModuleBuilder();
                $package = $mb->getPackage($this->package);
                $module = $package->getModule($this->module);
                $moduleType = $module->getModuleType();
            }
            if (!empty($moduleType)) {
                $this->base_defsfile = 'include/SugarObjects/templates/' . $moduleType . '/clients/' . $client . '/views/' . $viewname . '/' . $viewname . '.php';
                if (file_exists($this->base_defsfile)) {
                    require $this->base_defsfile;
                } else {
                    $this->base_defsfile = 'include/SugarObjects/templates/basic/clients/' . $client . '/views/' . $viewname . '/' . $viewname . '.php';
                    if (file_exists($this->base_defsfile)) {
                        require $this->base_defsfile;
                    } else {
                        $this->logUpgradeStatus("Could not find basic {$viewname} template for module {$this->module} type {$moduleType}");
                    }
                }
                // See if there are viewdefs defined that we can use
                if (isset($viewdefs['<module_name>'][$client]['view'][$viewname])) {
                    //Need to perform variable replacement for some field defs
                    $module = $this->getNormalizedModuleName();
                    $convertedDefs = MetaDataFiles::getModuleMetaDataDefsWithReplacements($module, $viewdefs);
                    if (isset($convertedDefs[$module][$client]['view'][$viewname])) {
                        $newdefs = $convertedDefs[$module][$client]['view'][$viewname];
                    } else {
                        $newdefs = $viewdefs['<module_name>'][$client]['view'][$viewname];
                    }
                }
                // Only write a defs file for deployed modules
                if ($newdefs && $this->deployed) {
                    // If we used the template, create the basic one
                    $this->logUpgradeStatus(get_class($this) . ": Copying template defs {$this->base_defsfile} to {$this->defsfile}");
                    mkdir_recursive(dirname($this->defsfile));
                    $viewname = pathinfo($this->defsfile, PATHINFO_FILENAME);
                    $export = var_export($newdefs, true);
                    $data = <<<END
<?php
/* Generated by SugarCRM Upgrader */
\$viewdefs['{$this->module}']['{$client}']['view']['{$viewname}'] = {$export};
END;
                    sugar_file_put_contents($this->defsfile, $data);
                }
            }
        }
        return $newdefs;
    }
Example #25
0
 function display()
 {
     $selected_lang = !empty($_REQUEST['relationship_lang']) ? $_REQUEST['relationship_lang'] : $_SESSION['authenticated_user_language'];
     $this->smarty = new Sugar_Smarty();
     $ac = new AjaxCompose();
     $this->fromModuleBuilder = isset($_REQUEST['MB']) || !empty($_REQUEST['view_package']) && $_REQUEST['view_package'] != 'studio';
     $this->smarty->assign('fromModuleBuilder', $this->fromModuleBuilder);
     if (!$this->fromModuleBuilder) {
         $module = StudioModuleFactory::getStudioModule($_REQUEST['view_module']);
         $moduleName = $_REQUEST['view_module'];
         $fields = $module->fields;
         require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php';
         $relatableModules = DeployedRelationships::findRelatableModules();
         $appStrings = return_app_list_strings_language($selected_lang);
         $modStrings = return_module_language($selected_lang, $_REQUEST['view_module'], true);
         $appStrings = $appStrings['moduleList'];
     } else {
         $mb = new ModuleBuilder();
         $mb->getPackages();
         //display the latest module name rather than what is in or not in the loaded app_list_strings.
         $mb->getPackage($_REQUEST['view_package'])->loadModuleTitles();
         $module = $mb->getPackageModule($_REQUEST['view_package'], $_REQUEST['view_module']);
         $moduleName = empty($module->key_name) ? $module->getModuleName() : $module->key_name;
         $this->smarty->assign('view_package', $_REQUEST['view_package']);
         $mbvardefs = $module->getVardefs();
         $fields = $mbvardefs['fields'];
         require_once 'modules/ModuleBuilder/parsers/relationships/UndeployedRelationships.php';
         $relatableModules = UndeployedRelationships::findRelatableModules();
         $appStrings = $module->getModStrings($selected_lang);
     }
     ksort($relatableModules);
     $lhs_subpanels = $module->getProvidedSubpanels();
     // Fix to re-add sorting of the subpanel names so that the 'default' subpanel always appears first in the list.
     // This assumes that subpanels are usually named ForXYZ which is the case currently, and hence 'default' will be sorted first.
     //I f this assumption is incorrect, then a better solution would be to remove 'default' from the subpanel list, then sort, and finally array_unshift it back on.
     natcasesort($lhs_subpanels);
     $cardinality = array(MB_ONETOONE => translate('LBL_ONETOONE'), MB_ONETOMANY => translate('LBL_ONETOMANY'), MB_MANYTOONE => translate('LBL_MANYTOONE'), MB_MANYTOMANY => translate('LBL_MANYTOMANY'));
     if (!$this->fromModuleBuilder) {
         unset($cardinality[MB_MANYTOONE]);
     }
     $relationships = $module->getRelationships();
     // if a description for this relationship already exists, then load it so it can be modified
     if (!empty($_REQUEST['relationship_name'])) {
         $relationship = $relationships->get($_REQUEST['relationship_name']);
         $relationship->setName($_REQUEST['relationship_name']);
         $definition = $relationship->getDefinition();
         if (!$this->fromModuleBuilder) {
             $modStrings = return_module_language($selected_lang, $relationship->rhs_module, true);
             $definition['lhs_label'] = isset($modStrings[$relationship->getTitleKey()]) ? $modStrings[$relationship->getTitleKey()] : $relationship->lhs_module;
             $modStrings = return_module_language($selected_lang, $relationship->lhs_module, true);
             $definition['rhs_label'] = isset($modStrings[$relationship->getTitleKey(true)]) ? $modStrings[$relationship->getTitleKey(true)] : $relationship->rhs_module;
         } else {
             #30624
             if (!empty($_REQUEST['rhs_module'])) {
                 $definition['rhs_label'] = $_REQUEST['rhs_module'];
             }
         }
     } else {
         $definition = array();
         $firstModuleDefinition = each($relatableModules);
         $definition['rhs_module'] = $firstModuleDefinition['key'];
         $definition['lhs_module'] = $moduleName;
         $definition['lhs_label'] = translate($moduleName);
         $definition['relationship_type'] = MB_MANYTOMANY;
     }
     // load the relationship from post - required as we can call view.relationship.php from Ajax when changing the rhs_module for example
     $definition = $this->overrideDefinitionFromPOST($definition);
     if (empty($definition['rhs_label'])) {
         $definition['rhs_label'] = translate($definition['rhs_module']);
     }
     if (empty($definition['lhs_label'])) {
         $definition['lhs_label'] = translate($definition['lhs_module']);
     }
     $relationship = RelationshipFactory::newRelationship($definition);
     $rhs_subpanels = $relatableModules[$relationship->rhs_module];
     // Fix to re-add sorting of the subpanel names so that the 'default' subpanel always appears first in the list. This assumes that subpanels are usually named ForXYZ which is the case currently, and hence 'default' will be sorted first. If this assumption is incorrect, then a better solution would be to remove 'default' from the subpanel list, then sort, and finally array_unshift it back on.
     natcasesort($rhs_subpanels);
     if (empty($_REQUEST['relationship_name'])) {
         // tidy up the options for the view based on the modules participating in the relationship and the cardinality
         // some modules (e.g., Knowledge Base/KBDocuments) lack subpanels. That means they can't be the lhs of a 1-many or many-many, or the rhs of a many-many for example
         // fix up the available cardinality options
         $relationship_type = $relationship->getType();
         if (count($lhs_subpanels) == 0 || count($rhs_subpanels) == 0) {
             unset($cardinality[MB_MANYTOMANY]);
         }
         if (count($rhs_subpanels) == 0) {
             unset($cardinality[MB_ONETOMANY]);
         }
         if (isset($definition['rhs_module']) && $definition['rhs_module'] == 'Activities') {
             $cardinality = array(MB_ONETOMANY => translate('LBL_ONETOMANY'));
         }
         //Bug 23139, Campaigns module current cannot display custom subpanels, so we need to ban it from any
         //relationships that would require a new subpanel to be shown in Campaigns.
         if (isset($definition['lhs_module']) && $definition['lhs_module'] == 'Campaigns') {
             unset($cardinality[MB_MANYTOMANY]);
             unset($cardinality[MB_ONETOMANY]);
         }
         if (isset($definition['rhs_module']) && $definition['rhs_module'] == 'Campaigns' && isset($cardinality[MB_MANYTOMANY])) {
             unset($cardinality[MB_MANYTOMANY]);
             unset($cardinality[MB_MANYTOONE]);
         }
         if (!isset($cardinality[$relationship->getType()])) {
             end($cardinality);
             $definition['relationship_type'] = key($cardinality);
             $relationship = RelationshipFactory::newRelationship($definition);
         }
         $this->smarty->assign('is_new', true);
     } else {
         $this->smarty->assign('is_new', false);
     }
     //Remove Activities if one-to-many is not availible
     if (!isset($cardinality[MB_ONETOMANY]) && isset($relatableModules['Activities'])) {
         unset($relatableModules['Activities']);
     }
     // now enforce the relationship_only requirement - that is, only construct the underlying relationship and link fields, and not the UI, if the subpanel code will have troubles displaying the UI
     $relationships->enforceRelationshipOnly($relationship);
     $this->smarty->assign('view_module', $_REQUEST['view_module']);
     $this->smarty->assign('rel', $relationship->getDefinition());
     $this->smarty->assign('mod_strings', $GLOBALS['mod_strings']);
     $this->smarty->assign('module_key', $relationship->lhs_module);
     $this->smarty->assign('cardinality', array_keys($cardinality));
     $this->smarty->assign('translated_cardinality', $cardinality);
     $this->smarty->assign('selected_cardinality', translate($relationship->getType()));
     $relatable = array();
     foreach ($relatableModules as $name => $dummy) {
         $relatable[$name] = translate($name);
     }
     unset($relatable['KBDocuments']);
     natcasesort($relatable);
     $this->smarty->assign('relatable', array_keys($relatable));
     $this->smarty->assign('translated_relatable', $relatable);
     $this->smarty->assign('rhspanels', $rhs_subpanels);
     $this->smarty->assign('lhspanels', $lhs_subpanels);
     $this->smarty->assign('selected_lang', $selected_lang);
     $this->smarty->assign('available_languages', get_languages());
     switch ($relationship->relationship_type) {
         case MB_ONETOONE:
             break;
         case MB_ONETOMANY:
             if (empty($relationship->relationship_column_name)) {
                 $validRoleColumnFields = array();
                 foreach ($fields as $field) {
                     $validRoleColumnFields[] = $field;
                 }
                 $this->smarty->assign('relationship_role_column_enum', $validRoleColumnFields);
             }
             if (!empty($relationship->relationship_role_column_value)) {
                 $this->smarty->assign('relationship_role_column_value', $relationship->relationship_role_column_value);
             }
             break;
         case MB_MANYTOMANY:
             if (!empty($relationship->relationship_role_column_value)) {
                 $this->smarty->assign('relationship_role_column_value', $relationship->relationship_role_column_value);
             }
             break;
     }
     //see if we use the new system
     if (isset($_REQUEST['json']) && $_REQUEST['json'] == 'false') {
         echo $this->smarty->fetch('modules/ModuleBuilder/tpls/studioRelationship.tpl');
     } else {
         $ac->addSection('east', $module->name . ' ' . $GLOBALS['mod_strings']['LBL_RELATIONSHIPS'], $this->smarty->fetch('modules/ModuleBuilder/tpls/studioRelationship.tpl'));
         echo $ac->getJavascript();
     }
 }
Example #26
0
 public function processSugarPortal($ajax)
 {
     $this->ajax->addCrumb(translate('LBL_SUGARPORTAL'), 'ModuleBuilder.main("sugarportal")');
     if (isset($this->editModule)) {
         $module = StudioModuleFactory::getStudioModule($this->editModule);
         $this->generateSugarPortalViewButtons();
         $this->title = $module->name;
         $this->question = translate('LBL_QUESTION_SUGAR_PORTAL');
         $this->ajax->addCrumb(translate('LBL_LAYOUTS'), 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&portal=1&view=layout")');
         $this->ajax->addCrumb($module->name, 'ModuleBuilder.getContent("module=ModuleBuilder&action=wizard&portal=1&view_module=' . $this->editModule . '")');
         $this->help = 'layoutsHelp';
     } elseif (isset($_REQUEST['layout'])) {
         // SugarPortal Layouts Page
         $this->generateSugarPortalModuleButtons();
         $this->question = translate('LBL_QUESTION_MODULE1');
         $this->title = translate('LBL_SUGARPORTAL');
         $this->help = 'portalLayoutHelp';
     } else {
         //Main SugarPortal Page
         $this->generateSugarPortalMainButtons();
         $this->question = translate('LBL_QUESTION_FUNCTION');
         $this->title = translate('LBL_SUGARPORTAL');
         $this->help = 'portalHelp';
     }
 }