コード例 #1
0
ファイル: CoreFnCrm.php プロジェクト: juanOspina13/SRX
 public static function getRelationship($modulo)
 {
     $bean = BeanFactory::newBean($modulo);
     require_once "modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php";
     $res = array();
     $x = new DeployedRelationships($modulo);
     $res = array();
     //print_r($bean->field_name_map);
     foreach ($bean->field_name_map as $field => $data) {
         if ($data['type'] === 'link') {
             if ($def = $x->get($data['relationship'])) {
                 $def = $def->getDefinition();
                 if ($def['relationship_type'] == 'many-to-many') {
                     continue;
                 } elseif ($def['lhs_module'] == $modulo && $def['relationship_type'] == 'one-to-many') {
                     continue;
                 } else {
                     $res[$data['name']] = "{$data['name']} : {$def['lhs_module']} {$def['relationship_type']} {$def['rhs_module']}";
                 }
                 //print_r($def);
             }
         }
     }
     return $res;
 }
コード例 #2
0
ファイル: CoreFnPdf.php プロジェクト: juanOspina13/SRX
 /**
  *	Esta funcion devuelve los tags disponibles para el PDF
  */
 public static function getTags($plantilla_id)
 {
     require_once "modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php";
     $res = array();
     $plantilla_bean = BeanFactory::getBean('opalo_plantillas', $plantilla_id);
     $modulo = $plantilla_bean->pariente;
     $relaciones = unencodeMultienum($plantilla_bean->relaciones);
     ///CARGA LOS CAMPOS DEL MODULO
     $bean = BeanFactory::newBean($modulo);
     foreach ($bean->field_name_map as $campo => $data) {
         $res[$campo] = $data['type'];
     }
     $x = new DeployedRelationships($modulo);
     ///CARGA LOS CAMPOS DE LA RELACION <relationship_name>::<field_name>
     foreach ($relaciones as $relation) {
         $rel = $bean->field_name_map[$relation]['relationship'];
         $def = $x->get($rel)->getDefinition();
         $otro_modulo = $def['rhs_module'];
         if ($modulo == $def['rhs_module']) {
             $otro_modulo = $def['lhs_module'];
         }
         $bean_seg = BeanFactory::newBean($otro_modulo);
         foreach ($bean_seg->field_name_map as $campo => $data) {
             $res[$relation . "::" . $campo] = $data['type'];
         }
         $bean->load_relationship($relation);
     }
     return $res;
 }
コード例 #3
0
/**
 * Searches through the installed relationships to find broken self referencing one-to-many relationships 
 * (wrong field used in the subpanel, and the left link not marked as left)
 */
function upgrade_custom_relationships($modules = array())
{
    global $current_user, $moduleList;
    if (!is_admin($current_user)) {
        sugar_die($GLOBALS['app_strings']['ERR_NOT_ADMIN']);
    }
    require_once "modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php";
    require_once "modules/ModuleBuilder/parsers/relationships/OneToManyRelationship.php";
    if (empty($modules)) {
        $modules = $moduleList;
    }
    foreach ($modules as $module) {
        $depRels = new DeployedRelationships($module);
        $relList = $depRels->getRelationshipList();
        foreach ($relList as $relName) {
            $relObject = $depRels->get($relName);
            $def = $relObject->getDefinition();
            //We only need to fix self referencing one to many relationships
            if ($def['lhs_module'] == $def['rhs_module'] && $def['is_custom'] && $def['relationship_type'] == "one-to-many") {
                $layout_defs = array();
                if (!is_dir("custom/Extension/modules/{$module}/Ext/Layoutdefs") || !is_dir("custom/Extension/modules/{$module}/Ext/Vardefs")) {
                    continue;
                }
                //Find the extension file containing the vardefs for this relationship
                foreach (scandir("custom/Extension/modules/{$module}/Ext/Vardefs") as $file) {
                    if (substr($file, 0, 1) != "." && strtolower(substr($file, -4)) == ".php") {
                        $dictionary = array($module => array("fields" => array()));
                        $filePath = "custom/Extension/modules/{$module}/Ext/Vardefs/{$file}";
                        include $filePath;
                        if (isset($dictionary[$module]["fields"][$relName])) {
                            $rhsDef = $dictionary[$module]["fields"][$relName];
                            //Update the vardef for the left side link field
                            if (!isset($rhsDef['side']) || $rhsDef['side'] != 'left') {
                                $rhsDef['side'] = 'left';
                                $fileContents = file_get_contents($filePath);
                                $out = preg_replace('/\\$dictionary[\\w"\'\\[\\]]*?' . $relName . '["\'\\[\\]]*?\\s*?=\\s*?array\\s*?\\(.*?\\);/s', '$dictionary["' . $module . '"]["fields"]["' . $relName . '"]=' . var_export_helper($rhsDef) . ";", $fileContents);
                                file_put_contents($filePath, $out);
                            }
                        }
                    }
                }
                //Find the extension file containing the subpanel definition for this relationship
                foreach (scandir("custom/Extension/modules/{$module}/Ext/Layoutdefs") as $file) {
                    if (substr($file, 0, 1) != "." && strtolower(substr($file, -4)) == ".php") {
                        $layout_defs = array($module => array("subpanel_setup" => array()));
                        $filePath = "custom/Extension/modules/{$module}/Ext/Layoutdefs/{$file}";
                        include $filePath;
                        foreach ($layout_defs[$module]["subpanel_setup"] as $key => $subDef) {
                            if ($layout_defs[$module]["subpanel_setup"][$key]['get_subpanel_data'] == $relName) {
                                $fileContents = file_get_contents($filePath);
                                $out = preg_replace('/[\'"]get_subpanel_data[\'"]\\s*=>\\s*[\'"]' . $relName . '[\'"],/s', "'get_subpanel_data' => '{$def["join_key_lhs"]}',", $fileContents);
                                file_put_contents($filePath, $out);
                            }
                        }
                    }
                }
            }
        }
    }
}
コード例 #4
0
 protected function constructSmarty()
 {
     $smarty = new Sugar_Smarty();
     $smarty->assign('translate', true);
     $smarty->assign('language', "Leads");
     $smarty->assign('view_module', "Leads");
     $smarty->assign('module', "Leads");
     $smarty->assign('helpName', 'listViewEditor');
     $smarty->assign('helpDefault', 'modify');
     $smarty->assign('title', 'Convert Layout');
     $modules = $this->getModulesFromDefs();
     $smarty->assign('modules', $this->jsonHelper->encode($modules));
     require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php';
     $relatableModules = DeployedRelationships::findRelatableModules();
     //pull out modules that have already been chosen
     foreach ($modules as $mDef) {
         if (isset($relatableModules[$mDef['module']])) {
             unset($relatableModules[$mDef['module']]);
         }
     }
     $displayModules = array();
     $moduleDefaults = array();
     foreach ($relatableModules as $mod => $def) {
         if ($this->parser->isModuleAllowedInConvert($mod)) {
             $displayModules[$mod] = translate($mod);
             $moduleDefaults[$mod] = $this->parser->getDefaultDefForModule($mod);
         }
     }
     $smarty->assign('availableModules', $displayModules);
     $smarty->assign('moduleDefaults', $this->jsonHelper->encode($moduleDefaults));
     return $smarty;
 }
コード例 #5
0
ファイル: Bug53223Test.php プロジェクト: delkyd/sugarcrm_dev
 private function deleteRelationship($lhs_module, $rhs_module = null, $rel_name = null)
 {
     $rhs_module = $rhs_module == null ? $lhs_module : $rhs_module;
     $this->relationships = new DeployedRelationships($lhs_module);
     $this->relationships->delete($rel_name !== null ? $rel_name : $this->relationship->getName());
     $this->relationships->save();
     SugarRelationshipFactory::deleteCache();
     LanguageManager::clearLanguageCache($lhs_module);
     if ($lhs_module != $rhs_module) {
         LanguageManager::clearLanguageCache($rhs_module);
     }
 }
