Merge pull request #21030 from Hystepik/develop#1

Fix : socialnetworks import in db and import model in import
This commit is contained in:
Laurent Destailleur 2022-05-25 16:57:27 +02:00 committed by GitHub
commit 60dd526973
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 26 deletions

View File

@ -715,19 +715,16 @@ class ImportCsv extends ModeleImports
}
if (!empty($newval) && $arrayrecord[($key - 1)]['type'] > 0) {
$socialkey = array_search("socialnetworks", $listfields);
$socialnetwork = explode("_", $fieldname)[1];
if (empty($listvalues[$socialkey]) || $listvalues[$socialkey] == "null") {
$socialnetwork = explode("_", $fieldname)[1];
$json = new stdClass();
$json->$socialnetwork = $newval;
$newvalue = json_encode($json);
$listvalues[$socialkey] = "'".$this->db->escape($newvalue)."'";
$listvalues[$socialkey] = json_encode($json);
} else {
$socialnetwork = explode("_", $fieldname)[1];
$jsondata = $listvalues[$socialkey];
$jsondata = str_replace("'", "", $jsondata);
$json = json_decode($jsondata);
$json->$socialnetwork = $newval;
$listvalues[$socialkey] = "'".$this->db->escape(json_encode($json))."'";
$listvalues[$socialkey] = json_encode($json);
}
}
} else {
@ -745,6 +742,12 @@ class ImportCsv extends ModeleImports
$i++;
}
// We db escape social network field because he isn't in field creation
if (in_array("socialnetworks", $listfields)) {
$socialkey = array_search("socialnetworks", $listfields);
$tmpsql = $listvalues[$socialkey];
$listvalues[$socialkey] = "'".$this->db->escape($tmpsql)."'";
}
// We add hidden fields (but only if there is at least one field to add into table)
// We process here all the fields that were declared into the array ->import_fieldshidden_array of the descriptor file.
// Previously we processed the ->import_fields_array.

View File

@ -153,18 +153,6 @@ $htmlother = new FormOther($db);
$formfile = new FormFile($db);
// Init $array_match_file_to_database from _SESSION
$serialized_array_match_file_to_database = isset($_SESSION["dol_array_match_file_to_database"]) ? $_SESSION["dol_array_match_file_to_database"] : '';
$array_match_file_to_database = array();
$fieldsarray = explode(',', $serialized_array_match_file_to_database);
foreach ($fieldsarray as $elem) {
$tabelem = explode('=', $elem, 2);
$key = $tabelem[0];
$val = (isset($tabelem[1]) ? $tabelem[1] : '');
if ($key && $val) {
$array_match_file_to_database[$key] = $val;
}
}
if (empty($array_match_file_to_database)) {
$serialized_array_match_file_to_database = isset($_SESSION["dol_array_match_file_to_database_select"]) ? $_SESSION["dol_array_match_file_to_database_select"] : '';
$array_match_file_to_database = array();
@ -1072,14 +1060,14 @@ if ($step == 4 && $datatoimport) {
if (!$line["imported"]) {
$optionsnotused .= $text;
}
$optionsall[$code] = array('label'=>$langs->trans($line["label"]), 'required'=>(empty($line["required"]) ? 0 : 1), 'position'=>$line['position']);
$optionsall[$code] = array('label'=>$langs->trans($line["label"]), 'required'=>(empty($line["required"]) ? 0 : 1), 'position'=>!empty($line['position']) ? $line['position'] : 0);
}
// $optionsall is an array of all possible fields. key=>array('label'=>..., 'xxx')
$height = '32px'; //needs px for css height attribute below
$i = 0;
$mandatoryfieldshavesource = true;
$more = "";
//var_dump($fieldstarget);
//var_dump($optionsall);
//exit;
@ -1100,7 +1088,7 @@ if ($step == 4 && $datatoimport) {
$entity = (!empty($objimport->array_import_entities[0][$code]) ? $objimport->array_import_entities[0][$code] : $objimport->array_import_icon[0]);
$tablealias = preg_replace('/(\..*)$/i', '', $code);
$tablename = $objimport->array_import_tables[0][$tablealias];
$tablename = !empty($objimport->array_import_tables[0][$tablealias]) ? $objimport->array_import_tables[0][$tablealias] : "";
$entityicon = !empty($entitytoicon[$entity]) ? $entitytoicon[$entity] : $entity; // $entityicon must string name of picto of the field like 'project', 'company', 'contact', 'modulename', ...
$entitylang = $entitytolang[$entity] ? $entitytolang[$entity] : $objimport->array_import_label[0]; // $entitylang must be a translation key to describe object the field is related to, like 'Company', 'Contact', 'MyModyle', ...
@ -1118,8 +1106,8 @@ if ($step == 4 && $datatoimport) {
//var_dump($_SESSION['dol_array_match_file_to_database']);
//var_dump($modetoautofillmapping);
print '<select id="selectorderimport_'.($i+1).'" class="targetselectchange minwidth300" name="select_'.$line["label"].'">';
if ($line["imported"]) {
print '<select id="selectorderimport_'.($i+1).'" class="targetselectchange minwidth300" name="select_'.($i+1).'">';
if (!empty($line["imported"])) {
print '<option value="-1">&nbsp;</option>';
} else {
print '<option selected="" value="-1">&nbsp;</option>';
@ -1166,10 +1154,10 @@ if ($step == 4 && $datatoimport) {
//var_dump($code);
//var_dump($tmpselectioninsession);
//if ($tmpselectioninsession[$j] == $code) {
if ($tmpselectioninsession[($i+1)] == $tmpcode) {
if (!empty($tmpselectioninsession[($i+1)]) && $tmpselectioninsession[($i+1)] == $tmpcode) {
print ' selected';
}
print ' data-debug="'.$tmpcode.'-'.$code.'-'.$j.'-'.$tmpselectioninsession[($i+1)].'"';
print ' data-debug="'.$tmpcode.'-'.$code.'-'.$j.'-'.(!empty($tmpselectioninsession[($i+1)]) ? $tmpselectioninsession[($i+1)] : "").'"';
}
print ' data-html="'.dol_escape_htmltag($label).'"';
print '>';
@ -1234,7 +1222,7 @@ if ($step == 4 && $datatoimport) {
$htmltext .= $langs->trans("DataCodeIDSourceIsInsertedInto").'<br>';
}
}
$htmltext .= $langs->trans("FieldTitle").": <b>".$langs->trans($line["label"])."</b><br>";
$htmltext .= $langs->trans("FieldTitle").": <b>".$langs->trans($fieldstarget[$arraykeysfieldtarget[$code-1]]["label"])."</b><br>";
$htmltext .= $langs->trans("Table")." -> ".$langs->trans("Field").': <b>'.$tablename." -> ".preg_replace('/^.*\./', '', $code)."</b><br>";
print $form->textwithpicto($more, $htmltext);
print '</tr>';