372 public function import_insert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys)
375 global $langs, $conf, $user;
376 global $thirdparty_static;
377 global $tablewithentity_cache;
381 $this->errors = array();
382 $this->warnings = array();
389 $array_match_database_to_file = array_flip($array_match_file_to_database);
390 $sort_array_match_file_to_database = $array_match_file_to_database;
391 ksort($sort_array_match_file_to_database);
395 if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[1][
'val']))) {
397 $this->warnings[$warning][
'lib'] = $langs->trans(
'EmptyLine');
398 $this->warnings[$warning][
'type'] =
'EMPTY';
401 $last_insert_id_array = array();
405 foreach ($objimport->array_import_tables[0] as $alias => $tablename) {
408 $listfields = array();
409 $listvalues = array();
411 $errorforthistable = 0;
414 if (!isset($tablewithentity_cache[$tablename])) {
415 dol_syslog(
"Check if table " . $tablename .
" has an entity field");
416 $resql = $this->db->DDLDescTable($tablename,
'entity');
418 $obj = $this->db->fetch_object($resql);
420 $tablewithentity_cache[$tablename] = 1;
422 $tablewithentity_cache[$tablename] = 0;
432 $arrayfield = array();
433 foreach ($sort_array_match_file_to_database as $key => $val) {
434 $arrayfield[$val] = ($key);
441 foreach ($sort_array_match_file_to_database as $key => $val) {
442 $fieldalias = preg_replace(
'/\..*$/i',
'', $val);
443 $fieldname = preg_replace(
'/^.*\./i',
'', $val);
445 if ($alias != $fieldalias) {
449 if ($key <= $maxfields) {
452 if ($arrayrecord[($key)][
'type'] > 0) {
453 $newval = $arrayrecord[($key)][
'val'];
462 if (preg_match(
'/\*/', $objimport->array_import_fields[0][$val]) && ((string) $newval ==
'')) {
463 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorMissingMandatoryValue',
num2Alpha($key - 1));
464 $this->errors[$error][
'type'] =
'NOTNULL';
465 $errorforthistable++;
470 if (!empty($objimport->array_import_convertvalue[0][$val])) {
472 if ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeid'
473 || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromref'
474 || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeorlabel'
478 if (!is_numeric($newval) && $newval !=
'' && !preg_match(
'/^id:/i', $newval)) {
481 $newval = preg_replace(
'/^(id|ref):/i',
'', $newval);
484 if ($isidorref ==
'ref') {
485 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
486 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
487 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
488 if ($this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_'][$newval] !=
'') {
489 $newval = $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_'][$newval];
492 if (empty($resultload)) {
493 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method);
496 $classinstance =
new $class($this->db);
497 if ($class ==
'CGenericDic') {
498 $classinstance->element = $objimport->array_import_convertvalue[0][$val][
'element'];
499 $classinstance->table_element = $objimport->array_import_convertvalue[0][$val][
'table_element'];
503 $param_array = array(
'', $newval);
504 if ($class ==
'AccountingAccount') {
517 $param_array = array(
'', $newval, 0, $arrayrecord[0][
'val']);
520 $result = call_user_func_array(array($classinstance, $method), $param_array);
523 if (!($classinstance->id !=
'') && $result == -2) {
524 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorMultipleRecordFoundFromRef', $newval);
525 $this->errors[$error][
'type'] =
'FOREIGNKEY';
526 $errorforthistable++;
531 if (!($classinstance->id !=
'') && $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeorlabel') {
532 $param_array = array(
'',
'', $newval);
533 call_user_func_array(array($classinstance, $method), $param_array);
535 $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_'][$newval] = $classinstance->id;
538 if ($classinstance->id !=
'') {
539 $newval = $classinstance->id;
540 } elseif (! $error) {
541 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
543 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn', $key, $newval,
'code', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
544 } elseif (!empty($objimport->array_import_convertvalue[0][$val][
'element'])) {
546 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldRefNotIn', $key, $newval, $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'element']));
548 $this->errors[$error][
'lib'] =
'ErrorBadDefinitionOfImportProfile';
550 $this->errors[$error][
'type'] =
'FOREIGNKEY';
551 $errorforthistable++;
556 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeandlabel') {
558 if (!is_numeric($newval) && $newval !=
'' && !preg_match(
'/^id:/i', $newval)) {
561 $newval = preg_replace(
'/^(id|ref):/i',
'', $newval);
563 if ($isidorref ==
'ref') {
564 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
565 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
566 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
567 $codefromfield = $objimport->array_import_convertvalue[0][$val][
'codefromfield'];
568 $code = $arrayrecord[$arrayfield[$codefromfield]][
'val'];
569 if ($this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $code][$newval] !=
'') {
570 $newval = $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $code][$newval];
573 if (empty($resultload)) {
574 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method .
', code=' . $code);
577 $classinstance =
new $class($this->db);
579 $param_array = array(
'', $newval, $code);
580 call_user_func_array(array($classinstance, $method), $param_array);
581 $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $code][$newval] = $classinstance->id;
582 if ($classinstance->id > 0) {
583 $newval = $classinstance->id;
585 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
587 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn', $key, $newval,
'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
589 $this->errors[$error][
'lib'] =
'ErrorFieldValueNotIn';
591 $this->errors[$error][
'type'] =
'FOREIGNKEY';
592 $errorforthistable++;
597 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'zeroifnull') {
598 if (empty($newval)) {
601 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeunits' || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchscalefromcodeunits') {
602 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
603 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
604 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
605 $units = $objimport->array_import_convertvalue[0][$val][
'units'];
606 if ($this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $units][$newval] !=
'') {
607 $newval = $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $units][$newval];
610 if (empty($resultload)) {
611 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method .
', units=' . $units);
614 $classinstance =
new $class($this->db);
616 call_user_func_array(array($classinstance, $method), array(
'',
'', $newval, $units));
617 $scaleorid = (($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeunits') ? $classinstance->id : $classinstance->scale);
618 $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $units][$newval] = $scaleorid;
620 if ($classinstance->id > 0) {
621 $newval = $scaleorid ? $scaleorid : 0;
623 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
625 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn', $key, $newval,
'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
627 $this->errors[$error][
'lib'] =
'ErrorFieldValueNotIn';
629 $this->errors[$error][
'type'] =
'FOREIGNKEY';
630 $errorforthistable++;
634 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getcustomercodeifauto') {
635 if (strtolower($newval) ==
'auto') {
636 $this->thirdpartyobject->get_codeclient(0, 0);
637 $newval = $this->thirdpartyobject->code_client;
640 if (empty($newval)) {
641 $arrayrecord[($key)][
'type'] = -1;
643 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getsuppliercodeifauto') {
644 if (strtolower($newval) ==
'auto') {
645 $this->thirdpartyobject->get_codefournisseur(0, 1);
646 $newval = $this->thirdpartyobject->code_fournisseur;
649 if (empty($newval)) {
650 $arrayrecord[($key)][
'type'] = -1;
652 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getcustomeraccountancycodeifauto') {
653 if (strtolower($newval) ==
'auto') {
654 $this->thirdpartyobject->get_codecompta(
'customer');
655 $newval = $this->thirdpartyobject->code_compta;
658 if (empty($newval)) {
659 $arrayrecord[($key)][
'type'] = -1;
661 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getsupplieraccountancycodeifauto') {
662 if (strtolower($newval) ==
'auto') {
663 $this->thirdpartyobject->get_codecompta(
'supplier');
664 $newval = $this->thirdpartyobject->code_compta_fournisseur;
665 if (empty($newval)) {
666 $arrayrecord[($key)][
'type'] = -1;
670 if (empty($newval)) {
671 $arrayrecord[($key)][
'type'] = -1;
673 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getrefifauto') {
674 if (strtolower($newval) ==
'auto') {
677 $classModForNumber = $objimport->array_import_convertvalue[0][$val][
'class'];
678 $pathModForNumber = $objimport->array_import_convertvalue[0][$val][
'path'];
680 if (!empty($classModForNumber) && !empty($pathModForNumber) && is_readable(DOL_DOCUMENT_ROOT.$pathModForNumber)) {
681 require_once DOL_DOCUMENT_ROOT.$pathModForNumber;
682 $modForNumber =
new $classModForNumber();
686 if (!empty($objimport->array_import_convertvalue[0][$val][
'classobject'])) {
687 $pathForObject = $objimport->array_import_convertvalue[0][$val][
'pathobject'];
688 require_once DOL_DOCUMENT_ROOT.$pathForObject;
689 $tmpclassobject = $objimport->array_import_convertvalue[0][$val][
'classobject'];
690 $tmpobject =
new $tmpclassobject($this->db);
691 foreach ($arrayfield as $tmpkey => $tmpval) {
692 if (in_array($tmpkey, array(
't.date',
'c.date_commande'))) {
693 $tmpobject->date =
dol_stringtotime($arrayrecord[$arrayfield[$tmpkey]][
'val'], 1);
698 $defaultref = $modForNumber->getNextValue(
null, $tmpobject);
700 if (is_numeric($defaultref) && $defaultref <= 0) {
703 $newval = $defaultref;
705 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'compute') {
706 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
707 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
708 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
710 if (empty($resultload)) {
711 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method);
714 $classinstance =
new $class($this->db);
715 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, $key));
716 if (empty($classinstance->error) && empty($classinstance->errors)) {
719 $this->errors[$error][
'type'] =
'CLASSERROR';
720 $this->errors[$error][
'lib'] = implode(
722 array_merge([$classinstance->error], $classinstance->errors)
724 $errorforthistable++;
727 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'numeric') {
729 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'accountingaccount') {
731 $newval = rtrim(trim($newval),
"0");
733 $newval = trim($newval);
741 if (!empty($objimport->array_import_regex[0][$val]) && ($newval !=
'')) {
744 if (preg_match(
'/^(.+)@([^:]+)(:.+)?$/', $objimport->array_import_regex[0][$val], $reg)) {
747 $filter = !empty($reg[3]) ? substr($reg[3], 1) :
'';
749 $cachekey = $field .
'@' . $table;
750 if (!empty($filter)) {
751 $cachekey .=
':' . $filter;
755 if (!is_array($this->cachefieldtable[$cachekey])) {
756 $sql =
"SELECT " . $field .
" as aliasfield FROM " . $table;
757 if (!empty($filter)) {
758 $sql .=
' WHERE ' . $filter;
762 $resql = $this->db->query($sql);
764 $num = $this->db->num_rows($resql);
767 $obj = $this->db->fetch_object($resql);
769 $this->cachefieldtable[$cachekey][] = $obj->aliasfield;
779 if (!is_array($this->cachefieldtable[$cachekey]) || !in_array($newval, $this->cachefieldtable[$cachekey])) {
780 $tableforerror = $table;
781 if (!empty($filter)) {
782 $tableforerror .=
':' . $filter;
785 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorFieldValueNotIn', $key, $newval, $field, $tableforerror);
786 $this->errors[$error][
'type'] =
'FOREIGNKEY';
787 $errorforthistable++;
790 } elseif (!preg_match(
'/' . $objimport->array_import_regex[0][$val] .
'/i', $newval)) {
794 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorWrongValueForField', $key, $newval, $objimport->array_import_regex[0][$val]);
795 $this->errors[$error][
'type'] =
'REGEX';
796 $errorforthistable++;
805 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorHtmlInjectionForField', $key,
dol_trunc($newval, 100));
806 $this->errors[$error][
'type'] =
'HTMLINJECTION';
807 $errorforthistable++;
816 if (isModEnabled(
"socialnetworks") && strpos($fieldname,
"socialnetworks") !==
false) {
817 if (!in_array(
"socialnetworks", $listfields)) {
818 $listfields[] =
"socialnetworks";
819 $socialkey = array_search(
"socialnetworks", $listfields);
820 $listvalues[$socialkey] =
'';
822 if (!empty($newval) && $arrayrecord[($key)][
'type'] > 0) {
823 $socialkey = array_search(
"socialnetworks", $listfields);
824 $socialnetwork = explode(
"_", $fieldname)[1];
825 if (empty($listvalues[$socialkey]) || $listvalues[$socialkey] ==
"null") {
827 $json->$socialnetwork = $newval;
828 $listvalues[$socialkey] = json_encode($json);
830 $jsondata = $listvalues[$socialkey];
831 $json = json_decode($jsondata);
832 $json->$socialnetwork = $newval;
833 $listvalues[$socialkey] = json_encode($json);
837 $listfields[] = $fieldname;
840 if (empty($newval) && $arrayrecord[($key)][
'type'] < 0) {
841 $listvalues[] = ($newval ==
'0' ? (int) $newval :
"null");
842 } elseif (empty($newval) && $arrayrecord[($key)][
'type'] == 0) {
843 $listvalues[] =
"''";
845 $listvalues[] =
"'".$this->db->escape($newval).
"'";
855 if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0])) {
857 foreach ($objimport->array_import_fieldshidden[0] as $key => $val) {
858 if (!preg_match(
'/^' . preg_quote($alias,
'/') .
'\./', $key)) {
861 $keyfieldcache = preg_replace(
'/^' . preg_quote($alias,
'/') .
'\./',
'', $key);
862 if (in_array($keyfieldcache, $listfields)) {
864 } elseif ($val ==
'user->id') {
865 $listfields[] = $keyfieldcache;
866 $listvalues[] = ((int) $user->id);
867 } elseif (preg_match(
'/^lastrowid-/', $val)) {
868 $tmp = explode(
'-', $val);
869 $lastinsertid = (isset($last_insert_id_array[$tmp[1]])) ? $last_insert_id_array[$tmp[1]] : 0;
870 $listfields[] = $keyfieldcache;
871 $keyfield = $keyfieldcache;
872 $listvalues[] = (int) $lastinsertid;
874 } elseif (preg_match(
'/^const-/', $val)) {
875 $tmp = explode(
'-', $val, 2);
876 $listfields[] = $keyfieldcache;
877 $listvalues[] =
"'".$this->db->escape($tmp[1]).
"'";
878 } elseif (preg_match(
'/^rule-/', $val)) {
880 if (!empty($objimport->array_import_convertvalue[0][$fieldname])) {
881 if ($objimport->array_import_convertvalue[0][$fieldname][
'rule'] ==
'compute') {
882 $file = (empty($objimport->array_import_convertvalue[0][$fieldname][
'classfile']) ? $objimport->array_import_convertvalue[0][$fieldname][
'file'] : $objimport->array_import_convertvalue[0][$fieldname][
'classfile']);
883 $class = $objimport->array_import_convertvalue[0][$fieldname][
'class'];
884 $method = $objimport->array_import_convertvalue[0][$fieldname][
'method'];
885 $type = $objimport->array_import_convertvalue[0][$fieldname][
'type'];
887 if (empty($resultload)) {
888 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method);
891 $classinstance =
new $class($this->db);
892 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, $key));
893 $fieldArr = explode(
'.', $fieldname);
894 if (count($fieldArr) > 0) {
895 $fieldname = $fieldArr[1];
899 $listfields[] = $fieldname;
900 if ($type ==
'int') {
901 $listvalues[] = (int) $res;
902 } elseif ($type ==
'double') {
903 $listvalues[] = (float) $res;
905 $listvalues[] =
"'".$this->db->escape($res).
"'";
908 $this->errors[$error][
'type'] =
'CLASSERROR';
909 $this->errors[$error][
'lib'] = implode(
911 array_merge([$classinstance->error], $classinstance->errors)
913 $errorforthistable++;
918 $this->errors[$error][
'lib'] =
'Bad value of profile setup ' . $val .
' for array_import_fieldshidden';
919 $this->errors[$error][
'type'] =
'Import profile setup';
928 if (!$errorforthistable) {
930 if (!empty($listfields)) {
934 $is_table_category_link =
false;
936 if (strpos($tablename,
'_categorie_') !==
false) {
937 $is_table_category_link =
true;
941 if (!empty($updatekeys)) {
944 if (empty($lastinsertid)) {
945 $sqlSelect =
"SELECT ".$fname.
" FROM " . $tablename;
947 $data = array_combine($listfields, $listvalues);
951 '@phan-var string[] $where';
953 foreach ($updatekeys as $key) {
954 $col = $objimport->array_import_updatekeys[0][$key];
955 $key = preg_replace(
'/^.*\./i',
'', $key);
956 if (isModEnabled(
"socialnetworks") && strpos($key,
"socialnetworks") !==
false) {
957 $tmp = explode(
"_", $key);
959 $socialnetwork = $tmp[1];
960 $jsondata = $data[$key];
961 $json = json_decode($jsondata);
962 $stringtosearch = json_encode($socialnetwork).
':'.json_encode($json->$socialnetwork);
965 $where[] = $key.
" LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch)).
"%'";
966 $filters[] = $col.
" LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch)).
"%'";
969 $where[] = $key.
' = '.$data[$key];
970 $filters[] = $col.
' = '.$data[$key];
973 if (!empty($tablewithentity_cache[$tablename])) {
977 $sqlSelect .=
" WHERE " . implode(
' AND ', $where);
979 $resql = $this->db->query($sqlSelect);
981 $num_rows = $this->db->num_rows($resql);
982 if ($num_rows == 1) {
983 $res = $this->db->fetch_object($resql);
984 $lastinsertid = $res->rowid;
985 if ($is_table_category_link) {
986 $lastinsertid =
'linktable';
988 $last_insert_id_array[$tablename] = $lastinsertid;
989 } elseif ($num_rows > 1) {
990 $this->errors[$error][
'lib'] = $langs->trans(
'MultipleRecordFoundWithTheseFilters', implode(
', ', $filters));
991 $this->errors[$error][
'type'] =
'SQL';
998 $this->errors[$error][
'lib'] = $this->db->lasterror();
999 $this->errors[$error][
'type'] =
'SQL';
1008 $sqlSelect =
"SELECT rowid FROM " . $tablename;
1011 if (empty($keyfield)) {
1012 $keyfield =
'rowid';
1014 $sqlSelect .=
" WHERE ".$keyfield.
" = ".((int) $lastinsertid);
1016 if (!empty($tablewithentity_cache[$tablename])) {
1020 $resql = $this->db->query($sqlSelect);
1022 $res = $this->db->fetch_object($resql);
1023 if ($this->db->num_rows($resql) == 1) {
1032 $this->errors[$error][
'lib'] = $this->db->lasterror();
1033 $this->errors[$error][
'type'] =
'SQL';
1038 if (!empty($lastinsertid)) {
1040 if (in_array(
"socialnetworks", $listfields)) {
1041 $socialkey = array_search(
"socialnetworks", $listfields);
1042 $tmpsql = $listvalues[$socialkey];
1043 $listvalues[$socialkey] =
"'".$this->db->escape($tmpsql).
"'";
1047 $sqlstart =
"UPDATE " . $tablename;
1049 $data = array_combine($listfields, $listvalues);
1051 foreach ($data as $key => $val) {
1052 $set[] = $key.
" = ".$val;
1054 $sqlstart .=
" SET " . implode(
', ', $set) .
", import_key = '" . $this->db->escape($importid) .
"'";
1055 if (empty($keyfield)) {
1056 $keyfield =
'rowid';
1058 $sqlend =
" WHERE " . $keyfield .
" = ".((int) $lastinsertid);
1060 if ($is_table_category_link) {
1061 '@phan-var-force string[] $where';
1062 $sqlend =
" WHERE " . implode(
' AND ', $where);
1065 if (!empty($tablewithentity_cache[$tablename])) {
1069 $sql = $sqlstart . $sqlend;
1072 $resql = $this->db->query($sql);
1078 $this->errors[$error][
'lib'] = $this->db->lasterror();
1079 $this->errors[$error][
'type'] =
'SQL';
1086 if (!$error && !$updatedone) {
1088 if (in_array(
"socialnetworks", $listfields)) {
1089 $socialkey = array_search(
"socialnetworks", $listfields);
1090 $tmpsql = $listvalues[$socialkey];
1091 $listvalues[$socialkey] =
"'".$this->db->escape($tmpsql).
"'";
1095 $sqlstart =
"INSERT INTO " . $tablename .
"(" . implode(
", ", $listfields) .
", import_key";
1096 $sqlend =
") VALUES(" . implode(
', ', $listvalues) .
", '" . $this->db->escape($importid) .
"'";
1097 if (!empty($tablewithentity_cache[$tablename])) {
1098 $sqlstart .=
", entity";
1099 $sqlend .=
", " . $conf->entity;
1101 if (!empty($objimport->array_import_tables_creator[0][$alias])) {
1102 $sqlstart .=
", " . $objimport->array_import_tables_creator[0][$alias];
1103 $sqlend .=
", " . $user->id;
1105 $sql = $sqlstart . $sqlend .
")";
1110 $resql = $this->db->query($sql);
1112 if (!$is_table_category_link) {
1113 $last_insert_id_array[$tablename] = $this->db->last_insert_id($tablename);
1118 $this->errors[$error][
'lib'] = $this->db->lasterror();
1119 $this->errors[$error][
'type'] =
'SQL';