コード例 #6
0
ファイル: relate.php プロジェクト: aldridged/gtg-sugar
function get_body(&$ss, $vardef)
{
    $modules = array();
    require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php';
    $relatableModules = array_keys(DeployedRelationships::findRelatableModules());
    foreach ($relatableModules as $module) {
        $modules[$module] = translate('LBL_MODULE_NAME', $module);
    }
    foreach (ACLController::disabledModuleList($modules, false, 'list') as $disabled_parent_type) {
        unset($modules[$disabled_parent_type]);
    }
    unset($modules[""]);
    unset($modules['Activities']);
    // cannot relate to Activities as only Activities' submodules have records; use a Flex Relate instead!
    // tyoung bug 18631 - reduce potential confusion when creating a relate custom field for Products - actually points to the Product Catalog, so label it that way in the drop down list
    if (isset($modules['ProductTemplates']) && $modules['ProductTemplates'] == 'Product') {
        $modules['ProductTemplates'] = translate('LBL_MODULE_NAME', 'ProductTemplates');
    }
    $ss->assign('modules', $modules);
    return $ss->fetch('modules/DynamicFields/templates/Fields/Forms/relate.tpl');
}
コード例 #7
0
ファイル: uw_utils.php プロジェクト: omusico/sugar_work
function repair_long_relationship_names($path = '')
{
    logThis("Begin repair_long_relationship_names", $path);
    require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php';
    $GLOBALS['mi_remove_tables'] = false;
    $touched = array();
    foreach ($GLOBALS['moduleList'] as $module) {
        $relationships = new DeployedRelationships($module);
        foreach ($relationships->getRelationshipList() as $rel_name) {
            if (strlen($rel_name) > 27 && empty($touched[$rel_name])) {
                logThis("Rebuilding relationship fields for {$rel_name}", $path);
                $touched[$rel_name] = true;
                $rel_obj = $relationships->get($rel_name);
                $rel_obj->setReadonly(false);
                $relationships->delete($rel_name);
                $relationships->save();
                $relationships->add($rel_obj);
                $relationships->save();
                $relationships->build();
            }
        }
    }
    logThis("End repair_long_relationship_names", $path);
}
コード例 #8
0
 function action_SaveRelationshipLabel()
 {
     $selected_lang = !empty($_REQUEST['relationship_lang']) ? $_REQUEST['relationship_lang'] : $_SESSION['authenticated_user_language'];
     if (empty($_REQUEST['view_package'])) {
         require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php';
         $relationships = new DeployedRelationships($_REQUEST['view_module']);
         if (!empty($_REQUEST['relationship_name'])) {
             if ($relationship = $relationships->get($_REQUEST['relationship_name'])) {
                 $metadata = $relationship->buildLabels(true);
                 require_once 'modules/ModuleBuilder/parsers/parser.label.php';
                 $parser = new ParserLabel($_REQUEST['view_module']);
                 $parser->handleSaveRelationshipLabels($metadata, $selected_lang);
             }
         }
     } else {
         //TODO FOR MB
     }
     $this->view = 'relationships';
 }
コード例 #9
0
ファイル: view.resetmodule.php プロジェクト: MexinaD/SuiteCRM
 /**
  * Removes all custom relationships containing this module
  * 
  * @return html output record of the files deleted
  */
 function removeCustomRelationships()
 {
     require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php';
     $out = "";
     $madeChanges = false;
     $relationships = new DeployedRelationships($this->module);
     foreach ($relationships->getRelationshipList() as $relationshipName) {
         $rel = $relationships->get($relationshipName)->getDefinition();
         if ($rel['is_custom'] || isset($rel['from_studio']) && $rel['from_studio']) {
             $relationships->delete($relationshipName);
             $out .= "Removed relationship {$relationshipName}<br/>";
         }
     }
     if ($madeChanges) {
         $relationships->save();
     }
     return $out;
 }
