public function testgetValidDBName() { $expected = ''; $actual = getValidDBName(''); $this->assertSame($expected, $actual); $expected = 'col'; $actual = getValidDBName('Col'); $this->assertSame($expected, $actual); }
/** * upgradeTeamColumn * Helper function to create a team_set_id column and also set team_set_id column * to have the value of the $column_name parameter * * @param $bean SugarBean which we are adding team_set_id column to * @param $column_name The name of the column containing the default team_set_id value */ function upgradeTeamColumn($bean, $column_name) { //first let's check to ensure that the team_set_id field is defined, if not it could be the case that this is an older //module that does not use the SugarObjects if (empty($bean->field_defs['team_set_id']) && $bean->module_dir != 'Trackers') { //at this point we could assume that since we have a team_id defined and not a team_set_id that we need to //add that field and the corresponding relationships $object = $bean->object_name; $module = $bean->module_dir; $object_name = $object; $_object_name = strtolower($object_name); if (!empty($GLOBALS['dictionary'][$object]['table'])) { $table_name = $GLOBALS['dictionary'][$object]['table']; } else { $table_name = strtolower($module); } $path = 'include/SugarObjects/implements/team_security/vardefs.php'; require $path; //go through each entry in the vardefs from team_security and unset anything that is already set in the core module //this will ensure we have the proper ordering. $fieldDiff = array_diff_assoc($vardefs['fields'], $GLOBALS['dictionary'][$bean->object_name]['fields']); $file = 'custom/Extension/modules/' . $bean->module_dir . '/Ext/Vardefs/teams.php'; $contents = "<?php\n"; if (!empty($fieldDiff)) { foreach ($fieldDiff as $key => $val) { $contents .= "\n\$GLOBALS['dictionary']['" . $object . "']['fields']['" . $key . "']=" . var_export_helper($val) . ";"; } } $relationshipDiff = array_diff_assoc($vardefs['relationships'], $GLOBALS['dictionary'][$bean->object_name]['relationships']); if (!empty($relationshipDiff)) { foreach ($relationshipDiff as $key => $val) { $contents .= "\n\$GLOBALS['dictionary']['" . $object . "']['relationships']['" . $key . "']=" . var_export_helper($val) . ";"; } } $indexDiff = array_diff_assoc($vardefs['indices'], $GLOBALS['dictionary'][$bean->object_name]['indices']); if (!empty($indexDiff)) { foreach ($indexDiff as $key => $val) { $contents .= "\n\$GLOBALS['dictionary']['" . $object . "']['indices']['" . $key . "']=" . var_export_helper($val) . ";"; } } if ($fh = @sugar_fopen($file, 'wt')) { fputs($fh, $contents); fclose($fh); } //we have written out the teams.php into custom/Extension/modules/{$module_dir}/Ext/Vardefs/teams.php' //now let's merge back into vardefs.ext.php require_once 'ModuleInstall/ModuleInstaller.php'; $mi = new ModuleInstaller(); $mi->merge_files('Ext/Vardefs/', 'vardefs.ext.php'); VardefManager::loadVardef($bean->module_dir, $bean->object_name, true); $bean->field_defs = $GLOBALS['dictionary'][$bean->object_name]['fields']; } if (isset($bean->field_defs['team_set_id'])) { //Create the team_set_id column $FieldArray = $GLOBALS['db']->helper->get_columns($bean->table_name); if (!isset($FieldArray['team_set_id'])) { $GLOBALS['db']->addColumn($bean->table_name, $bean->field_defs['team_set_id']); } $indexArray = $GLOBALS['db']->helper->get_indices($bean->table_name); $indexName = getValidDBName('idx_' . strtolower($bean->table_name) . '_tmst_id', true, 34); $indexDef = array(array('name' => $indexName, 'type' => 'index', 'fields' => array('team_set_id'))); if (!isset($indexArray[$indexName])) { $GLOBALS['db']->addIndexes($bean->table_name, $indexDef); } //Update the table's team_set_id column to have the same values as team_id $GLOBALS['db']->query("UPDATE {$bean->table_name} SET team_set_id = {$column_name}"); } }
function filter_fields($value, $fields) { global $invalid_contact_fields; $filterFields = array(); foreach ($fields as $field) { if (is_array($invalid_contact_fields)) { if (in_array($field, $invalid_contact_fields)) { continue; } // if } // if if (isset($value->field_defs[$field])) { $var = $value->field_defs[$field]; if (isset($var['source']) && ($var['source'] != 'db' && $var['source'] != 'custom_fields') && $var['name'] != 'email1' && $var['name'] != 'email2' && (!isset($var['type']) || $var['type'] != 'relate')) { continue; } } // if // No valid field should be caught by this quoting. $filterFields[] = getValidDBName($field); } // foreach return $filterFields; }
public function testEnsureUnique() { $this->assertEquals(getValidDBName('idx_test_123_456_789_foo_bar_id', true), getValidDBName('idx_test_123_456_789_foo_bar_id', true)); $this->assertNotEquals(getValidDBName('idx_test_123_456_789_foo_bar_id', true), getValidDBName('idx_test_123_446_789_foo_bar_id', true)); }
/** * @dataProvider longNameProvider */ public function testLongNameAffected($name_1, $name_2) { $this->assertNotEquals(getValidDBName($name_1), getValidDBName($name_2)); }
static function getValidDBName($name, $ensureUnique = true) { require_once 'modules/ModuleBuilder/parsers/constants.php'; return getValidDBName($name, $ensureUnique, MB_MAXDBIDENTIFIERLENGTH); }
public function testLongNameAffected() { $this->assertNotEquals(getValidDBName('eeeee_eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee_opportunities', true), getValidDBName('eeeee_eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee1_opportunities', true)); }