protected function saveImportBean($focus, $newRecord) { global $timedate, $current_user; // Populate in any default values to the bean $focus->populateDefaultValues(); if (!isset($focus->assigned_user_id) || $focus->assigned_user_id == '' && $newRecord) { $focus->assigned_user_id = $current_user->id; } /* * Bug 34854: Added all conditions besides the empty check on date modified. */ if (!empty($focus->new_with_id) && !empty($focus->date_modified) || empty($focus->new_with_id) && $timedate->to_db($focus->date_modified) != $timedate->to_db($timedate->to_display_date_time($focus->fetched_row['date_modified']))) { $focus->update_date_modified = false; } $focus->optimistic_lock = false; if ($focus->object_name == "Contact" && isset($focus->sync_contact)) { //copy the potential sync list to another varible $list_of_users = $focus->sync_contact; //and set it to false for the save $focus->sync_contact = false; } else { if ($focus->object_name == "User" && !empty($current_user) && $focus->is_admin && !is_admin($current_user) && is_admin_for_module($current_user, 'Users')) { sugar_die($GLOBALS['mod_strings']['ERR_IMPORT_SYSTEM_ADMININSTRATOR']); } } //bug# 46411 importing Calls will not populate Leads or Contacts Subpanel if (!empty($focus->parent_type) && !empty($focus->parent_id)) { foreach ($focus->relationship_fields as $key => $val) { if ($val == strtolower($focus->parent_type)) { $focus->{$key} = $focus->parent_id; } } } //bug# 40260 setting it true as the module in focus is involved in an import $focus->in_import = true; // call any logic needed for the module preSave $focus->beforeImportSave(); // if modified_user_id is set, set the flag to false so SugarBEan will not reset it if (isset($focus->modified_user_id) && $focus->modified_user_id) { $focus->update_modified_by = false; } // if created_by is set, set the flag to false so SugarBEan will not reset it if (isset($focus->created_by) && $focus->created_by) { $focus->set_created_by = false; } if ($focus->object_name == "Contact" && isset($list_of_users)) { $focus->process_sync_to_outlook($list_of_users); } $focus->save(false); //now that save is done, let's make sure that parent and related id's were saved as relationships //this takes place before the afterImportSave() $this->checkRelatedIDsAfterSave($focus); // call any logic needed for the module postSave $focus->afterImportSave(); // Add ID to User's Last Import records if ($newRecord) { $this->importSource->writeRowToLastImport($_REQUEST['import_module'], $focus->object_name == 'Case' ? 'aCase' : $focus->object_name, $focus->id); } }
/** * Parses serialized data of non-primary email addresses * * @param string $value Serialized data in the following format: * email_address1[,invalid_email1[,opt_out1]][;email_address2...] * @param string $fieldTranslated Name of CSV column * * @return array Collection of address properties * @see serializeNonPrimaryEmails() */ protected function parseNonPrimaryEmails($value, $fieldTranslated) { global $mod_strings; $result = array(); if (empty($value)) { return $result; } // explode serialized value into groups of attributes $emails = explode(';', $value); foreach ($emails as $email) { // explode serialized attributes $attrs = explode(',', $email); if (!$attrs) { continue; } $email_address = array_shift($attrs); if (!$this->ifs->email($email_address, array())) { $this->importSource->writeError($mod_strings['LBL_ERROR_INVALID_EMAIL'], $fieldTranslated, $email_address); continue; } $address = array('email_address' => $email_address, 'primary_address' => false, 'invalid_email' => false, 'opt_out' => false); // check if there are elements in $attrs after $email_address was shifted from there if ($attrs) { $invalid_email = array_shift($attrs); $invalid_email = $this->ifs->bool($invalid_email, array()); if ($invalid_email === false) { $this->importSource->writeError($mod_strings['LBL_ERROR_INVALID_BOOL'], $fieldTranslated, $invalid_email); continue; } $address['invalid_email'] = $invalid_email; } // check if there are elements in $attrs after $email_address and $invalid_email were shifted from there if ($attrs) { $opt_out = array_shift($attrs); $opt_out = $this->ifs->bool($opt_out, array()); if ($opt_out === false) { $this->importSource->writeError($mod_strings['LBL_ERROR_INVALID_BOOL'], $fieldTranslated, $opt_out); continue; } $address['opt_out'] = $opt_out; } $result[] = $address; } return $result; }
protected function saveImportBean($focus, $newRecord) { global $timedate, $current_user; // Populate in any default values to the bean $focus->populateDefaultValues(); if (!isset($focus->assigned_user_id) || $focus->assigned_user_id == '' && $newRecord) { $focus->assigned_user_id = $current_user->id; } /* * Bug 34854: Added all conditions besides the empty check on date modified. */ if (!empty($focus->new_with_id) && !empty($focus->date_modified) || empty($focus->new_with_id) && $timedate->to_db($focus->date_modified) != $timedate->to_db($timedate->to_display_date_time($focus->fetched_row['date_modified']))) { $focus->update_date_modified = false; } $focus->optimistic_lock = false; if ($focus->object_name == "Contacts" && isset($focus->sync_contact)) { //copy the potential sync list to another varible $list_of_users = $focus->sync_contact; //and set it to false for the save $focus->sync_contact = false; } else { if ($focus->object_name == "User" && !empty($current_user) && $focus->is_admin && !is_admin($current_user) && is_admin_for_module($current_user, 'Users')) { sugar_die($GLOBALS['mod_strings']['ERR_IMPORT_SYSTEM_ADMININSTRATOR']); } } //bug# 40260 setting it true as the module in focus is involved in an import $focus->in_import = true; // call any logic needed for the module preSave $focus->beforeImportSave(); $focus->save(false); // call any logic needed for the module postSave $focus->afterImportSave(); if ($focus->object_name == "Contacts" && isset($list_of_users)) { $focus->process_sync_to_outlook($list_of_users); } // Add ID to User's Last Import records if ($newRecord) { $this->importSource->writeRowToLastImport($_REQUEST['import_module'], $focus->object_name == 'Case' ? 'aCase' : $focus->object_name, $focus->id); } }