コード例 #10
0
 function fetch($ac = false)
 {
     $fv = new FieldViewer();
     if (empty($_REQUEST['field']) && !empty($_REQUEST['name'])) {
         $_REQUEST['field'] = $_REQUEST['name'];
     }
     $field_name = '';
     if (!empty($this->view_object_map['field_name'])) {
         $field_name = $this->view_object_map['field_name'];
     } elseif (!empty($_REQUEST['field'])) {
         $field_name = $_REQUEST['field'];
     } else {
         $field_name = '';
     }
     $action = 'saveField';
     // tyoung bug 17606: default action is to save as a dynamic field; but for standard OOB
     // fields we override this so don't create a new dynamic field instead of updating the existing field
     $isClone = false;
     if (!empty($this->view_object_map['is_clone']) && $this->view_object_map['is_clone'] && strcmp($field_name, "name") != 0) {
         $isClone = true;
     }
     /*
     $field_types =  array('varchar'=>'YourField', 'int'=>'Integer', 'float'=>'Decimal','bool'=>'Checkbox','enum'=>'DropDown',
     		'date'=>'Date', 'phone' => 'Phone', 'currency' => 'Currency', 'html' => 'HTML', 'radioenum' => 'Radio',
     		'relate' => 'Relate', 'address' => 'Address', 'text' => 'TextArea', 'url' => 'Link');
     */
     $field_types = $GLOBALS['mod_strings']['fieldTypes'];
     if (isset($field_types['encrypt'])) {
         unset($field_types['encrypt']);
     }
     $field_name_exceptions = array('ADD', 'EXCEPT', 'PERCENT', 'ALL', 'EXEC', 'PLAN', 'ALTER', 'EXECUTE', 'PRECISION', 'AND', 'EXISTS', 'PRIMARY', 'ANY', 'EXIT', 'PRINT', 'AS', 'FETCH', 'PROC', 'ASC', 'FILE', 'PROCEDURE', 'AUTHORIZATION', 'FILLFACTOR', 'PUBLIC', 'BACKUP', 'FOR', 'RAISERROR', 'BEGIN', 'FOREIGN', 'READ', 'BETWEEN', 'FREETEXT', 'READTEXT', 'BREAK', 'FREETEXTTABLE', 'RECONFIGURE', 'BROWSE', 'FROM', 'REFERENCES', 'BULK', 'FULL', 'REPLICATION', 'BY', 'FUNCTION', 'RESTORE', 'CASCADE', 'GOTO', 'RESTRICT', 'CASE', 'GRANT', 'RETURN', 'CHECK', 'GROUP', 'REVOKE', 'CHECKPOINT', 'HAVING', 'RIGHT', 'CLOSE', 'HOLDLOCK', 'ROLLBACK', 'CLUSTERED', 'IDENTITY', 'ROWCOUNT', 'COALESCE', 'IDENTITY_INSERT', 'ROWGUIDCOL', 'COLLATE', 'IDENTITYCOL', 'RULE', 'COLUMN', 'IF', 'SAVE', 'COMMIT', 'IN', 'SCHEMA', 'COMPUTE', 'INDEX', 'SELECT', 'CONSTRAINT', 'INNER', 'SESSION_USER', 'CONTAINS', 'INSERT', 'SET', 'CONTAINSTABLE', 'INTERSECT', 'SETUSER', 'CONTINUE', 'INTO', 'SHUTDOWN', 'CONVERT', 'IS', 'SOME', 'CREATE', 'JOIN', 'STATISTICS', 'CROSS', 'KEY', 'SYSTEM_USER', 'CURRENT', 'KILL', 'TABLE', 'CURRENT_DATE', 'LEFT', 'TEXTSIZE', 'CURRENT_TIME', 'LIKE', 'THEN', 'CURRENT_TIMESTAMP', 'LINENO', 'TO', 'CURRENT_USER', 'LOAD', 'TOP', 'CURSOR', 'NATIONAL', 'TRAN', 'DATABASE', 'NOCHECK', 'TRANSACTION', 'DBCC', 'NONCLUSTERED', 'TRIGGER', 'DEALLOCATE', 'NOT', 'TRUNCATE', 'DECLARE', 'NULL', 'TSEQUAL', 'DEFAULT', 'NULLIF', 'UNION', 'DELETE', 'OF', 'UNIQUE', 'DENY', 'OFF', 'UPDATE', 'DESC', 'OFFSETS', 'UPDATETEXT', 'DISK', 'ON', 'USE', 'DISTINCT', 'OPEN', 'USER', 'DISTRIBUTED', 'OPENCONNECTOR', 'VALUES', 'DOUBLE', 'OPENQUERY', 'VARYING', 'DROP', 'OPENROWSET', 'VIEW', 'DUMMY', 'OPENXML', 'WAITFOR', 'DUMP', 'OPTION', 'WHEN', 'ELSE', 'OR', 'WHERE', 'END', 'ORDER', 'WHILE', 'ERRLVL', 'OUTER', 'WITH', 'ESCAPE', 'OVER', 'WRITETEXT', 'ANALYZE', 'ASENSITIVE', 'BEFORE', 'BIGINT', 'BINARY', 'BOTH', 'CALL', 'CHANGE', 'CHARACTER', 'CONDITION', 'DATABASES', 'DAY_HOUR', 'DAY_MICROSECOND', 'DAY_MINUTE', 'DAY_SECOND', 'DEC', 'DECIMAL', 'DELAYED', 'DESCRIBE', 'DETERMINISTIC', 'DISTINCTROW', 'DIV', 'DUAL', 'EACH', 'ELSEIF', 'ENCLOSED', 'ESCAPED', 'EXPLAIN', 'FALSE', 'FLOAT', 'FLOAT4', 'FLOAT8', 'FORCE', 'FULLTEXT', 'HIGH_PRIORITY', 'HOUR_MICROSECOND', 'HOUR_MINUTE', 'HOUR_SECOND', 'IGNORE', 'INFILE', 'INOUT', 'INSENSITIVE', 'INT', 'INT1', 'INT2', 'INT3', 'INT4', 'INT8', 'INTEGER', 'ITERATE', 'KEYS', 'LEADING', 'LEAVE', 'LIMIT', 'LINES', 'LOCALTIME', 'LOCALTIMESTAMP', 'LOCK', 'LONGBLOB', 'LONGTEXT', 'LOOP', 'LOW_PRIORITY', 'MATCH', 'MEDIUMBLOB', 'MEDIUMINT', 'MEDIUMTEXT', 'MIDDLEINT', 'MINUTE_MICROSECOND', 'MINUTE_SECOND', 'MOD', 'MODIFIES', 'NATURAL', 'NO_WRITE_TO_BINLOG', 'NUMERIC', 'OPTIMIZE', 'OPTIONALLY', 'OUT', 'OUTFILE', 'PURGE', 'READS', 'REAL', 'REGEXP', 'RELEASE', 'RENAME', 'REPEAT', 'REPLACE', 'REQUIRE', 'RLIKE', 'SCHEMAS', 'SECOND_MICROSECOND', 'SENSITIVE', 'SEPARATOR', 'SHOW', 'SMALLINT', 'SONAME', 'SPATIAL', 'SPECIFIC', 'SQL', 'SQLEXCEPTION', 'SQLSTATE', 'SQLWARNING', 'SQL_BIG_RESULT', 'SQL_CALC_FOUND_ROWS', 'SQL_SMALL_RESULT', 'SSL', 'STARTING', 'STRAIGHT_JOIN', 'TERMINATED', 'TINYBLOB', 'TINYINT', 'TINYTEXT', 'TRAILING', 'TRUE', 'UNDO', 'UNLOCK', 'UNSIGNED', 'USAGE', 'USING', 'UTC_DATE', 'UTC_TIME', 'UTC_TIMESTAMP', 'VARBINARY', 'VARCHARACTER', 'WRITE', 'XOR', 'YEAR_MONTH', 'ZEROFILL', 'CONNECTION', 'LABEL', 'UPGRADE', 'DATE', 'VARCHAR', 'VARCHAR2', 'NVARCHAR2', 'CHAR', 'NCHAR', 'NUMBER', 'PLS_INTEGER', 'BINARY_INTEGER', 'LONG', 'TIMESTAMP', 'INTERVAL', 'RAW', 'ROWID', 'UROWID', 'MLSLABEL', 'CLOB', 'NCLOB', 'BLOB', 'BFILE', 'XMLTYPE', 'ID', 'ID_C', 'PARENT_NAME', 'PARENT_ID');
     //C.L. - Add support to mark related module id columns as reserved keywords
     require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php';
     $relatedModules = array_keys(DeployedRelationships::findRelatableModules());
     global $beanList, $current_language;
     foreach ($relatedModules as $relModule) {
         if (isset($beanList[$relModule])) {
             $field_name_exceptions[] = strtoupper($beanList[$relModule]) . '_ID';
         }
     }
     if (empty($_REQUEST['view_package']) || $_REQUEST['view_package'] == 'studio') {
         $moduleName = $_REQUEST['view_module'];
         $objectName = BeanFactory::getObjectName($moduleName);
         $module = BeanFactory::getBean($moduleName);
         VardefManager::loadVardef($moduleName, $objectName, true);
         global $dictionary;
         // Fix for issue #1177 - when trying to add or edit fields in a module an error message is shown:
         // "Warning: Creating default object from empty value"
         if (!isset($module->mbvardefs) || is_null($module->mbvardefs)) {
             $module->mbvardefs = new stdClass();
         }
         $module->mbvardefs->vardefs = $dictionary[$objectName];
         $module->name = $moduleName;
         if (!$ac) {
             $ac = new AjaxCompose();
         }
         $vardef = !empty($module->mbvardefs->vardefs['fields'][$field_name]) ? $module->mbvardefs->vardefs['fields'][$field_name] : array();
         if ($isClone) {
             unset($vardef['name']);
         }
         if (empty($vardef['name'])) {
             if (!empty($_REQUEST['type'])) {
                 $vardef['type'] = $_REQUEST['type'];
             }
             $fv->ss->assign('hideLevel', 0);
         } elseif (isset($vardef['custom_module'])) {
             $fv->ss->assign('hideLevel', 2);
         } else {
             $action = 'saveSugarField';
             // tyoung - for OOB fields we currently only support modifying the label
             $fv->ss->assign('hideLevel', 3);
         }
         if ($isClone && isset($vardef['type']) && $vardef['type'] == 'datetime') {
             $vardef['type'] = 'datetimecombo';
         }
         require_once 'modules/DynamicFields/FieldCases.php';
         $tf = get_widget(empty($vardef['type']) ? "" : $vardef['type']);
         $tf->module = $module;
         $tf->populateFromRow($vardef);
         $vardef = array_merge($vardef, $tf->get_field_def());
         //          $GLOBALS['log']->debug('vardefs after loading = '.print_r($vardef,true));
         //Check if autoincrement fields are allowed
         $allowAutoInc = true;
         $enumFields = array();
         foreach ($module->field_defs as $field => $def) {
             if (!empty($def['type']) && $def['type'] == "int" && !empty($def['auto_increment'])) {
                 $allowAutoInc = false;
                 continue;
             }
             if (!empty($def['type']) && $def['type'] == "enum" && $field != $vardef['name']) {
                 if (!empty($def['studio']) && $def['studio'] == "false") {
                     continue;
                 }
                 //bug51866
                 $enumFields[$field] = translate($def['vname'], $moduleName);
                 if (substr($enumFields[$field], -1) == ":") {
                     $enumFields[$field] = substr($enumFields[$field], 0, strlen($enumFields[$field]) - 1);
                 }
             }
         }
         $fv->ss->assign('allowAutoInc', $allowAutoInc);
         $GLOBALS['log']->warn('view.modulefield: hidelevel ' . $fv->ss->get_template_vars('hideLevel') . " " . print_r($vardef, true));
         if (!empty($vardef['vname'])) {
             $fv->ss->assign('lbl_value', htmlentities(translate($vardef['vname'], $moduleName), ENT_QUOTES, 'UTF-8'));
         }
         $fv->ss->assign('module', $module);
         if (empty($module->mbvardefs->vardefs['fields']['parent_name']) || isset($vardef['type']) && $vardef['type'] == 'parent') {
             $field_types['parent'] = $GLOBALS['mod_strings']['parent'];
         }
         $edit_or_add = 'editField';
     } else {
         require_once 'modules/ModuleBuilder/MB/ModuleBuilder.php';
         $mb = new ModuleBuilder();
         $moduleName = $_REQUEST['view_module'];
         $module =& $mb->getPackageModule($_REQUEST['view_package'], $moduleName);
         $package =& $mb->packages[$_REQUEST['view_package']];
         $module->getVardefs();
         if (!$ac) {
             $ac = new AjaxCompose();
         }
         $vardef = !empty($module->mbvardefs->vardefs['fields'][$field_name]) ? $module->mbvardefs->vardefs['fields'][$field_name] : array();
         if ($isClone) {
             unset($vardef['name']);
         }
         if (empty($vardef['name'])) {
             if (!empty($_REQUEST['type'])) {
                 $vardef['type'] = $_REQUEST['type'];
             }
             $fv->ss->assign('hideLevel', 0);
         } else {
             if (!empty($module->mbvardefs->vardef['fields'][$vardef['name']])) {
                 $fv->ss->assign('hideLevel', 1);
             } elseif (isset($vardef['custom_module'])) {
                 $fv->ss->assign('hideLevel', 2);
             } else {
                 $fv->ss->assign('hideLevel', 3);
                 // tyoung bug 17350 - effectively mark template derived fields as readonly
             }
         }
         require_once 'modules/DynamicFields/FieldCases.php';
         $tf = get_widget(empty($vardef['type']) ? "" : $vardef['type']);
         $tf->module = $module;
         $tf->populateFromRow($vardef);
         $vardef = array_merge($vardef, $tf->get_field_def());
         $fv->ss->assign('module', $module);
         $fv->ss->assign('package', $package);
         $fv->ss->assign('MB', '1');
         if (isset($vardef['vname'])) {
             $fv->ss->assign('lbl_value', htmlentities($module->getLabel('en_us', $vardef['vname']), ENT_QUOTES, 'UTF-8'));
         }
         if (empty($module->mbvardefs->vardefs['fields']['parent_name']) || isset($vardef['type']) && $vardef['type'] == 'parent') {
             $field_types['parent'] = $GLOBALS['mod_strings']['parent'];
         }
         $enumFields = array();
         if (!empty($module->mbvardefs->vardefs['fields'])) {
             foreach ($module->mbvardefs->vardefs['fields'] as $field => $def) {
                 if (!empty($def['type']) && $def['type'] == "enum" && $field != $vardef['name']) {
                     $enumFields[$field] = isset($module->mblanguage->strings[$current_language][$def['vname']]) ? $this->mbModule->mblanguage->strings[$current_language][$def['vname']] : translate($field);
                     if (substr($enumFields[$field], -1) == ":") {
                         $enumFields[$field] = substr($enumFields[$field], 0, strlen($enumFields[$field]) - 1);
                     }
                 }
             }
         }
         $edit_or_add = 'mbeditField';
     }
     if ($_REQUEST['action'] == 'RefreshField') {
         require_once 'modules/DynamicFields/FieldCases.php';
         $field = get_widget($_POST['type']);
         $field->populateFromPost();
         $vardef = $field->get_field_def();
         $vardef['options'] = $_REQUEST['new_dropdown'];
         $fv->ss->assign('lbl_value', htmlentities($_REQUEST['labelValue'], ENT_QUOTES, 'UTF-8'));
     }
     foreach (array("formula", "default", "comments", "help", "visiblityGrid") as $toEscape) {
         if (!empty($vardef[$toEscape]) && is_string($vardef[$toEscape])) {
             $vardef[$toEscape] = htmlentities($vardef[$toEscape], ENT_QUOTES, 'UTF-8');
         }
     }
     if (!empty($vardef['studio']) && is_array($vardef['studio']) && !empty($vardef['studio']['no_duplicate']) && $vardef['studio']['no_duplicate'] == true || strcmp($field_name, "name") == 0 || isset($vardef['type']) && $vardef['type'] == 'name') {
         $fv->ss->assign('no_duplicate', true);
     }
     $fv->ss->assign('action', $action);
     $fv->ss->assign('isClone', $isClone ? 1 : 0);
     $fv->ss->assign("module_dd_fields", $enumFields);
     $json = getJSONobj();
     $fv->ss->assign('field_name_exceptions', $json->encode($field_name_exceptions));
     ksort($field_types);
     $fv->ss->assign('field_types', $field_types);
     $fv->ss->assign('importable_options', $GLOBALS['app_list_strings']['custom_fields_importable_dom']);
     $fv->ss->assign('duplicate_merge_options', $GLOBALS['app_list_strings']['custom_fields_merge_dup_dom']);
     $triggers = array();
     $existing_field_names = array();
     foreach ($module->mbvardefs->vardefs['fields'] as $field) {
         if ($field['type'] == 'enum' || $field['type'] == 'multienum') {
             $triggers[] = $field['name'];
         }
         if (!isset($field['source']) || $field['source'] != 'non-db') {
             if (preg_match('/^(.*?)(_c)?$/', $field['name'], $matches)) {
                 $existing_field_names[] = strtoupper($matches[1]);
             }
         }
     }
     $fv->ss->assign('triggers', $triggers);
     $fv->ss->assign('existing_field_names', $json->encode($existing_field_names));
     $fv->ss->assign('mod_strings', $GLOBALS['mod_strings']);
     // jchi #24880
     // end
     $layout = $fv->getLayout($vardef);
     $fv->ss->assign('fieldLayout', $layout);
     if (empty($vardef['type'])) {
         $vardef['type'] = 'varchar';
     }
     $fv->ss->assign('vardef', $vardef);
     if (empty($_REQUEST['field'])) {
         $edit_or_add = 'addField';
     }
     $fv->ss->assign('help_group', $edit_or_add);
     $body = $this->fetchTemplate($fv, 'modules/ModuleBuilder/tpls/MBModule/field.tpl');
     $ac->addSection('east', translate('LBL_SECTION_FIELDEDITOR', 'ModuleBuilder'), $body);
     return $ac;
 }
