Skip to content

Commit

Permalink
Merge pull request #272 from Sota-Miyamoto/fix_export_import_relation…
Browse files Browse the repository at this point in the history
…_users

#249 関連のユーザーをエクスポート・インポートした際に生じる問題を修正
  • Loading branch information
Remicck authored Jan 30, 2022
2 parents 38c52a8 + fac7944 commit f344c9f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
16 changes: 13 additions & 3 deletions modules/Import/actions/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ public function createRecords() {

public function transformForImport($fieldData, $moduleMeta, $fillDefault = true, $checkMandatoryFieldValues = true) {
global $current_user;
$adb = PearDatabase::getInstance();
$moduleImportableFields = array();
$moduleFields = $moduleMeta->getModuleFields();
$moduleName = $moduleMeta->getEntityName();
Expand Down Expand Up @@ -571,7 +572,17 @@ public function transformForImport($fieldData, $moduleMeta, $fillDefault = true,
$referenceModuleName = trim($fieldValueDetails[0]);
if (count($fieldValueDetails) == 2) {
$entityLabel = trim($fieldValueDetails[1]);
$entityId = getEntityId($referenceModuleName, decode_html($entityLabel));
if ($fieldValueDetails[0] == 'Users') {
$query = "SELECT id FROM vtiger_users WHERE trim(concat(last_name,' ',first_name)) = ? ;";
$result = $adb->pquery($query, array($entityLabel));
if ($adb->num_rows($result) > 0) {
$entityId = $adb->query_result($result, 0, "id");
} elseif ($adb->num_rows($result) == 0 && $fieldInstance->isMandatory()) {
$entityId = $this->user->id;
}
} else {
$entityId = getEntityId($referenceModuleName, decode_html($entityLabel));
}
} else {//multi reference field
$entityIdsList = $this->getEntityIdsList($referenceModuleName, $fieldValueDetails);
if ($entityIdsList) {
Expand Down Expand Up @@ -619,8 +630,7 @@ public function transformForImport($fieldData, $moduleMeta, $fillDefault = true,
if (isset($defaultFieldValues[$fieldName])) {
$fieldData[$fieldName] = $defaultFieldValues[$fieldName];
}
if (empty($fieldData[$fieldName]) ||
!Import_Utils_Helper::hasAssignPrivilege($moduleName, $fieldData[$fieldName])) {
if ($fieldInstance->isMandatory() && (empty($fieldData[$fieldName]) || !Import_Utils_Helper::hasAssignPrivilege($moduleName, $fieldData[$fieldName]))) {
$fieldData[$fieldName] = $this->user->id;
}
} else {
Expand Down
17 changes: 16 additions & 1 deletion modules/Vtiger/actions/ExportData.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ function sanitizeValues($arr){
}elseif($type == 'reference'){
$value = trim($value);
if(!empty($value)) {
$parent_module = getSalesEntityType($value);
$parent_module = $this->getParentModuleName($value, $fieldName);
$displayValueArray = getEntityName($parent_module, $value);
if(!empty($displayValueArray)){
foreach($displayValueArray as $k=>$v){
Expand Down Expand Up @@ -388,6 +388,21 @@ function sanitizeValues($arr){
return $arr;
}

function getParentModuleName($value, $fieldName) {
$db = PearDatabase::getInstance();
$query = "SELECT relmodule FROM vtiger_fieldmodulerel WHERE fieldid = (SELECT fieldid FROM vtiger_field WHERE columnname = ? );";
$result = $db->pquery($query, array($fieldName));
if ($db->num_rows($result) > 0) {
$columname = $db->query_result($result, 0, "relmodule");
}
if($columname == "Users"){
$parent_module = "Users";
} else {
$parent_module = getSalesEntityType($value);
}
return $parent_module;
}

public function moduleFieldInstances($moduleName) {
return $this->moduleInstance->getFields();
}
Expand Down

0 comments on commit f344c9f

Please sign in to comment.