/** * Test the getMime function for the use case where the mime type is already provided. * * @dataProvider _moduleNameProvider2 */ public function testGetModuleFromRenamed($renamed, $expectedName) { $GLOBALS['app_list_strings'] = return_app_list_strings_language($GLOBALS['current_language']); // manually rename the module name to 'Acct' $GLOBALS['app_list_strings']['moduleList']['Accounts'] = 'Acct'; $module = get_module_from_singular($renamed); $this->assertEquals($expectedName, $module); }
function action_SaveModifyDisplay() { if (empty($_REQUEST['display_sources'])) { return; } require_once 'include/connectors/utils/ConnectorUtils.php'; require_once 'include/connectors/sources/SourceFactory.php'; $connectors = ConnectorUtils::getConnectors(); $connector_keys = array_keys($connectors); $modules_sources = ConnectorUtils::getDisplayConfig(); if (!is_array($modules_sources)) { $modules_sources = (array) $modules_sources; } $sources = array(); $values = array(); $new_modules_sources = array(); if (!empty($_REQUEST['display_values'])) { $display_values = explode(',', $_REQUEST['display_values']); foreach ($display_values as $value) { $entry = explode(':', $value); $mod = get_module_from_singular($entry[1]); // get the internal module name $new_modules_sources[$mod][$entry[0]] = $entry[0]; } } //These are the sources that were modified. //We only update entries for these sources that have been changed $display_sources = explode(',', $_REQUEST['display_sources']); foreach ($display_sources as $source) { $sources[$source] = $source; } //foreach $removedModules = array(); //Unset entries that have all sources removed foreach ($modules_sources as $module => $source_entries) { foreach ($source_entries as $source_id) { if (!empty($sources[$source_id]) && empty($new_modules_sources[$module][$source_id])) { unset($modules_sources[$module][$source_id]); $removedModules[$module] = true; } } } $removedModules = array_keys($removedModules); foreach ($removedModules as $key) { if (empty($new_modules_sources[$key])) { ConnectorUtils::cleanMetaDataFile($key); } } //Update based on new_modules_sources foreach ($new_modules_sources as $module => $enabled_sources) { //If the module is not in $modules_sources add it there if (empty($modules_sources[$module])) { $modules_sources[$module] = $enabled_sources; } else { foreach ($enabled_sources as $source_id) { if (empty($modules_sources[$module][$source_id])) { $modules_sources[$module][$source_id] = $source_id; } } //foreach } } //foreach //Should we just remove entries where all sources are disabled? $unset_modules = array(); foreach ($modules_sources as $module => $mapping) { if (empty($mapping)) { $unset_modules[] = $module; } } foreach ($unset_modules as $mod) { unset($modules_sources[$mod]); } if (!write_array_to_file('modules_sources', $modules_sources, CONNECTOR_DISPLAY_CONFIG_FILE)) { //Log error and return empty array $GLOBALS['log']->fatal("Cannot write \$modules_sources to " . CONNECTOR_DISPLAY_CONFIG_FILE); } $sources_modules = array(); foreach ($modules_sources as $module => $source_entries) { foreach ($source_entries as $id) { $sources_modules[$id][$module] = $module; } } //Now update the searchdefs and field mapping entries accordingly require 'modules/Connectors/metadata/searchdefs.php'; $originalSearchDefs = $searchdefs; $connectorSearchDefs = ConnectorUtils::getSearchDefs(); $searchdefs = array(); foreach ($sources_modules as $source_id => $modules) { foreach ($modules as $module) { $searchdefs[$source_id][$module] = !empty($connectorSearchDefs[$source_id][$module]) ? $connectorSearchDefs[$source_id][$module] : (!empty($originalSearchDefs[$source_id][$module]) ? $originalSearchDefs[$source_id][$module] : array()); } } //Write the new searchdefs out if (!write_array_to_file('searchdefs', $searchdefs, 'custom/modules/Connectors/metadata/searchdefs.php')) { $GLOBALS['log']->fatal("Cannot write file custom/modules/Connectors/metadata/searchdefs.php"); } //Unset the $_SESSION['searchDefs'] variable if (isset($_SESSION['searchDefs'])) { unset($_SESSION['searchDefs']); } //Clear mapping file if needed (this happens when all modules are removed from a source foreach ($sources as $id) { if (empty($sources_modules[$source])) { //Now write the new mapping entry to the custom folder $dir = $connectors[$id]['directory']; if (!preg_match('/^custom\\//', $dir)) { $dir = 'custom/' . $dir; } if (!file_exists("{$dir}")) { mkdir_recursive("{$dir}"); } $fakeMapping = array('beans' => array()); if (!write_array_to_file('mapping', $fakeMapping, "{$dir}/mapping.php")) { $GLOBALS['log']->fatal("Cannot write file {$dir}/mapping.php"); } $s = SourceFactory::getSource($id); $s->saveMappingHook($fakeMapping); } //if } //foreach //Now update the field mapping entries foreach ($sources_modules as $id => $modules) { $source = SourceFactory::getSource($id); $mapping = $source->getMapping(); $mapped_modules = array_keys($mapping['beans']); foreach ($mapped_modules as $module) { if (empty($sources_modules[$id][$module])) { unset($mapping['beans'][$module]); } } //Remove modules from the mapping entries foreach ($modules as $module) { if (empty($mapping['beans'][$module])) { $originalMapping = $source->getOriginalMapping(); if (empty($originalMapping['beans'][$module])) { $defs = $source->getFieldDefs(); $keys = array_keys($defs); $new_mapping_entry = array(); foreach ($keys as $key) { $new_mapping_entry[$key] = ''; } $mapping['beans'][$module] = $new_mapping_entry; } else { $mapping['beans'][$module] = $originalMapping['beans'][$module]; } } //if } //foreach //Now write the new mapping entry to the custom folder $dir = $connectors[$id]['directory']; if (!preg_match('/^custom\\//', $dir)) { $dir = 'custom/' . $dir; } if (!file_exists("{$dir}")) { mkdir_recursive("{$dir}"); } if (!write_array_to_file('mapping', $mapping, "{$dir}/mapping.php")) { $GLOBALS['log']->fatal("Cannot write file {$dir}/mapping.php"); } $source->saveMappingHook($mapping); } //foreach // save eapm configs foreach ($connectors as $connector_name => $data) { if (isset($sources[$connector_name]) && !empty($data["eapm"])) { // if we touched it AND it has EAPM data $connectors[$connector_name]["eapm"]["enabled"] = !empty($_REQUEST[$connector_name . "_external"]); } } ConnectorUtils::saveConnectors($connectors); ConnectorUtils::updateMetaDataFiles(); // BEGIN SUGAR INT if (empty($_REQUEST['from_unit_test'])) { // END SUGAR INT header("Location: index.php?action=ConnectorSettings&module=Connectors"); // BEGIN SUGAR INT } // END SUGAR INT }
protected function importRow($row) { global $sugar_config, $mod_strings, $current_user; $focus = clone $this->bean; $focus->unPopulateDefaultValues(); $focus->save_from_post = false; $focus->team_id = null; $this->ifs->createdBeans = array(); $this->importSource->resetRowErrorCounter(); $do_save = true; for ($fieldNum = 0; $fieldNum < $_REQUEST['columncount']; $fieldNum++) { // loop if this column isn't set if (!isset($this->importColumns[$fieldNum])) { continue; } // get this field's properties $field = $this->importColumns[$fieldNum]; $fieldDef = $focus->getFieldDefinition($field); $fieldTranslated = translate(isset($fieldDef['vname']) ? $fieldDef['vname'] : $fieldDef['name'], $focus->module_dir) . " (" . $fieldDef['name'] . ")"; $defaultRowValue = ''; // Bug 37241 - Don't re-import over a field we already set during the importing of another field if (!empty($focus->{$field})) { continue; } // translate strings global $locale; if (empty($locale)) { $locale = new Localization(); } if (isset($row[$fieldNum])) { $rowValue = $locale->translateCharset(strip_tags(trim($row[$fieldNum])), $this->importSource->importlocale_charset, $sugar_config['default_charset']); } else { if (isset($this->sugarToExternalSourceFieldMap[$field]) && isset($row[$this->sugarToExternalSourceFieldMap[$field]])) { $rowValue = $locale->translateCharset(strip_tags(trim($row[$this->sugarToExternalSourceFieldMap[$field]])), $this->importSource->importlocale_charset, $sugar_config['default_charset']); } else { $rowValue = ''; } } // If there is an default value then use it instead if (!empty($_REQUEST[$field])) { $defaultRowValue = $this->populateDefaultMapValue($field, $_REQUEST[$field], $fieldDef); if (empty($rowValue)) { $rowValue = $defaultRowValue; //reset the default value to empty $defaultRowValue = ''; } } // Bug 22705 - Don't update the First Name or Last Name value if Full Name is set if (in_array($field, array('first_name', 'last_name')) && !empty($focus->full_name)) { continue; } // loop if this value has not been set if (!isset($rowValue)) { continue; } // If the field is required and blank then error out if (array_key_exists($field, $focus->get_import_required_fields()) && empty($rowValue) && $rowValue != '0') { $this->importSource->writeError($mod_strings['LBL_REQUIRED_VALUE'], $fieldTranslated, 'NULL'); $do_save = false; } // Handle the special case "Sync to Outlook" if ($focus->object_name == "Contact" && $field == 'sync_contact') { /** * Bug #41194 : if true used as value of sync_contact - add curent user to list to sync */ if (true == $rowValue || 'true' == strtolower($rowValue)) { $focus->sync_contact = $focus->id; } elseif (false == $rowValue || 'false' == strtolower($rowValue)) { $focus->sync_contact = ''; } else { $bad_names = array(); $returnValue = $this->ifs->synctooutlook($rowValue, $fieldDef, $bad_names); // try the default value on fail if (!$returnValue && !empty($defaultRowValue)) { $returnValue = $this->ifs->synctooutlook($defaultRowValue, $fieldDef, $bad_names); } if (!$returnValue) { $this->importSource->writeError($mod_strings['LBL_ERROR_SYNC_USERS'], $fieldTranslated, $bad_names); $do_save = 0; } else { $focus->sync_contact = $returnValue; } } } // Handle email field, if it's a semi-colon separated export if ($field == 'email_addresses_non_primary' && !empty($rowValue)) { if (strpos($rowValue, ';') !== false) { $rowValue = explode(';', $rowValue); } else { $rowValue = array($rowValue); } } // Handle email1 and email2 fields ( these don't have the type of email ) if ($field == 'email1' || $field == 'email2') { $returnValue = $this->ifs->email($rowValue, $fieldDef, $focus); // try the default value on fail if (!$returnValue && !empty($defaultRowValue)) { $returnValue = $this->ifs->email($defaultRowValue, $fieldDef); } if ($returnValue === FALSE) { $do_save = 0; $this->importSource->writeError($mod_strings['LBL_ERROR_INVALID_EMAIL'], $fieldTranslated, $rowValue); } else { $rowValue = $returnValue; // check for current opt_out and invalid email settings for this email address // if we find any, set them now $emailres = $focus->db->query("SELECT opt_out, invalid_email FROM email_addresses WHERE email_address = '" . $focus->db->quote($rowValue) . "'"); if ($emailrow = $focus->db->fetchByAssoc($emailres)) { $focus->email_opt_out = $emailrow['opt_out']; $focus->invalid_email = $emailrow['invalid_email']; } } } // Handle splitting Full Name into First and Last Name parts if ($field == 'full_name' && !empty($rowValue)) { $this->ifs->fullname($rowValue, $fieldDef, $focus); } // to maintain 451 compatiblity if (!isset($fieldDef['module']) && $fieldDef['type'] == 'relate') { $fieldDef['module'] = ucfirst($fieldDef['table']); } if (isset($fieldDef['custom_type']) && !empty($fieldDef['custom_type'])) { $fieldDef['type'] = $fieldDef['custom_type']; } // If the field is empty then there is no need to check the data if (!empty($rowValue)) { // If it's an array of non-primary e-mails, check each mail if ($field == "email_addresses_non_primary" && is_array($rowValue)) { foreach ($rowValue as $tempRow) { $tempRow = $this->sanitizeFieldValueByType($tempRow, $fieldDef, $defaultRowValue, $focus, $fieldTranslated); if ($tempRow === FALSE) { $rowValue = false; $do_save = false; break; } } } else { $rowValue = $this->sanitizeFieldValueByType($rowValue, $fieldDef, $defaultRowValue, $focus, $fieldTranslated); } if ($rowValue === false) { /* BUG 51213 - jeff @ neposystems.com */ $do_save = false; continue; } } // if the parent type is in singular form, get the real module name for parent_type if (isset($fieldDef['type']) && $fieldDef['type'] == 'parent_type') { $rowValue = get_module_from_singular($rowValue); } $focus->{$field} = $rowValue; unset($defaultRowValue); } // Now try to validate flex relate fields if (isset($focus->field_defs['parent_name']) && isset($focus->parent_name) && $focus->field_defs['parent_name']['type'] == 'parent') { // populate values from the picker widget if the import file doesn't have them $parent_idField = $focus->field_defs['parent_name']['id_name']; if (empty($focus->{$parent_idField}) && !empty($_REQUEST[$parent_idField])) { $focus->{$parent_idField} = $_REQUEST[$parent_idField]; } $parent_typeField = $focus->field_defs['parent_name']['type_name']; if (empty($focus->{$parent_typeField}) && !empty($_REQUEST[$parent_typeField])) { $focus->{$parent_typeField} = $_REQUEST[$parent_typeField]; } // now validate it $returnValue = $this->ifs->parent($focus->parent_name, $focus->field_defs['parent_name'], $focus, empty($_REQUEST['parent_name'])); if (!$returnValue && !empty($_REQUEST['parent_name'])) { $returnValue = $this->ifs->parent($_REQUEST['parent_name'], $focus->field_defs['parent_name'], $focus); } } // check to see that the indexes being entered are unique. if (isset($_REQUEST['enabled_dupes']) && $_REQUEST['enabled_dupes'] != "") { $toDecode = html_entity_decode($_REQUEST['enabled_dupes'], ENT_QUOTES); $enabled_dupes = json_decode($toDecode); $idc = new ImportDuplicateCheck($focus); if ($idc->isADuplicateRecord($enabled_dupes)) { $this->importSource->markRowAsDuplicate($idc->_dupedFields); $this->_undoCreatedBeans($this->ifs->createdBeans); return; } } else { if (!empty($_REQUEST['enabled_dup_fields'])) { $toDecode = html_entity_decode($_REQUEST['enabled_dup_fields'], ENT_QUOTES); $enabled_dup_fields = json_decode($toDecode); $idc = new ImportDuplicateCheck($focus); if ($idc->isADuplicateRecordByFields($enabled_dup_fields)) { $this->importSource->markRowAsDuplicate($idc->_dupedFields); $this->_undoCreatedBeans($this->ifs->createdBeans); return; } } } // if the id was specified $newRecord = true; if (!empty($focus->id)) { $focus->id = $this->_convertId($focus->id); // check if it already exists $query = "SELECT * FROM {$focus->table_name} WHERE id='" . $focus->db->quote($focus->id) . "'"; $result = $focus->db->query($query) or sugar_die("Error selecting sugarbean: "); $dbrow = $focus->db->fetchByAssoc($result); if (isset($dbrow['id']) && $dbrow['id'] != -1) { // if it exists but was deleted, just remove it if (isset($dbrow['deleted']) && $dbrow['deleted'] == 1 && $this->isUpdateOnly == false) { $this->removeDeletedBean($focus); $focus->new_with_id = true; } else { if (!$this->isUpdateOnly) { $this->importSource->writeError($mod_strings['LBL_ID_EXISTS_ALREADY'], 'ID', $focus->id); $this->_undoCreatedBeans($this->ifs->createdBeans); return; } $clonedBean = $this->cloneExistingBean($focus); if ($clonedBean === FALSE) { $this->importSource->writeError($mod_strings['LBL_RECORD_CANNOT_BE_UPDATED'], 'ID', $focus->id); $this->_undoCreatedBeans($this->ifs->createdBeans); return; } else { $focus = $clonedBean; $newRecord = FALSE; } } } else { $focus->new_with_id = true; } } if ($do_save) { $this->saveImportBean($focus, $newRecord); // Update the created/updated counter $this->importSource->markRowAsImported($newRecord); } else { $this->_undoCreatedBeans($this->ifs->createdBeans); } unset($defaultRowValue); }
protected function importRow($row) { global $sugar_config, $mod_strings, $current_user; $focus = BeanFactory::getBean($this->bean->module_dir); $focus->unPopulateDefaultValues(); $focus->save_from_post = false; $focus->team_id = null; $this->ifs->createdBeans = array(); $this->importSource->resetRowErrorCounter(); $do_save = true; // set the currency for the row, if it has a currency_id in the row if ($this->currencyFieldPosition !== false && !empty($row[$this->currencyFieldPosition])) { $currency_id = $row[$this->currencyFieldPosition]; if (!isset($this->cachedCurrencySymbols[$currency_id])) { /** @var Currency $currency */ $currency = BeanFactory::getBean('Currencies', $currency_id); $this->cachedCurrencySymbols[$currency_id] = $currency->symbol; unset($currency); } $this->ifs->currency_symbol = $this->cachedCurrencySymbols[$currency_id]; $this->ifs->currency_id = $currency_id; } // Collect email addresses, and add them before save $emailAddresses = array('non-primary' => array()); $fields_order = $this->getImportColumnsOrder($focus->getFieldDefinitions()); foreach ($fields_order as $fieldNum) { // loop if this column isn't set if (!isset($this->importColumns[$fieldNum])) { continue; } // get this field's properties $field = $this->importColumns[$fieldNum]; $fieldDef = $focus->getFieldDefinition($field); $fieldTranslated = translate(isset($fieldDef['vname']) ? $fieldDef['vname'] : $fieldDef['name'], $focus->module_dir) . " (" . $fieldDef['name'] . ")"; $defaultRowValue = ''; // Bug 37241 - Don't re-import over a field we already set during the importing of another field if (!empty($focus->{$field})) { continue; } // translate strings global $locale; if (empty($locale)) { $locale = Localization::getObject(); } if (isset($row[$fieldNum])) { $rowValue = strip_tags(trim($row[$fieldNum])); } else { if (isset($this->sugarToExternalSourceFieldMap[$field]) && isset($row[$this->sugarToExternalSourceFieldMap[$field]])) { $rowValue = strip_tags(trim($row[$this->sugarToExternalSourceFieldMap[$field]])); } else { $rowValue = ''; } } // If there is an default value then use it instead if (!empty($_REQUEST[$field])) { $defaultRowValue = $this->populateDefaultMapValue($field, $_REQUEST[$field], $fieldDef); if (!empty($fieldDef['custom_type']) && $fieldDef['custom_type'] == 'teamset' && empty($rowValue)) { require_once 'include/SugarFields/Fields/Teamset/SugarFieldTeamset.php'; $sugar_field = new SugarFieldTeamset('Teamset'); $rowValue = implode(', ', $sugar_field->getTeamsFromRequest($field)); } if (empty($rowValue)) { $rowValue = $defaultRowValue; //reset the default value to empty $defaultRowValue = ''; } } // Bug 22705 - Don't update the First Name or Last Name value if Full Name is set if (in_array($field, array('first_name', 'last_name')) && !empty($focus->full_name)) { continue; } // loop if this value has not been set if (!isset($rowValue)) { continue; } // If the field is required and blank then error out if (array_key_exists($field, $focus->get_import_required_fields()) && empty($rowValue) && $rowValue != '0') { $this->importSource->writeError($mod_strings['LBL_REQUIRED_VALUE'], $fieldTranslated, 'NULL'); $do_save = false; } // Handle the special case 'Sync to Mail Client' if ($focus->object_name == "Contact" && $field == 'sync_contact') { /** * Bug #41194 : if true used as value of sync_contact - add curent user to list to sync */ if (true == $rowValue || 'true' == strtolower($rowValue)) { $focus->sync_contact = $focus->id; } elseif (false == $rowValue || 'false' == strtolower($rowValue)) { $focus->sync_contact = ''; } else { $bad_names = array(); $returnValue = $this->ifs->synctooutlook($rowValue, $fieldDef, $bad_names); // try the default value on fail if (!$returnValue && !empty($defaultRowValue)) { $returnValue = $this->ifs->synctooutlook($defaultRowValue, $fieldDef, $bad_names); } if (!$returnValue) { $this->importSource->writeError($mod_strings['LBL_ERROR_SYNC_USERS'], $fieldTranslated, $bad_names); $do_save = 0; } else { $focus->sync_contact = $returnValue; } } } // Handle email1 and email2 fields ( these don't have the type of email ) if ($field == 'email1' || $field == 'email2') { $returnValue = $this->ifs->email($rowValue, $fieldDef, $focus); // try the default value on fail if (!$returnValue && !empty($defaultRowValue)) { $returnValue = $this->ifs->email($defaultRowValue, $fieldDef); } if ($returnValue === FALSE) { $do_save = 0; $this->importSource->writeError($mod_strings['LBL_ERROR_INVALID_EMAIL'], $fieldTranslated, $rowValue); } else { $rowValue = $returnValue; $address = array('email_address' => $rowValue, 'primary_address' => $field == 'email1', 'invalid_email' => false, 'opt_out' => false); // check for current opt_out and invalid email settings for this email address // if we find any, set them now $emailres = $focus->db->query("SELECT opt_out, invalid_email FROM email_addresses WHERE email_address = '" . $focus->db->quote($rowValue) . "'"); if ($emailrow = $focus->db->fetchByAssoc($emailres)) { $address = array_merge($address, $emailrow); } if ($field === 'email1') { //flip the array so we can use it to get the key # $flippedVals = array_flip($this->importColumns); //if the opt out column is set, then attempt to retrieve the values if (isset($flippedVals['email_opt_out'])) { //if the string for this value has a length, then use it. if (isset($row[$flippedVals['email_opt_out']]) && strlen($row[$flippedVals['email_opt_out']]) > 0) { $address['opt_out'] = $row[$flippedVals['email_opt_out']]; } } //if the invalid email column is set, then attempt to retrieve the values if (isset($flippedVals['invalid_email'])) { //if the string for this value has a length, then use it. if (isset($row[$flippedVals['invalid_email']]) && strlen($row[$flippedVals['invalid_email']]) > 0) { $address['invalid_email'] = $row[$flippedVals['invalid_email']]; } } $emailAddresses['primary'] = $address; } else { $emailAddresses['non-primary'][] = $address; } } } if ($field == 'email_addresses_non_primary') { $nonPrimaryAddresses = $this->handleNonPrimaryEmails($rowValue, $defaultRowValue, $fieldTranslated); $emailAddresses['non-primary'] = array_merge($emailAddresses['non-primary'], $nonPrimaryAddresses); } // Handle splitting Full Name into First and Last Name parts if ($field == 'full_name' && !empty($rowValue)) { $this->ifs->fullname($rowValue, $fieldDef, $focus); } // to maintain 451 compatiblity if (!isset($fieldDef['module']) && $fieldDef['type'] == 'relate') { $fieldDef['module'] = ucfirst($fieldDef['table']); } if (isset($fieldDef['custom_type']) && !empty($fieldDef['custom_type'])) { $fieldDef['type'] = $fieldDef['custom_type']; } // If the field is empty then there is no need to check the data if (!empty($rowValue)) { //Start $rowValue = $this->sanitizeFieldValueByType($rowValue, $fieldDef, $defaultRowValue, $focus, $fieldTranslated); if ($rowValue === FALSE) { /* BUG 51213 - jeff @ neposystems.com */ $do_save = false; continue; } } // if the parent type is in singular form, get the real module name for parent_type if (isset($fieldDef['type']) && $fieldDef['type'] == 'parent_type') { $rowValue = get_module_from_singular($rowValue); } $focus->{$field} = $rowValue; unset($defaultRowValue); } // Now try to validate flex relate fields if (isset($focus->field_defs['parent_name']) && isset($focus->parent_name) && $focus->field_defs['parent_name']['type'] == 'parent') { // populate values from the picker widget if the import file doesn't have them $parent_idField = $focus->field_defs['parent_name']['id_name']; if (empty($focus->{$parent_idField}) && !empty($_REQUEST[$parent_idField])) { $focus->{$parent_idField} = $_REQUEST[$parent_idField]; } $parent_typeField = $focus->field_defs['parent_name']['type_name']; if (empty($focus->{$parent_typeField}) && !empty($_REQUEST[$parent_typeField])) { $focus->{$parent_typeField} = $_REQUEST[$parent_typeField]; } // now validate it $returnValue = $this->ifs->parent($focus->parent_name, $focus->field_defs['parent_name'], $focus, empty($_REQUEST['parent_name'])); if (!$returnValue && !empty($_REQUEST['parent_name'])) { $returnValue = $this->ifs->parent($_REQUEST['parent_name'], $focus->field_defs['parent_name'], $focus); } } // check to see that the indexes being entered are unique. if (isset($_REQUEST['enabled_dupes']) && $_REQUEST['enabled_dupes'] != "") { $toDecode = html_entity_decode($_REQUEST['enabled_dupes'], ENT_QUOTES); $enabled_dupes = json_decode($toDecode); $idc = new ImportDuplicateCheck($focus); if ($idc->isADuplicateRecord($enabled_dupes)) { $this->importSource->markRowAsDuplicate($idc->_dupedFields); $this->_undoCreatedBeans($this->ifs->createdBeans); return; } } else { if (!empty($_REQUEST['enabled_dup_fields'])) { $toDecode = html_entity_decode($_REQUEST['enabled_dup_fields'], ENT_QUOTES); $enabled_dup_fields = json_decode($toDecode); $idc = new ImportDuplicateCheck($focus); if ($idc->isADuplicateRecordByFields($enabled_dup_fields)) { $this->importSource->markRowAsDuplicate($idc->_dupedFields); $this->_undoCreatedBeans($this->ifs->createdBeans); return; } } } // if the id was specified $newRecord = true; if (!empty($focus->id)) { $focus->id = $this->_convertId($focus->id); // check if it already exists $query = "SELECT * FROM {$focus->table_name} WHERE id='" . $focus->db->quote($focus->id) . "'"; $result = $focus->db->query($query) or sugar_die("Error selecting sugarbean: "); $dbrow = $focus->db->fetchByAssoc($result); if (isset($dbrow['id']) && $dbrow['id'] != -1) { // if it exists but was deleted, just remove it if (isset($dbrow['deleted']) && $dbrow['deleted'] == 1 && $this->isUpdateOnly == false) { $this->removeDeletedBean($focus); $focus->new_with_id = true; } else { if (!$this->isUpdateOnly) { $this->importSource->writeError($mod_strings['LBL_ID_EXISTS_ALREADY'], 'ID', $focus->id); $this->_undoCreatedBeans($this->ifs->createdBeans); return; } $clonedBean = $this->cloneExistingBean($focus); if ($clonedBean === FALSE) { $this->importSource->writeError($mod_strings['LBL_RECORD_CANNOT_BE_UPDATED'], 'ID', $focus->id); $this->_undoCreatedBeans($this->ifs->createdBeans); return; } else { $focus = $clonedBean; $newRecord = FALSE; } } } else { $focus->new_with_id = true; } } try { // Update e-mails here, because we're calling retrieve, and it overwrites the emailAddress object if ($focus->hasEmails()) { $this->handleEmailUpdate($focus, $emailAddresses); } } catch (Exception $e) { $this->importSource->writeError($e->getMessage(), $fieldTranslated, $focus->id); $do_save = false; } if ($do_save) { $this->saveImportBean($focus, $newRecord); // Update the created/updated counter $this->importSource->markRowAsImported($newRecord); } else { $this->_undoCreatedBeans($this->ifs->createdBeans); } unset($defaultRowValue); }