コード例 #11
0
 function fetch($ac = false)
 {
     $fv = new FieldViewer();
     if (empty($_REQUEST['field']) && !empty($_REQUEST['name'])) {
         $_REQUEST['field'] = $_REQUEST['name'];
     }
     $field_name = '';
     if (!empty($this->view_object_map['field_name'])) {
         $field_name = $this->view_object_map['field_name'];
     } elseif (!empty($_REQUEST['field'])) {
         $field_name = $_REQUEST['field'];
     }
     // If this is a new field mark it as such
     $isNew = empty($field_name) || !empty($_REQUEST['is_new']);
     $action = 'saveField';
     // tyoung bug 17606: default action is to save as a dynamic field; but for standard OOB
     // fields we override this so don't create a new dynamic field instead of updating the existing field
     $isClone = false;
     if (!empty($this->view_object_map['is_clone']) && $this->view_object_map['is_clone'] && strcmp($field_name, "name") != 0) {
         $isClone = true;
     }
     /*
     $field_types =  array('varchar'=>'YourField', 'int'=>'Integer', 'float'=>'Decimal','bool'=>'Checkbox','enum'=>'DropDown',
     		'date'=>'Date', 'phone' => 'Phone', 'currency' => 'Currency', 'html' => 'HTML', 'radioenum' => 'Radio',
     		'relate' => 'Relate', 'address' => 'Address', 'text' => 'TextArea', 'url' => 'Link');
     */
     $field_types = $GLOBALS['mod_strings']['fieldTypes'];
     //bug 22264: Field name must not be an SQL keyword.
     $field_name_exceptions = array_merge(array_keys($GLOBALS['db']->getReservedWords()), array('ID', 'ID_C', 'PARENT_NAME', 'PARENT_ID'));
     //C.L. - Add support to mark related module id columns as reserved keywords
     require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php';
     $relatedModules = array_keys(DeployedRelationships::findRelatableModules());
     global $beanList, $current_language;
     foreach ($relatedModules as $relModule) {
         if (isset($beanList[$relModule])) {
             $field_name_exceptions[] = strtoupper($beanList[$relModule]) . '_ID';
         }
     }
     if (empty($_REQUEST['view_package']) || $_REQUEST['view_package'] == 'studio') {
         $moduleName = $_REQUEST['view_module'];
         $objectName = BeanFactory::getObjectName($moduleName);
         $module = BeanFactory::getBean($moduleName);
         VardefManager::loadVardef($moduleName, $objectName, true);
         global $dictionary;
         if (empty($module->mbvardefs)) {
             $module->mbvardefs = new stdClass();
         }
         $module->mbvardefs->vardefs = $dictionary[$objectName];
         $module->name = $moduleName;
         if (!$ac) {
             $ac = new AjaxCompose();
         }
         $vardef = !empty($module->mbvardefs->vardefs['fields'][$field_name]) ? $module->mbvardefs->vardefs['fields'][$field_name] : array();
         if ($isClone) {
             unset($vardef['name']);
         }
         // If this is a new field but we are loading this form a second time,
         // like from coming back from a dropdown create on a new field, then
         // keep the 'name' field open to allow the create field process to
         // continue like normal
         if (empty($vardef['name']) || $isNew) {
             if (!empty($_REQUEST['type'])) {
                 $vardef['type'] = $_REQUEST['type'];
             }
             $fv->ss->assign('hideLevel', 0);
         } elseif (isset($vardef['custom_module'])) {
             $fv->ss->assign('hideLevel', 2);
         } else {
             $action = 'saveSugarField';
             // tyoung - for OOB fields we currently only support modifying the label
             $fv->ss->assign('hideLevel', 3);
         }
         if ($isClone && isset($vardef['type']) && $vardef['type'] == 'datetime') {
             $vardef['type'] = 'datetimecombo';
         }
         require_once 'modules/DynamicFields/FieldCases.php';
         $tf = get_widget(empty($vardef['type']) ? "" : $vardef['type']);
         $tf->module = $module;
         $tf->populateFromRow($vardef);
         $vardef = array_merge($vardef, $tf->get_field_def());
         //          $GLOBALS['log']->debug('vardefs after loading = '.print_r($vardef,true));
         //Check if autoincrement fields are allowed
         $allowAutoInc = true;
         $enumFields = array();
         foreach ($module->field_defs as $field => $def) {
             if (!empty($def['type']) && $def['type'] == "int" && !empty($def['auto_increment'])) {
                 $allowAutoInc = false;
                 continue;
             }
             if (!empty($def['type']) && $def['type'] == "enum" && $field != $vardef['name']) {
                 if (!empty($def['studio']) && $def['studio'] == "false") {
                     continue;
                 }
                 //bug51866
                 $enumFields[$field] = translate($def['vname'], $moduleName);
                 if (substr($enumFields[$field], -1) == ":") {
                     $enumFields[$field] = substr($enumFields[$field], 0, strlen($enumFields[$field]) - 1);
                 }
             }
         }
         $fv->ss->assign('allowAutoInc', $allowAutoInc);
         $GLOBALS['log']->warn('view.modulefield: hidelevel ' . $fv->ss->get_template_vars('hideLevel') . " " . print_r($vardef, true));
         if (!empty($vardef['vname'])) {
             $fv->ss->assign('lbl_value', htmlentities(translate($vardef['vname'], $moduleName), ENT_QUOTES, 'UTF-8'));
         }
         $fv->ss->assign('module', $module);
         if (empty($module->mbvardefs->vardefs['fields']['parent_name']) || isset($vardef['type']) && $vardef['type'] == 'parent') {
             $field_types['parent'] = $GLOBALS['mod_strings']['parent'];
         }
         $edit_or_add = 'editField';
     } else {
         require_once 'modules/ModuleBuilder/MB/ModuleBuilder.php';
         $mb = new ModuleBuilder();
         $moduleName = $_REQUEST['view_module'];
         $module =& $mb->getPackageModule($_REQUEST['view_package'], $moduleName);
         $package =& $mb->packages[$_REQUEST['view_package']];
         $module->getVardefs();
         if (!$ac) {
             $ac = new AjaxCompose();
         }
         $vardef = !empty($module->mbvardefs->vardefs['fields'][$field_name]) ? $module->mbvardefs->vardefs['fields'][$field_name] : array();
         if ($isClone) {
             unset($vardef['name']);
         }
         if (empty($vardef['name'])) {
             if (!empty($_REQUEST['type'])) {
                 $vardef['type'] = $_REQUEST['type'];
             }
             $fv->ss->assign('hideLevel', 0);
         } else {
             if (!empty($module->mbvardefs->vardef['fields'][$vardef['name']])) {
                 $fv->ss->assign('hideLevel', 1);
             } elseif (isset($vardef['custom_module'])) {
                 $fv->ss->assign('hideLevel', 2);
             } else {
                 $fv->ss->assign('hideLevel', 3);
                 // tyoung bug 17350 - effectively mark template derived fields as readonly
             }
         }
         require_once 'modules/DynamicFields/FieldCases.php';
         $tf = get_widget(empty($vardef['type']) ? "" : $vardef['type']);
         $tf->module = $module;
         $tf->populateFromRow($vardef);
         $vardef = array_merge($vardef, $tf->get_field_def());
         $fv->ss->assign('module', $module);
         $fv->ss->assign('package', $package);
         $fv->ss->assign('MB', '1');
         if (isset($vardef['vname'])) {
             $fv->ss->assign('lbl_value', htmlentities($module->getLabel('en_us', $vardef['vname']), ENT_QUOTES, 'UTF-8'));
         }
         if (empty($module->mbvardefs->vardefs['fields']['parent_name']) || isset($vardef['type']) && $vardef['type'] == 'parent') {
             $field_types['parent'] = $GLOBALS['mod_strings']['parent'];
         }
         $enumFields = array();
         if (!empty($module->mbvardefs->vardefs['fields'])) {
             foreach ($module->mbvardefs->vardefs['fields'] as $field => $def) {
                 if (!empty($def['type']) && $def['type'] == "enum" && $field != $vardef['name']) {
                     $enumFields[$field] = isset($module->mblanguage->strings[$current_language][$def['vname']]) ? $this->mbModule->mblanguage->strings[$current_language][$def['vname']] : translate($field);
                     if (substr($enumFields[$field], -1) == ":") {
                         $enumFields[$field] = substr($enumFields[$field], 0, strlen($enumFields[$field]) - 1);
                     }
                 }
             }
         }
         $edit_or_add = 'mbeditField';
     }
     if ($_REQUEST['action'] == 'RefreshField') {
         require_once 'modules/DynamicFields/FieldCases.php';
         $field = get_widget($_POST['type']);
         $field->populateFromPost();
         $vardef = $field->get_field_def();
         $vardef['options'] = $_REQUEST['new_dropdown'];
         $fv->ss->assign('lbl_value', htmlentities($_REQUEST['labelValue'], ENT_QUOTES, 'UTF-8'));
     }
     foreach (array("formula", "default", "comments", "help", "visiblityGrid") as $toEscape) {
         if (!empty($vardef[$toEscape]) && is_string($vardef[$toEscape])) {
             $vardef[$toEscape] = htmlentities($vardef[$toEscape], ENT_QUOTES, 'UTF-8');
         }
     }
     if (!empty($vardef['studio']['no_duplicate']) || $field_name === 'name' || $field_name === 'parent_type' || $field_name === 'parent_id' || $field_name === 'parent_name' || isset($vardef['type']) && $vardef['type'] === 'name') {
         $fv->ss->assign('no_duplicate', true);
     }
     $fv->ss->assign('action', $action);
     $fv->ss->assign('isClone', $isClone ? 1 : 0);
     $fv->ss->assign('isNew', $isNew);
     $fv->ss->assign("module_dd_fields", $enumFields);
     $json = getJSONobj();
     $fv->ss->assign('field_name_exceptions', $json->encode($field_name_exceptions));
     ksort($field_types);
     $fv->ss->assign('field_types', $field_types);
     $ftsEngineType = getFTSEngineType();
     $usa = new UnifiedSearchAdvanced();
     if (SugarSearchEngineFactory::getInstance()->isTypeFtsEnabled($vardef['type']) && (!empty($_REQUEST['view_package']) && $_REQUEST['view_package'] != 'studio' || $usa->shouldShowModule($moduleName))) {
         $ftsBoostOptions = getFTSBoostOptions($ftsEngineType . '_boost_options');
         $fv->ss->assign('fts_options', $ftsBoostOptions);
         $fv->ss->assign('show_fts', true);
     } else {
         $fv->ss->assign('show_fts', false);
     }
     //Ensure certain field types always have correct formula return types for validation.
     if (!empty($vardef['type'])) {
         switch ($vardef['type']) {
             case 'date':
             case 'datetime':
                 $fv->ss->assign('calcFieldType', 'date');
                 break;
             case 'bool':
                 $fv->ss->assign('calcFieldType', 'boolean');
                 break;
             default:
                 $fv->ss->assign('calcFieldType', '');
                 break;
         }
     }
     $fv->ss->assign('importable_options', $GLOBALS['app_list_strings']['custom_fields_importable_dom']);
     $fv->ss->assign('duplicate_merge_options', $GLOBALS['app_list_strings']['custom_fields_merge_dup_dom']);
     $triggers = array();
     $existing_field_names = array();
     foreach ($module->mbvardefs->vardefs['fields'] as $field) {
         if ($field['type'] == 'enum' || $field['type'] == 'multienum') {
             $triggers[] = $field['name'];
         }
         if (!isset($field['source']) || $field['source'] != 'non-db') {
             if (preg_match('/^(.*?)(_c)?$/', $field['name'], $matches)) {
                 $existing_field_names[] = strtoupper($matches[1]);
             }
         }
     }
     $fv->ss->assign('triggers', $triggers);
     $fv->ss->assign('existing_field_names', $json->encode($existing_field_names));
     $fv->ss->assign('mod_strings', $GLOBALS['mod_strings']);
     // jchi #24880
     if (!isset($vardef['reportable'])) {
         $vardef['reportable'] = 1;
     }
     // end
     $layout = $fv->getLayout($vardef);
     $fv->ss->assign('fieldLayout', $layout);
     if (empty($vardef['type'])) {
         $vardef['type'] = 'varchar';
     }
     $fv->ss->assign('vardef', $vardef);
     if (empty($_REQUEST['field'])) {
         $edit_or_add = 'addField';
     }
     $fv->ss->assign('help_group', $edit_or_add);
     $body = $this->fetchTemplate($fv, 'modules/ModuleBuilder/tpls/MBModule/field.tpl');
     $ac->addSection('east', translate('LBL_SECTION_FIELDEDITOR', 'ModuleBuilder'), $body);
     return $ac;
 }
