Fix : socialnetworks import in db

This commit is contained in:
lmarcouiller 2022-05-25 16:05:02 +02:00
parent 9a7c28d61d
commit b1481d8495
2 changed files with 15 additions and 12 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

@ -1072,14 +1072,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 +1100,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 +1118,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>';
@ -1234,7 +1234,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>';