307 public function import_insert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys)
310 global $langs, $conf, $user;
311 global $thirdparty_static;
312 global $tablewithentity_cache;
316 $this->errors = array();
317 $this->warnings = array();
324 $array_match_database_to_file = array_flip($array_match_file_to_database);
325 $sort_array_match_file_to_database = $array_match_file_to_database;
326 ksort($sort_array_match_file_to_database);
330 if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[0][
'val']))) {
332 $this->warnings[$warning][
'lib'] = $langs->trans(
'EmptyLine');
333 $this->warnings[$warning][
'type'] =
'EMPTY';
336 $last_insert_id_array = array();
340 foreach ($objimport->array_import_tables[0] as $alias => $tablename) {
343 $listfields = array();
344 $listvalues = array();
346 $errorforthistable = 0;
349 if (!isset($tablewithentity_cache[$tablename])) {
350 dol_syslog(
"Check if table ".$tablename.
" has an entity field");
351 $resql = $this->db->DDLDescTable($tablename,
'entity');
353 $obj = $this->db->fetch_object($resql);
355 $tablewithentity_cache[$tablename] = 1;
357 $tablewithentity_cache[$tablename] = 0;
367 $arrayfield = array();
368 foreach ($sort_array_match_file_to_database as $key => $val) {
369 $arrayfield[$val] = ($key - 1);
376 foreach ($sort_array_match_file_to_database as $key => $val) {
377 $fieldalias = preg_replace(
'/\..*$/i',
'', $val);
378 $fieldname = preg_replace(
'/^.*\./i',
'', $val);
380 if ($alias != $fieldalias) {
384 if ($key <= $maxfields) {
387 if ($arrayrecord[($key - 1)][
'type'] > 0) {
388 $newval = $arrayrecord[($key - 1)][
'val'];
397 if (preg_match(
'/\*/', $objimport->array_import_fields[0][$val]) && ((string) $newval ==
'')) {
399 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorMissingMandatoryValue', $key);
400 $this->errors[$error][
'type'] =
'NOTNULL';
401 $errorforthistable++;
406 if (!empty($objimport->array_import_convertvalue[0][$val])) {
408 if ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeid'
409 || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromref'
410 || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeorlabel'
414 if (!is_numeric($newval) && $newval !=
'' && !preg_match(
'/^id:/i', $newval)) {
418 $newval = preg_replace(
'/^(id|ref):/i',
'', $newval);
421 if ($isidorref ==
'ref') {
422 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
423 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
424 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
425 if ($this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'][$newval] !=
'') {
426 $newval = $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'][$newval];
429 if (empty($resultload)) {
430 dol_print_error(
null,
'Error trying to call file='.$file.
', class='.$class.
', method='.$method);
433 $classinstance =
new $class($this->db);
434 if ($class ==
'CGenericDic') {
435 $classinstance->element = $objimport->array_import_convertvalue[0][$val][
'element'];
436 $classinstance->table_element = $objimport->array_import_convertvalue[0][$val][
'table_element'];
440 $param_array = array(
'', $newval);
441 if ($class ==
'AccountingAccount') {
454 $param_array = array(
'', $newval, 0, $arrayrecord[0][
'val']);
456 if ($class ==
'CActionComm') {
457 $param_array = array($newval);
459 $result = call_user_func_array(array($classinstance, $method), $param_array);
462 if (!($classinstance->id !=
'') && $result == -2) {
463 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorMultipleRecordFoundFromRef', $newval);
464 $this->errors[$error][
'type'] =
'FOREIGNKEY';
465 $errorforthistable++;
470 if (!($classinstance->id !=
'') && $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeorlabel') {
471 $param_array = array(
'',
'', $newval);
472 call_user_func_array(array($classinstance, $method), $param_array);
474 $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'][$newval] = $classinstance->id;
477 if ($classinstance->id !=
'') {
478 $newval = $classinstance->id;
479 } elseif (! $error) {
480 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
481 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn',
num2Alpha($key - 1), $newval,
'code', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
482 } elseif (!empty($objimport->array_import_convertvalue[0][$val][
'element'])) {
483 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldRefNotIn',
num2Alpha($key - 1), $newval, $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'element']));
485 $this->errors[$error][
'lib'] =
'ErrorBadDefinitionOfImportProfile';
487 $this->errors[$error][
'type'] =
'FOREIGNKEY';
488 $errorforthistable++;
493 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeandlabel') {
495 if (!is_numeric($newval) && $newval !=
'' && !preg_match(
'/^id:/i', $newval)) {
498 $newval = preg_replace(
'/^(id|ref):/i',
'', $newval);
500 if ($isidorref ==
'ref') {
501 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
502 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
503 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
504 $codefromfield = $objimport->array_import_convertvalue[0][$val][
'codefromfield'];
505 $code = $arrayrecord[$arrayfield[$codefromfield]][
'val'];
506 if ($this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$code][$newval] !=
'') {
507 $newval = $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$code][$newval];
510 if (empty($resultload)) {
511 dol_print_error(
null,
'Error trying to call file='.$file.
', class='.$class.
', method='.$method.
', code='.$code);
514 $classinstance =
new $class($this->db);
516 $param_array = array(
'', $newval, $code);
517 call_user_func_array(array($classinstance, $method), $param_array);
518 $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$code][$newval] = $classinstance->id;
519 if ($classinstance->id > 0) {
520 $newval = $classinstance->id;
522 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
523 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn',
num2Alpha($key - 1), $newval,
'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
525 $this->errors[$error][
'lib'] =
'ErrorFieldValueNotIn';
527 $this->errors[$error][
'type'] =
'FOREIGNKEY';
528 $errorforthistable++;
533 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'zeroifnull') {
534 if (empty($newval)) {
537 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeunits' || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchscalefromcodeunits') {
538 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
539 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
540 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
541 $units = $objimport->array_import_convertvalue[0][$val][
'units'];
542 if ($this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$units][$newval] !=
'') {
543 $newval = $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$units][$newval];
546 if (empty($resultload)) {
547 dol_print_error(
null,
'Error trying to call file='.$file.
', class='.$class.
', method='.$method.
', units='.$units);
550 $classinstance =
new $class($this->db);
552 call_user_func_array(array($classinstance, $method), array(
'',
'', $newval, $units));
553 $scaleorid = (($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeunits') ? $classinstance->id : $classinstance->scale);
554 $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$units][$newval] = $scaleorid;
556 if ($classinstance->id > 0) {
557 $newval = $scaleorid ? $scaleorid : 0;
559 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
560 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn',
num2Alpha($key - 1), $newval,
'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
562 $this->errors[$error][
'lib'] =
'ErrorFieldValueNotIn';
564 $this->errors[$error][
'type'] =
'FOREIGNKEY';
565 $errorforthistable++;
569 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getcustomercodeifauto') {
570 if (strtolower($newval) ==
'auto') {
571 $this->thirdpartyobject->get_codeclient(0, 0);
572 $newval = $this->thirdpartyobject->code_client;
575 if (empty($newval)) {
576 $arrayrecord[($key - 1)][
'type'] = -1;
578 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getsuppliercodeifauto') {
579 if (strtolower($newval) ==
'auto') {
580 $this->thirdpartyobject->get_codefournisseur(0, 1);
581 $newval = $this->thirdpartyobject->code_fournisseur;
584 if (empty($newval)) {
585 $arrayrecord[($key - 1)][
'type'] = -1;
587 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getcustomeraccountancycodeifauto') {
588 if (strtolower($newval) ==
'auto') {
589 $this->thirdpartyobject->get_codecompta(
'customer');
590 $newval = $this->thirdpartyobject->code_compta;
593 if (empty($newval)) {
594 $arrayrecord[($key - 1)][
'type'] = -1;
596 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getsupplieraccountancycodeifauto') {
597 if (strtolower($newval) ==
'auto') {
598 $this->thirdpartyobject->get_codecompta(
'supplier');
599 $newval = $this->thirdpartyobject->code_compta_fournisseur;
600 if (empty($newval)) {
601 $arrayrecord[($key - 1)][
'type'] = -1;
605 if (empty($newval)) {
606 $arrayrecord[($key - 1)][
'type'] = -1;
608 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getrefifauto') {
609 if (strtolower($newval) ==
'auto') {
612 $classModForNumber = $objimport->array_import_convertvalue[0][$val][
'class'];
613 $pathModForNumber = $objimport->array_import_convertvalue[0][$val][
'path'];
615 if (!empty($classModForNumber) && !empty($pathModForNumber) && is_readable(DOL_DOCUMENT_ROOT.$pathModForNumber)) {
616 require_once DOL_DOCUMENT_ROOT.$pathModForNumber;
617 $modForNumber =
new $classModForNumber();
621 if (!empty($objimport->array_import_convertvalue[0][$val][
'classobject'])) {
622 $pathForObject = $objimport->array_import_convertvalue[0][$val][
'pathobject'];
623 require_once DOL_DOCUMENT_ROOT.$pathForObject;
624 $tmpclassobject = $objimport->array_import_convertvalue[0][$val][
'classobject'];
625 $tmpobject =
new $tmpclassobject($this->db);
626 foreach ($arrayfield as $tmpkey => $tmpval) {
627 if (in_array($tmpkey, array(
't.date',
'c.date_commande'))) {
628 $tmpobject->date =
dol_stringtotime($arrayrecord[$arrayfield[$tmpkey]][
'val'], 1);
633 $defaultref = $modForNumber->getNextValue(
null, $tmpobject);
635 if (is_numeric($defaultref) && $defaultref <= 0) {
638 $newval = $defaultref;
640 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'compute') {
641 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
642 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
643 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
645 if (empty($resultload)) {
646 dol_print_error(
null,
'Error trying to call file='.$file.
', class='.$class.
', method='.$method);
649 $classinstance =
new $class($this->db);
650 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, ($key - 1)));
651 if (empty($classinstance->error) && empty($classinstance->errors)) {
654 $this->errors[$error][
'type'] =
'CLASSERROR';
655 $this->errors[$error][
'lib'] = implode(
657 array_merge([$classinstance->error], $classinstance->errors)
659 $errorforthistable++;
662 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'numeric') {
664 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'accountingaccount') {
666 $newval = rtrim(trim($newval),
"0");
668 $newval = trim($newval);
676 if (!empty($objimport->array_import_regex[0][$val]) && ($newval !=
'')) {
679 if (preg_match(
'/^(.+)@([^:]+)(:.+)?$/', $objimport->array_import_regex[0][$val], $reg)) {
682 $filter = !empty($reg[3]) ? substr($reg[3], 1) :
'';
684 $cachekey = $field.
'@'.$table;
685 if (!empty($filter)) {
686 $cachekey .=
':'.$filter;
690 if (!is_array($this->cachefieldtable[$cachekey])) {
691 $sql =
"SELECT ".$field.
" as aliasfield FROM ".$table;
692 if (!empty($filter)) {
693 $sql .=
' WHERE '.$filter;
696 $resql = $this->db->query($sql);
698 $num = $this->db->num_rows($resql);
701 $obj = $this->db->fetch_object($resql);
703 $this->cachefieldtable[$cachekey][] = $obj->aliasfield;
713 if (!is_array($this->cachefieldtable[$cachekey]) || !in_array($newval, $this->cachefieldtable[$cachekey])) {
714 $tableforerror = $table;
715 if (!empty($filter)) {
716 $tableforerror .=
':'.$filter;
718 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorFieldValueNotIn',
num2Alpha($key - 1), $newval, $field, $tableforerror);
719 $this->errors[$error][
'type'] =
'FOREIGNKEY';
720 $errorforthistable++;
723 } elseif (!preg_match(
'/'.$objimport->array_import_regex[0][$val].
'/i', $newval)) {
726 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorWrongValueForField',
num2Alpha($key - 1), $newval, $objimport->array_import_regex[0][$val]);
727 $this->errors[$error][
'type'] =
'REGEX';
728 $errorforthistable++;
736 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorHtmlInjectionForField',
num2Alpha($key - 1),
dol_trunc($newval, 100));
737 $this->errors[$error][
'type'] =
'HTMLINJECTION';
738 $errorforthistable++;
747 if (isModEnabled(
"socialnetworks") && strpos($fieldname,
"socialnetworks") !==
false) {
748 if (!in_array(
"socialnetworks", $listfields)) {
749 $listfields[] =
"socialnetworks";
750 $socialkey = array_search(
"socialnetworks", $listfields);
751 $listvalues[$socialkey] =
'';
754 if (!empty($newval) && $arrayrecord[($key - 1)][
'type'] > 0) {
755 $socialkey = array_search(
"socialnetworks", $listfields);
757 $socialnetwork = explode(
"_", $fieldname)[1];
758 if (empty($listvalues[$socialkey]) || $listvalues[$socialkey] ==
"null") {
760 $json->$socialnetwork = $newval;
761 $listvalues[$socialkey] = json_encode($json);
763 $jsondata = $listvalues[$socialkey];
764 $json = json_decode($jsondata);
765 $json->$socialnetwork = $newval;
766 $listvalues[$socialkey] = json_encode($json);
770 $listfields[] = $fieldname;
772 if (empty($newval) && $arrayrecord[($key - 1)][
'type'] < 0) {
773 $listvalues[] = ($newval ==
'0' ? (int) $newval :
"null");
774 } elseif (empty($newval) && $arrayrecord[($key - 1)][
'type'] == 0) {
775 $listvalues[] =
"''";
777 $listvalues[] =
"'".$this->db->escape($newval).
"'";
787 if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0])) {
789 foreach ($objimport->array_import_fieldshidden[0] as $tmpkey => $tmpval) {
790 if (!preg_match(
'/^' . preg_quote($alias,
'/') .
'\./', $tmpkey)) {
793 $keyfield = preg_replace(
'/^' . preg_quote($alias,
'/') .
'\./',
'', $tmpkey);
795 if (in_array($keyfield, $listfields)) {
797 } elseif ($tmpval ==
'user->id') {
798 $listfields[] = $keyfield;
799 $listvalues[] = ((int) $user->id);
800 } elseif (preg_match(
'/^lastrowid-/', $tmpval)) {
801 $tmp = explode(
'-', $tmpval);
802 $lastinsertid = (isset($last_insert_id_array[$tmp[1]])) ? $last_insert_id_array[$tmp[1]] : 0;
803 $listfields[] = $keyfield;
804 $listvalues[] = (int) $lastinsertid;
806 } elseif (preg_match(
'/^const-/', $tmpval)) {
807 $tmp = explode(
'-', $tmpval, 2);
808 $listfields[] = $keyfield;
809 $listvalues[] =
"'".$this->db->escape($tmp[1]).
"'";
810 } elseif (preg_match(
'/^rule-/', $tmpval)) {
811 $fieldname = $tmpkey;
812 if (!empty($objimport->array_import_convertvalue[0][$fieldname])) {
813 if ($objimport->array_import_convertvalue[0][$fieldname][
'rule'] ==
'compute') {
814 $file = (empty($objimport->array_import_convertvalue[0][$fieldname][
'classfile']) ? $objimport->array_import_convertvalue[0][$fieldname][
'file'] : $objimport->array_import_convertvalue[0][$fieldname][
'classfile']);
815 $class = $objimport->array_import_convertvalue[0][$fieldname][
'class'];
816 $method = $objimport->array_import_convertvalue[0][$fieldname][
'method'];
817 $type = $objimport->array_import_convertvalue[0][$fieldname][
'type'];
819 if (empty($resultload)) {
820 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method);
823 $classinstance =
new $class($this->db);
824 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, ($key - 1)));
825 if (empty($classinstance->error) && empty($classinstance->errors)) {
826 $fieldArr = explode(
'.', $fieldname);
827 if (count($fieldArr) > 0) {
828 $fieldname = $fieldArr[1];
832 $listfields[] = $fieldname;
833 if ($type ==
'int') {
834 $listvalues[] = (int) $res;
835 } elseif ($type ==
'double') {
836 $listvalues[] = (float) $res;
838 $listvalues[] =
"'".$this->db->escape($res).
"'";
841 $this->errors[$error][
'type'] =
'CLASSERROR';
842 $this->errors[$error][
'lib'] = implode(
844 array_merge([$classinstance->error], $classinstance->errors)
846 $errorforthistable++;
852 $this->errors[$error][
'lib'] =
'Bad value of profile setup '.$tmpval.
' for array_import_fieldshidden';
853 $this->errors[$error][
'type'] =
'Import profile setup';
862 if (!$errorforthistable) {
864 if (!empty($listfields)) {
868 $is_table_category_link =
false;
870 if (strpos($tablename,
'_categorie_') !==
false) {
871 $is_table_category_link =
true;
875 if (!empty($updatekeys)) {
878 if (empty($lastinsertid)) {
879 $sqlSelect =
"SELECT ".$fname.
" FROM ".$tablename;
880 $data = array_combine($listfields, $listvalues);
883 foreach ($updatekeys as $key) {
884 $col = $objimport->array_import_updatekeys[0][$key];
885 $key = preg_replace(
'/^.*\./i',
'', $key);
886 if (isModEnabled(
"socialnetworks") && strpos($key,
"socialnetworks") !==
false) {
887 $tmp = explode(
"_", $key);
889 $socialnetwork = $tmp[1];
890 $jsondata = $data[$key];
891 $json = json_decode($jsondata);
892 $stringtosearch = json_encode($socialnetwork).
':'.json_encode($json->$socialnetwork);
895 $where[] = $key.
" LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch)).
"%'";
896 $filters[] = $col.
" LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch)).
"%'";
899 $where[] = $key.
' = '.$data[$key];
900 $filters[] = $col.
' = '.$data[$key];
903 if (!empty($tablewithentity_cache[$tablename])) {
907 $sqlSelect .=
" WHERE ".implode(
' AND ', $where);
909 $resql = $this->db->query($sqlSelect);
911 $num_rows = $this->db->num_rows($resql);
912 if ($num_rows == 1) {
913 $res = $this->db->fetch_object($resql);
914 $lastinsertid = $res->rowid;
915 if ($is_table_category_link) {
916 $lastinsertid =
'linktable';
918 $last_insert_id_array[$tablename] = $lastinsertid;
919 } elseif ($num_rows > 1) {
920 $this->errors[$error][
'lib'] = $langs->trans(
'MultipleRecordFoundWithTheseFilters', implode(
', ', $filters));
921 $this->errors[$error][
'type'] =
'SQL';
928 $this->errors[$error][
'lib'] = $this->db->lasterror();
929 $this->errors[$error][
'type'] =
'SQL';
938 $sqlSelect =
"SELECT rowid FROM ".$tablename;
940 if (empty($keyfield)) {
943 $sqlSelect .=
" WHERE ".$keyfield.
" = ".((int) $lastinsertid);
945 if (!empty($tablewithentity_cache[$tablename])) {
949 $resql = $this->db->query($sqlSelect);
951 $res = $this->db->fetch_object($resql);
952 if ($this->db->num_rows($resql) == 1) {
961 $this->errors[$error][
'lib'] = $this->db->lasterror();
962 $this->errors[$error][
'type'] =
'SQL';
967 if (!empty($lastinsertid)) {
969 if (in_array(
"socialnetworks", $listfields)) {
970 $socialkey = array_search(
"socialnetworks", $listfields);
971 $tmpsql = $listvalues[$socialkey];
972 $listvalues[$socialkey] =
"'".$this->db->escape($tmpsql).
"'";
976 $sqlstart =
"UPDATE ".$tablename;
978 $data = array_combine($listfields, $listvalues);
980 foreach ($data as $key => $val) {
981 $set[] = $key.
" = ".$val;
983 $sqlstart .=
" SET ".implode(
', ', $set).
", import_key = '".$this->db->escape($importid).
"'";
985 if (empty($keyfield)) {
988 $sqlend =
" WHERE ".$keyfield.
" = ".((int) $lastinsertid);
990 if ($is_table_category_link) {
991 '@phan-var-force string[] $where';
992 $sqlend =
" WHERE " . implode(
' AND ', $where);
995 if (!empty($tablewithentity_cache[$tablename])) {
999 $sql = $sqlstart.$sqlend;
1002 $resql = $this->db->query($sql);
1008 $this->errors[$error][
'lib'] = $this->db->lasterror();
1009 $this->errors[$error][
'type'] =
'SQL';
1016 if (!$error && !$updatedone) {
1018 if (in_array(
"socialnetworks", $listfields)) {
1019 $socialkey = array_search(
"socialnetworks", $listfields);
1020 $tmpsql = $listvalues[$socialkey];
1021 $listvalues[$socialkey] =
"'".$this->db->escape($tmpsql).
"'";
1025 $sqlstart =
"INSERT INTO ".$tablename.
"(".implode(
", ", $listfields).
", import_key";
1026 $sqlend =
") VALUES(".implode(
', ', $listvalues).
", '".$this->db->escape($importid).
"'";
1027 if (!empty($tablewithentity_cache[$tablename])) {
1028 $sqlstart .=
", entity";
1029 $sqlend .=
", ".$conf->entity;
1031 if (!empty($objimport->array_import_tables_creator[0][$alias])) {
1032 $sqlstart .=
", ".$objimport->array_import_tables_creator[0][$alias];
1033 $sqlend .=
", ".$user->id;
1035 $sql = $sqlstart.$sqlend.
")";
1040 $resql = $this->db->query($sql);
1042 if (!$is_table_category_link) {
1043 $last_insert_id_array[$tablename] = $this->db->last_insert_id($tablename);
1048 $this->errors[$error][
'lib'] = $this->db->lasterror();
1049 $this->errors[$error][
'type'] =
'SQL';