コード例 #12
0
ファイル: controller.php プロジェクト: jglaine/sugar761-ent
 public function action_SaveRelationshipLabel()
 {
     global $locale;
     if (!empty($_REQUEST['relationship_lang'])) {
         $selected_lang = $_REQUEST['relationship_lang'];
     } else {
         $selected_lang = $locale->getAuthenticatedUserLanguage();
     }
     if (empty($_REQUEST['view_package'])) {
         $relationships = new DeployedRelationships($_REQUEST['view_module']);
         if (!empty($_REQUEST['relationship_name'])) {
             if ($relationship = $relationships->get($_REQUEST['relationship_name'])) {
                 $metadata = $relationship->buildLabels(true);
                 $parser = new ParserLabel($_REQUEST['view_module']);
                 $parser->handleSaveRelationshipLabels($metadata, $selected_lang);
             }
         }
     } else {
         //TODO FOR MB
     }
     $this->view = 'relationships';
 }
コード例 #13
0
ファイル: MBPackage.php プロジェクト: vsanth/dynamic-crm
 private function getExtensionsList($module, $excludeRelationships = true)
 {
     require_once 'modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php';
     $extPath = 'custom/Extension/modules/';
     $modExtPath = $extPath . $module . '/Ext';
     $rels = new DeployedRelationships($module);
     $relList = $rels->getRelationshipList();
     $ret = array();
     if (is_dir($modExtPath)) {
         $extFolders = scandir($modExtPath);
         foreach ($extFolders as $extFolder) {
             if (!is_dir("{$modExtPath}/{$extFolder}") || substr($extFolder, 0, 1) == ".") {
                 continue;
             }
             foreach (scandir("{$modExtPath}/{$extFolder}") as $extFile) {
                 if (substr($extFile, 0, 1) == "." || strtolower(substr($extFile, -4)) != ".php") {
                     continue;
                 }
                 //Exclude relattionship extension files
                 if ($excludeRelationships && (substr($extFile, 0, 6) == "custom" && isset($relList[substr($extFile, 6, strlen($extFile) - 10)]) || substr($extFile, 6, 6) == "custom" && isset($relList[substr($extFile, 12, strlen($extFile) - 16)]))) {
                     continue;
                 }
                 if (!isset($ret[$extFolder])) {
                     $ret[$extFolder] = array();
                 }
                 $ret[$extFolder][$extFile] = "{$modExtPath}/{$extFolder}/{$extFile}";
             }
         }
     }
     return $ret;
 }
コード例 #14
0
/**
 * Searches through the installed relationships to find broken self referencing one-to-many relationships 
 * (wrong field used in the subpanel, and the left link not marked as left)
 */
function upgrade_custom_relationships($modules = array())
{
    global $current_user, $moduleList;
    if (!is_admin($current_user)) {
        sugar_die($GLOBALS['app_strings']['ERR_NOT_ADMIN']);
    }
    require_once "modules/ModuleBuilder/parsers/relationships/DeployedRelationships.php";
    require_once "modules/ModuleBuilder/parsers/relationships/OneToManyRelationship.php";
    if (empty($modules)) {
        $modules = $moduleList;
    }
    foreach ($modules as $module) {
        $depRels = new DeployedRelationships($module);
        $relList = $depRels->getRelationshipList();
        foreach ($relList as $relName) {
            $relObject = $depRels->get($relName);
            $def = $relObject->getDefinition();
            //We only need to fix self referencing one to many relationships
            if ($def['lhs_module'] == $def['rhs_module'] && $def['is_custom'] && $def['relationship_type'] == "one-to-many") {
                $layout_defs = array();
                if (!is_dir("custom/Extension/modules/{$module}/Ext/Layoutdefs") || !is_dir("custom/Extension/modules/{$module}/Ext/Vardefs")) {
                    continue;
                }
                //Find the extension file containing the vardefs for this relationship
                foreach (scandir("custom/Extension/modules/{$module}/Ext/Vardefs") as $file) {
                    if (substr($file, 0, 1) != "." && strtolower(substr($file, -4)) == ".php") {
                        $dictionary = array($module => array("fields" => array()));
                        $filePath = "custom/Extension/modules/{$module}/Ext/Vardefs/{$file}";
                        include $filePath;
                        if (isset($dictionary[$module]["fields"][$relName])) {
                            $rhsDef = $dictionary[$module]["fields"][$relName];
                            //Update the vardef for the left side link field
                            if (!isset($rhsDef['side']) || $rhsDef['side'] != 'left') {
                                $rhsDef['side'] = 'left';
                                $rhsDef['link-type'] = 'one';
                                $fileContents = file_get_contents($filePath);
                                $out = preg_replace('/\\$dictionary[\\w"\'\\[\\]]*?' . $relName . '["\'\\[\\]]*?\\s*?=\\s*?array\\s*?\\(.*?\\);/s', '$dictionary["' . $module . '"]["fields"]["' . $relName . '"]=' . var_export_helper($rhsDef) . ";", $fileContents);
                                file_put_contents($filePath, $out);
                            }
                        }
                    }
                }
                //Find the extension file containing the subpanel definition for this relationship
                foreach (scandir("custom/Extension/modules/{$module}/Ext/Layoutdefs") as $file) {
                    if (substr($file, 0, 1) != "." && strtolower(substr($file, -4)) == ".php") {
                        $layout_defs = array($module => array("subpanel_setup" => array()));
                        $filePath = "custom/Extension/modules/{$module}/Ext/Layoutdefs/{$file}";
                        include $filePath;
                        $bean = BeanFactory::getBean($module);
                        $fields = $bean->getFieldDefinitions();
                        foreach ($layout_defs[$module]["subpanel_setup"] as $key => $subDef) {
                            if (isset($layout_defs[$module]["subpanel_setup"][$key]['get_subpanel_data']) && $layout_defs[$module]["subpanel_setup"][$key]['get_subpanel_data'] == $relName && isset($fields[$relName]) && $fields[$relName]['type'] != 'link') {
                                $fileContents = file_get_contents($filePath);
                                $out = preg_replace('/[\'"]get_subpanel_data[\'"]\\s*=>\\s*[\'"]' . $relName . '[\'"],/s', "'get_subpanel_data' => '{$def["join_key_lhs"]}',", $fileContents);
                                file_put_contents($filePath, $out);
                            }
                        }
                    }
                }
            }
        }
    }
    // Phase 2: Module builder has been incorrectly adding the id
    // field attributes to created relationships
    foreach (glob('custom/Extension/modules/*/Ext/Vardefs/*.php') as $fileToFix) {
        // continue to the next if it's not an existing file or it's a directory
        if (!file_exists($fileToFix) || is_dir($fileToFix)) {
            continue;
        }
        $filename = basename($fileToFix);
        $dictionary = array();
        require $fileToFix;
        $tmp = array_keys($dictionary);
        if (count($tmp) < 1) {
            // Empty dictionary
            continue;
        }
        $dictKey = $tmp[0];
        if (!isset($dictionary[$dictKey]['fields'])) {
            // Not modifying any fields, this isn't a relationship
            continue;
        }
        $isBadRelate = false;
        $idName = '';
        $linkField = null;
        $relateField = null;
        foreach ($dictionary[$dictKey]['fields'] as $fieldName => $field) {
            if (isset($field['id_name']) && $fieldName != $field['id_name']) {
                if (isset($field['type']) && $field['type'] == 'link') {
                    // This looks promising
                    if (isset($dictionary[$dictKey]['fields'][$field['id_name']])) {
                        $idField = $dictionary[$dictKey]['fields'][$field['id_name']];
                        if (isset($idField['type']) && $idField['type'] == 'link') {
                            // This looks like a winner
                            $idName = $field['id_name'];
                            $isBadRelate = true;
                            $linkField = $field;
                        }
                    }
                }
                if (isset($field['type']) && $field['type'] == 'relate') {
                    $relateField = $field;
                }
            }
        }
        if (!$isBadRelate) {
            continue;
        }
        $depRels = new DeployedRelationships($dictKey);
        $relObj = $depRels->get($linkField['relationship']);
        if (!$relObj) {
            // The system doesn't know about the relationship object.
            $linkMetadataLocation = 'custom/metadata/' . $linkField['relationship'] . 'MetaData.php';
            if (file_exists($linkMetadataLocation)) {
                require $linkMetadataLocation;
                $linkDef = $dictionary[$linkField['relationship']];
                $relObj = RelationshipFactory::newRelationship($linkDef);
            }
        }
        $newIdField = array('name' => $idName, 'type' => 'id', 'source' => 'non-db', 'vname' => $idField['vname'], 'id_name' => $idName, 'link' => $relateField['link'], 'table' => $relateField['table'], 'module' => $relateField['module'], 'rname' => 'id', 'reportable' => false, 'massupdate' => false, 'duplicate_merge' => 'disabled', 'hideacl' => true);
        if ($relObj && $relObj->getLhsModule() == $relObj->getRhsModule()) {
            $selfReferencing = true;
        } else {
            $selfReferencing = false;
        }
        if ($selfReferencing) {
            $newLinkField = array('name' => $relateField['link'] . '_right', 'type' => 'link', 'relationship' => $linkField['relationship'], 'source' => 'non-db', 'vname' => $idField['vname'], 'id_name' => $relObj->getJoinKeyRHS(), 'side' => 'right', 'link-type' => 'many');
        }
        $replaceString = '$dictionary["' . $dictKey . '"]["fields"]["' . $idName . '"]=' . var_export_helper($newIdField) . ";\n";
        if ($selfReferencing) {
            $replaceString .= '$dictionary["' . $dictKey . '"]["fields"]["' . $newLinkField['name'] . '"]=' . var_export_helper($newLinkField) . ";\n";
        }
        $fileContents = file_get_contents($fileToFix);
        $out = preg_replace('/\\$dictionary[\\w"\'\\[\\]]*?' . $idName . '["\'\\[\\]]*?\\s*?=\\s*?array\\s*?\\(.*?\\);/s', $replaceString, $fileContents);
        if ($selfReferencing) {
            $out = preg_replace('/\\$dictionary[\\w"\'\\[\\]]*?' . $relateField['name'] . '["\'\\[\\]]*?\\s*?=\\s*?array\\s*?\\(.*?\\);/s', '$dictionary["' . $dictKey . '"]["fields"]["' . $relateField['name'] . '"]=' . var_export_helper($relateField) . ";\n", $out);
        }
        file_put_contents($fileToFix, $out);
        if ($selfReferencing) {
            // Now to fix bad layouts in self-linking relationships
            // Go to the Layoutdefs path
            $layoutPath = dirname(dirname($fileToFix)) . '/Layoutdefs';
            foreach (glob($layoutPath . '/*.php') as $layoutToCheck) {
                // See if they match the id I just changed.
                $layout_defs = array();
                include $layoutToCheck;
                if (isset($layout_defs[$dictKey]['subpanel_setup'][$newIdField['name']])) {
                    $newLayout[$dictKey]['subpanel_setup'][$relateField['link']] = $layout_defs[$dictKey]['subpanel_setup'][$newIdField['name']];
                    $newLayout[$dictKey]['subpanel_setup'][$relateField['link']]['get_subpanel_data'] = $newLinkField['relationship'] . '_right';
                    write_array_to_file('layout_defs', $newLayout, $layoutToCheck);
                }
            }
        }
    }
}
コード例 #15
0
 /**
  * Convert a piece of a subpanel layoutdef to the new style
  * @param array $layoutdef old style layout
  * @return array new style layout for this piece
  */
 public function fromLegacySubpanelLayout(array $layoutdef)
 {
     $viewdefs = array('layout' => 'subpanel');
     // we aren't upgrading collections
     if (!empty($layoutdef['collection_list'])) {
         return $viewdefs;
     }
     foreach ($layoutdef as $key => $value) {
         if ($key == 'override_subpanel_name') {
             $subpanelFileName = $value;
             if (substr_count($value, '_') > 1 && stristr($value, 'subpanel')) {
                 $parts = explode('_subpanel_', $value);
                 $beanNameParts = explode('_', $parts[0]);
                 $subPanelBeanName = '';
                 foreach ($beanNameParts as $part) {
                     $subPanelBeanName .= ucwords($part);
                 }
                 // case is not the actually object name, it's aCase
                 if ($subPanelBeanName == 'Case') {
                     $subPanelBeanName = 'aCase';
                 }
                 $focus = BeanFactory::newBeanByName($subPanelBeanName);
                 if ($focus) {
                     $field = $focus->getFieldDefinition($parts[1]);
                     if ($field && $field['type'] == 'link') {
                         // since we have a valid link, we need to test the relationship to see if it's custom relationship
                         $relationships = new DeployedRelationships($focus->module_name);
                         $relationship = $relationships->get($parts[1]);
                         $relDef = array();
                         if ($relationship) {
                             $relDef = $relationship->getDefinition();
                         }
                         if (!empty($relDef['is_custom']) && !empty($relDef['from_studio']) && (!empty($relDef['name']) || !empty($relDef['relationship_name']))) {
                             $name = !empty($relDef['name']) ? $relDef['name'] : $relDef['relationship_name'];
                             $subpanelFileName = "For{$name}";
                         } else {
                             $subpanelFileName = "For{$focus->module_name}";
                         }
                     } else {
                         $subpanelFileName = "For{$focus->module_name}";
                     }
                 }
             }
             $viewdefs['override_subpanel_list_view'] = array('view' => $this->fromLegacySubpanelName($subpanelFileName), 'link' => isset($layoutdef['get_subpanel_data']) ? $layoutdef['get_subpanel_data'] : '');
         } elseif ($key == 'title_key') {
             $viewdefs['label'] = $value;
         } elseif ($key == 'get_subpanel_data') {
             $viewdefs['context']['link'] = $value;
         }
     }
     return $viewdefs;
 }
コード例 #16
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();
     }
 }
コード例 #17
0
ファイル: Bug45339Test.php プロジェクト: delkyd/sugarcrm_dev
 /**
  * @group 45339
  */
 public function testGetExtensionsList()
 {
     // Create new relationship between Leads and Accounts
     $_REQUEST['view_module'] = "Leads";
     $_REQUEST['lhs_module'] = "Leads";
     $_REQUEST['rhs_module'] = "Accounts";
     $_REQUEST['lhs_label'] = "Leads";
     $_REQUEST['rhs_label'] = "Accounts";
     $deployedRelation = new DeployedRelationships($_REQUEST['view_module']);
     $relationLeadAccount = $deployedRelation->addFromPost();
     $deployedRelation->save();
     $deployedRelation->build();
     //create expected file paths from custom extensions
     $accountContactRelInAccountVardefExtensions = sprintf('custom%1$sExtension%1$smodules%1$sAccounts%1$sExt%1$sVardefs%1$s' . $this->relationAccountContact->getName() . '_Accounts.php', DIRECTORY_SEPARATOR);
     $contactAccountRelInAccountVardefExtensions = sprintf('custom%1$sExtension%1$smodules%1$sAccounts%1$sExt%1$sVardefs%1$s' . $this->relationContactAccount->getName() . '_Accounts.php', DIRECTORY_SEPARATOR);
     $leadAccountRelInAccountVardefExtensions = sprintf('custom%1$sExtension%1$smodules%1$sAccounts%1$sExt%1$sVardefs%1$s' . $relationLeadAccount->getName() . '_Accounts.php', DIRECTORY_SEPARATOR);
     $sugarfieldAccountVardefExtensions = sprintf('custom%1$sExtension%1$smodules%1$sAccounts%1$sExt%1$sVardefs%1$s' . 'sugarfield_' . $this->field->name . '.php', DIRECTORY_SEPARATOR);
     //call mbPackage to retrieve arrays of Files to be exported using different test parameters
     $accountAllExtensions = $this->mbPackage->getExtensionsListTest('Accounts', array('Accounts', 'Contacts', 'Leads'));
     $accountExtContacts = $this->mbPackage->getExtensionsListTest('Accounts', array('Accounts', 'Contacts'));
     $accountExtOnly = $this->mbPackage->getExtensionsListTest('Accounts', array('Accounts'));
     $contactExtWithWrongRelationship = $this->mbPackage->getExtensionsListTest('Contacts', array(''));
     $wrongModuleName = $this->mbPackage->getExtensionsListTest('Wrong_module_name');
     // Remove relationship
     $deployedRelation->delete($relationLeadAccount->getName());
     $deployedRelation->save();
     SugarRelationshipFactory::deleteCache();
     //assert that contact rels are exported when all rels were defined
     $this->assertContains($accountContactRelInAccountVardefExtensions, $accountAllExtensions, 'Contact Relationship should have been exported when accounts and contacts modules are exported');
     //assert that contact rels are not exported when contact is not defined
     $this->assertNotContains($accountContactRelInAccountVardefExtensions, $accountExtOnly, 'Contact Relationship should NOT have been exported when exporting accounts only');
     //assert that non relationship change is exported when no related module is defined
     $this->assertContains($sugarfieldAccountVardefExtensions, $accountExtOnly, 'Sugarfield change should have been exported when exporting Accounts only');
     //assert only contact and Account modules are present when both contact and Accounts are defined
     $this->assertContains($accountContactRelInAccountVardefExtensions, $accountExtContacts, 'Accounts rels should be present when exporting Contacts and Accounts');
     $this->assertContains($contactAccountRelInAccountVardefExtensions, $accountExtContacts, 'Contacts rels should be present when exporting Contacts and Accounts');
     $this->assertNotContains($leadAccountRelInAccountVardefExtensions, $accountExtContacts, 'Leads rels should NOT be present when exporting Contacts and Accounts');
     //assert that requesting a wrong relationship returns an empty array
     $this->assertInternalType('array', $contactExtWithWrongRelationship, 'array type should be returned when no relationships are exported, and no other changes exist');
     $this->assertEmpty($contactExtWithWrongRelationship, 'An empty array should be returned when no relationships are exported, and no other changes exist');
     //assert that requesting a wrong module name returns an empty array
     $this->assertInternalType('array', $wrongModuleName, 'An array type should be returned when a bad module is requested for export');
     $this->assertEmpty($wrongModuleName, 'An empty array should be returned when a bad module is requested for export');
 }
コード例 #18
0
 /**
  * Remove all created relationships
  *
  * @static
  */
 public static function removeAllCreatedRelationships()
 {
     foreach (self::$_relsAdded as $rel) {
         $relationships = new DeployedRelationships($rel['lhs_module']);
         $relationships->delete($rel['relationship_name']);
         $relationships->save();
         $relationships->build();
         LanguageManager::clearLanguageCache($rel['lhs_module']);
         require_once "data/Relationships/RelationshipFactory.php";
         SugarRelationshipFactory::deleteCache();
         SugarRelationshipFactory::rebuildCache();
     }
     // since we are creating a relationship we need to unset this global var
     if (isset($GLOBALS['reload_vardefs'])) {
         unset($GLOBALS['reload_vardefs']);
     }
 }