365 public function import_insert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys)
368 global $langs, $conf, $user;
369 global $thirdparty_static;
370 global $tablewithentity_cache;
374 $this->errors = array();
375 $this->warnings = array();
382 $array_match_database_to_file = array_flip($array_match_file_to_database);
383 $sort_array_match_file_to_database = $array_match_file_to_database;
384 ksort($sort_array_match_file_to_database);
388 if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[1][
'val']))) {
390 $this->warnings[$warning][
'lib'] = $langs->trans(
'EmptyLine');
391 $this->warnings[$warning][
'type'] =
'EMPTY';
394 $last_insert_id_array = array();
398 foreach ($objimport->array_import_tables[0] as $alias => $tablename) {
401 $listfields = array();
402 $listvalues = array();
404 $errorforthistable = 0;
407 if (!isset($tablewithentity_cache[$tablename])) {
408 dol_syslog(
"Check if table " . $tablename .
" has an entity field");
409 $resql = $this->db->DDLDescTable($tablename,
'entity');
411 $obj = $this->db->fetch_object($resql);
413 $tablewithentity_cache[$tablename] = 1;
415 $tablewithentity_cache[$tablename] = 0;
425 $arrayfield = array();
426 foreach ($sort_array_match_file_to_database as $key => $val) {
427 $arrayfield[$val] = ($key);
434 foreach ($sort_array_match_file_to_database as $key => $val) {
435 $fieldalias = preg_replace(
'/\..*$/i',
'', $val);
436 $fieldname = preg_replace(
'/^.*\./i',
'', $val);
438 if ($alias != $fieldalias) {
442 if ($key <= $maxfields) {
445 if ($arrayrecord[($key)][
'type'] > 0) {
446 $newval = $arrayrecord[($key)][
'val'];
455 if (preg_match(
'/\*/', $objimport->array_import_fields[0][$val]) && ((string) $newval ==
'')) {
456 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorMissingMandatoryValue',
num2Alpha($key - 1));
457 $this->errors[$error][
'type'] =
'NOTNULL';
458 $errorforthistable++;
463 if (!empty($objimport->array_import_convertvalue[0][$val])) {
465 if ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeid'
466 || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromref'
467 || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeorlabel'
471 if (!is_numeric($newval) && $newval !=
'' && !preg_match(
'/^id:/i', $newval)) {
474 $newval = preg_replace(
'/^(id|ref):/i',
'', $newval);
477 if ($isidorref ==
'ref') {
478 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
479 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
480 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
481 if ($this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_'][$newval] !=
'') {
482 $newval = $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_'][$newval];
485 if (empty($resultload)) {
486 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method);
489 $classinstance =
new $class($this->db);
490 if ($class ==
'CGenericDic') {
491 $classinstance->element = $objimport->array_import_convertvalue[0][$val][
'element'];
492 $classinstance->table_element = $objimport->array_import_convertvalue[0][$val][
'table_element'];
496 $param_array = array(
'', $newval);
497 if ($class ==
'AccountingAccount') {
510 $param_array = array(
'', $newval, 0, $arrayrecord[0][
'val']);
513 $result = call_user_func_array(array($classinstance, $method), $param_array);
516 if (!($classinstance->id !=
'') && $result == -2) {
517 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorMultipleRecordFoundFromRef', $newval);
518 $this->errors[$error][
'type'] =
'FOREIGNKEY';
519 $errorforthistable++;
524 if (!($classinstance->id !=
'') && $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeorlabel') {
525 $param_array = array(
'',
'', $newval);
526 call_user_func_array(array($classinstance, $method), $param_array);
528 $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_'][$newval] = $classinstance->id;
531 if ($classinstance->id !=
'') {
532 $newval = $classinstance->id;
533 } elseif (! $error) {
534 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
536 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn', $key, $newval,
'code', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
537 } elseif (!empty($objimport->array_import_convertvalue[0][$val][
'element'])) {
539 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldRefNotIn', $key, $newval, $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'element']));
541 $this->errors[$error][
'lib'] =
'ErrorBadDefinitionOfImportProfile';
543 $this->errors[$error][
'type'] =
'FOREIGNKEY';
544 $errorforthistable++;
549 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeandlabel') {
551 if (!is_numeric($newval) && $newval !=
'' && !preg_match(
'/^id:/i', $newval)) {
554 $newval = preg_replace(
'/^(id|ref):/i',
'', $newval);
556 if ($isidorref ==
'ref') {
557 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
558 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
559 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
560 $codefromfield = $objimport->array_import_convertvalue[0][$val][
'codefromfield'];
561 $code = $arrayrecord[$arrayfield[$codefromfield]][
'val'];
562 if ($this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $code][$newval] !=
'') {
563 $newval = $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $code][$newval];
566 if (empty($resultload)) {
567 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method .
', code=' . $code);
570 $classinstance =
new $class($this->db);
572 $param_array = array(
'', $newval, $code);
573 call_user_func_array(array($classinstance, $method), $param_array);
574 $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $code][$newval] = $classinstance->id;
575 if ($classinstance->id > 0) {
576 $newval = $classinstance->id;
578 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
580 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn', $key, $newval,
'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
582 $this->errors[$error][
'lib'] =
'ErrorFieldValueNotIn';
584 $this->errors[$error][
'type'] =
'FOREIGNKEY';
585 $errorforthistable++;
590 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'zeroifnull') {
591 if (empty($newval)) {
594 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeunits' || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchscalefromcodeunits') {
595 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
596 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
597 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
598 $units = $objimport->array_import_convertvalue[0][$val][
'units'];
599 if ($this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $units][$newval] !=
'') {
600 $newval = $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $units][$newval];
603 if (empty($resultload)) {
604 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method .
', units=' . $units);
607 $classinstance =
new $class($this->db);
609 call_user_func_array(array($classinstance, $method), array(
'',
'', $newval, $units));
610 $scaleorid = (($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeunits') ? $classinstance->id : $classinstance->scale);
611 $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $units][$newval] = $scaleorid;
613 if ($classinstance->id > 0) {
614 $newval = $scaleorid ? $scaleorid : 0;
616 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
618 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn', $key, $newval,
'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
620 $this->errors[$error][
'lib'] =
'ErrorFieldValueNotIn';
622 $this->errors[$error][
'type'] =
'FOREIGNKEY';
623 $errorforthistable++;
627 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getcustomercodeifauto') {
628 if (strtolower($newval) ==
'auto') {
629 $this->thirdpartyobject->get_codeclient(0, 0);
630 $newval = $this->thirdpartyobject->code_client;
633 if (empty($newval)) {
634 $arrayrecord[($key)][
'type'] = -1;
636 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getsuppliercodeifauto') {
637 if (strtolower($newval) ==
'auto') {
638 $this->thirdpartyobject->get_codefournisseur(0, 1);
639 $newval = $this->thirdpartyobject->code_fournisseur;
642 if (empty($newval)) {
643 $arrayrecord[($key)][
'type'] = -1;
645 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getcustomeraccountancycodeifauto') {
646 if (strtolower($newval) ==
'auto') {
647 $this->thirdpartyobject->get_codecompta(
'customer');
648 $newval = $this->thirdpartyobject->code_compta_client;
651 if (empty($newval)) {
652 $arrayrecord[($key)][
'type'] = -1;
654 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getsupplieraccountancycodeifauto') {
655 if (strtolower($newval) ==
'auto') {
656 $this->thirdpartyobject->get_codecompta(
'supplier');
657 $newval = $this->thirdpartyobject->code_compta_fournisseur;
658 if (empty($newval)) {
659 $arrayrecord[($key)][
'type'] = -1;
663 if (empty($newval)) {
664 $arrayrecord[($key)][
'type'] = -1;
666 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getrefifauto') {
667 if (strtolower($newval) ==
'auto') {
670 $classModForNumber = $objimport->array_import_convertvalue[0][$val][
'class'];
671 $pathModForNumber = $objimport->array_import_convertvalue[0][$val][
'path'];
673 if (!empty($classModForNumber) && !empty($pathModForNumber) && is_readable(DOL_DOCUMENT_ROOT.$pathModForNumber)) {
674 require_once DOL_DOCUMENT_ROOT.$pathModForNumber;
675 $modForNumber =
new $classModForNumber();
676 '@phan-var-force ModeleNumRefMembers|ModeleNumRefCommandes|ModeleNumRefSuppliersInvoices|ModeleNumRefSuppliersOrders|ModeleNumRefProjects|ModeleNumRefTask|ModeleNumRefPropales $modForNumber';
680 if (!empty($objimport->array_import_convertvalue[0][$val][
'classobject'])) {
681 $pathForObject = $objimport->array_import_convertvalue[0][$val][
'pathobject'];
682 require_once DOL_DOCUMENT_ROOT.$pathForObject;
683 $tmpclassobject = $objimport->array_import_convertvalue[0][$val][
'classobject'];
684 $tmpobject =
new $tmpclassobject($this->db);
685 foreach ($arrayfield as $tmpkey => $tmpval) {
686 if (in_array($tmpkey, array(
't.date',
'c.date_commande'))) {
687 $tmpobject->date =
dol_stringtotime($arrayrecord[$arrayfield[$tmpkey]][
'val'], 1);
692 $defaultref = $modForNumber->getNextValue(
null, $tmpobject);
694 if (is_numeric($defaultref) && $defaultref <= 0) {
697 $newval = $defaultref;
699 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'compute') {
700 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
701 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
702 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
704 if (empty($resultload)) {
705 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method);
708 $classinstance =
new $class($this->db);
709 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, $key));
710 if (empty($classinstance->error) && empty($classinstance->errors)) {
713 $this->errors[$error][
'type'] =
'CLASSERROR';
714 $this->errors[$error][
'lib'] = implode(
716 array_merge([$classinstance->error], $classinstance->errors)
718 $errorforthistable++;
721 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'numeric') {
723 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'accountingaccount') {
725 $newval = rtrim(trim($newval),
"0");
727 $newval = trim($newval);
735 if (!empty($objimport->array_import_regex[0][$val]) && ($newval !=
'')) {
738 if (preg_match(
'/^(.+)@([^:]+)(:.+)?$/', $objimport->array_import_regex[0][$val], $reg)) {
741 $filter = !empty($reg[3]) ? substr($reg[3], 1) :
'';
743 $cachekey = $field .
'@' . $table;
744 if (!empty($filter)) {
745 $cachekey .=
':' . $filter;
749 if (!is_array($this->cachefieldtable[$cachekey])) {
750 $sql =
"SELECT " . $field .
" as aliasfield FROM " . $table;
751 if (!empty($filter)) {
752 $sql .=
' WHERE ' . $filter;
755 $resql = $this->db->query($sql);
757 $num = $this->db->num_rows($resql);
760 $obj = $this->db->fetch_object($resql);
762 $this->cachefieldtable[$cachekey][] = $obj->aliasfield;
772 if (!is_array($this->cachefieldtable[$cachekey]) || !in_array($newval, $this->cachefieldtable[$cachekey])) {
773 $tableforerror = $table;
774 if (!empty($filter)) {
775 $tableforerror .=
':' . $filter;
778 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorFieldValueNotIn', $key, $newval, $field, $tableforerror);
779 $this->errors[$error][
'type'] =
'FOREIGNKEY';
780 $errorforthistable++;
783 } elseif (!preg_match(
'/' . $objimport->array_import_regex[0][$val] .
'/i', $newval)) {
787 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorWrongValueForField', $key, $newval, $objimport->array_import_regex[0][$val]);
788 $this->errors[$error][
'type'] =
'REGEX';
789 $errorforthistable++;
798 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorHtmlInjectionForField', $key,
dol_trunc($newval, 100));
799 $this->errors[$error][
'type'] =
'HTMLINJECTION';
800 $errorforthistable++;
809 if (isModEnabled(
"socialnetworks") && strpos($fieldname,
"socialnetworks") !==
false) {
810 if (!in_array(
"socialnetworks", $listfields)) {
811 $listfields[] =
"socialnetworks";
812 $socialkey = array_search(
"socialnetworks", $listfields);
813 $listvalues[$socialkey] =
'';
815 if (!empty($newval) && $arrayrecord[($key)][
'type'] > 0) {
816 $socialkey = array_search(
"socialnetworks", $listfields);
817 $socialnetwork = explode(
"_", $fieldname)[1];
818 if (empty($listvalues[$socialkey]) || $listvalues[$socialkey] ==
"null") {
820 $json->$socialnetwork = $newval;
821 $listvalues[$socialkey] = json_encode($json);
823 $jsondata = $listvalues[$socialkey];
824 $json = json_decode($jsondata);
825 $json->$socialnetwork = $newval;
826 $listvalues[$socialkey] = json_encode($json);
830 $listfields[] = $fieldname;
833 if (empty($newval) && $arrayrecord[($key)][
'type'] < 0) {
834 $listvalues[] = ($newval ==
'0' ? (int) $newval :
"null");
835 } elseif (empty($newval) && $arrayrecord[($key)][
'type'] == 0) {
836 $listvalues[] =
"''";
838 $listvalues[] =
"'".$this->db->escape($newval).
"'";
848 if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0])) {
850 foreach ($objimport->array_import_fieldshidden[0] as $key => $val) {
851 if (!preg_match(
'/^' . preg_quote($alias,
'/') .
'\./', $key)) {
854 $keyfield = preg_replace(
'/^' . preg_quote($alias,
'/') .
'\./',
'', $key);
856 if (in_array($keyfield, $listfields)) {
858 } elseif ($val ==
'user->id') {
859 $listfields[] = $keyfield;
860 $listvalues[] = ((int) $user->id);
861 } elseif (preg_match(
'/^lastrowid-/', $val)) {
862 $tmp = explode(
'-', $val);
863 $lastinsertid = (isset($last_insert_id_array[$tmp[1]])) ? $last_insert_id_array[$tmp[1]] : 0;
864 $listfields[] = $keyfield;
865 $listvalues[] = (int) $lastinsertid;
867 } elseif (preg_match(
'/^const-/', $val)) {
868 $tmp = explode(
'-', $val, 2);
869 $listfields[] = $keyfield;
870 $listvalues[] =
"'".$this->db->escape($tmp[1]).
"'";
871 } elseif (preg_match(
'/^rule-/', $val)) {
873 if (!empty($objimport->array_import_convertvalue[0][$fieldname])) {
874 if ($objimport->array_import_convertvalue[0][$fieldname][
'rule'] ==
'compute') {
875 $file = (empty($objimport->array_import_convertvalue[0][$fieldname][
'classfile']) ? $objimport->array_import_convertvalue[0][$fieldname][
'file'] : $objimport->array_import_convertvalue[0][$fieldname][
'classfile']);
876 $class = $objimport->array_import_convertvalue[0][$fieldname][
'class'];
877 $method = $objimport->array_import_convertvalue[0][$fieldname][
'method'];
878 $type = $objimport->array_import_convertvalue[0][$fieldname][
'type'];
880 if (empty($resultload)) {
881 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method);
884 $classinstance =
new $class($this->db);
885 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, $key));
886 $fieldArr = explode(
'.', $fieldname);
887 if (count($fieldArr) > 0) {
888 $fieldname = $fieldArr[1];
892 $listfields[] = $fieldname;
893 if ($type ==
'int') {
894 $listvalues[] = (int) $res;
895 } elseif ($type ==
'double') {
896 $listvalues[] = (float) $res;
898 $listvalues[] =
"'".$this->db->escape($res).
"'";
901 $this->errors[$error][
'type'] =
'CLASSERROR';
902 $this->errors[$error][
'lib'] = implode(
904 array_merge([$classinstance->error], $classinstance->errors)
906 $errorforthistable++;
911 $this->errors[$error][
'lib'] =
'Bad value of profile setup ' . $val .
' for array_import_fieldshidden';
912 $this->errors[$error][
'type'] =
'Import profile setup';
921 if (!$errorforthistable) {
923 if (!empty($listfields)) {
927 $is_table_category_link =
false;
929 if (strpos($tablename,
'_categorie_') !==
false) {
930 $is_table_category_link =
true;
934 if (!empty($updatekeys)) {
937 if (empty($lastinsertid)) {
938 $sqlSelect =
"SELECT ".$fname.
" FROM " . $tablename;
940 $data = array_combine($listfields, $listvalues);
944 '@phan-var string[] $where';
946 foreach ($updatekeys as $key) {
947 $col = $objimport->array_import_updatekeys[0][$key];
948 $key = preg_replace(
'/^.*\./i',
'', $key);
949 if (isModEnabled(
"socialnetworks") && strpos($key,
"socialnetworks") !==
false) {
950 $tmp = explode(
"_", $key);
952 $socialnetwork = $tmp[1];
953 $jsondata = $data[$key];
954 $json = json_decode($jsondata);
955 $stringtosearch = json_encode($socialnetwork).
':'.json_encode($json->$socialnetwork);
958 $where[] = $key.
" LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch)).
"%'";
959 $filters[] = $col.
" LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch)).
"%'";
962 $where[] = $key.
' = '.$data[$key];
963 $filters[] = $col.
' = '.$data[$key];
966 if (!empty($tablewithentity_cache[$tablename])) {
970 $sqlSelect .=
" WHERE " . implode(
' AND ', $where);
972 $resql = $this->db->query($sqlSelect);
974 $num_rows = $this->db->num_rows($resql);
975 if ($num_rows == 1) {
976 $res = $this->db->fetch_object($resql);
977 $lastinsertid = $res->rowid;
978 if ($is_table_category_link) {
979 $lastinsertid =
'linktable';
981 $last_insert_id_array[$tablename] = $lastinsertid;
982 } elseif ($num_rows > 1) {
983 $this->errors[$error][
'lib'] = $langs->trans(
'MultipleRecordFoundWithTheseFilters', implode(
', ', $filters));
984 $this->errors[$error][
'type'] =
'SQL';
991 $this->errors[$error][
'lib'] = $this->db->lasterror();
992 $this->errors[$error][
'type'] =
'SQL';
1001 $sqlSelect =
"SELECT rowid FROM " . $tablename;
1004 if (empty($keyfield)) {
1005 $keyfield =
'rowid';
1007 $sqlSelect .=
" WHERE ".$keyfield.
" = ".((int) $lastinsertid);
1009 if (!empty($tablewithentity_cache[$tablename])) {
1013 $resql = $this->db->query($sqlSelect);
1015 $res = $this->db->fetch_object($resql);
1016 if ($this->db->num_rows($resql) == 1) {
1025 $this->errors[$error][
'lib'] = $this->db->lasterror();
1026 $this->errors[$error][
'type'] =
'SQL';
1031 if (!empty($lastinsertid)) {
1033 if (in_array(
"socialnetworks", $listfields)) {
1034 $socialkey = array_search(
"socialnetworks", $listfields);
1035 $tmpsql = $listvalues[$socialkey];
1036 $listvalues[$socialkey] =
"'".$this->db->escape($tmpsql).
"'";
1040 $sqlstart =
"UPDATE " . $tablename;
1042 $data = array_combine($listfields, $listvalues);
1044 foreach ($data as $key => $val) {
1045 $set[] = $key.
" = ".$val;
1047 $sqlstart .=
" SET " . implode(
', ', $set) .
", import_key = '" . $this->db->escape($importid) .
"'";
1049 if (empty($keyfield)) {
1050 $keyfield =
'rowid';
1052 $sqlend =
" WHERE " . $keyfield .
" = ".((int) $lastinsertid);
1054 if ($is_table_category_link) {
1055 '@phan-var-force string[] $where';
1056 $sqlend =
" WHERE " . implode(
' AND ', $where);
1059 if (!empty($tablewithentity_cache[$tablename])) {
1063 $sql = $sqlstart . $sqlend;
1066 $resql = $this->db->query($sql);
1072 $this->errors[$error][
'lib'] = $this->db->lasterror();
1073 $this->errors[$error][
'type'] =
'SQL';
1080 if (!$error && !$updatedone) {
1082 if (in_array(
"socialnetworks", $listfields)) {
1083 $socialkey = array_search(
"socialnetworks", $listfields);
1084 $tmpsql = $listvalues[$socialkey];
1085 $listvalues[$socialkey] =
"'".$this->db->escape($tmpsql).
"'";
1089 $sqlstart =
"INSERT INTO " . $tablename .
"(" . implode(
", ", $listfields) .
", import_key";
1090 $sqlend =
") VALUES(" . implode(
', ', $listvalues) .
", '" . $this->db->escape($importid) .
"'";
1091 if (!empty($tablewithentity_cache[$tablename])) {
1092 $sqlstart .=
", entity";
1093 $sqlend .=
", " . $conf->entity;
1095 if (!empty($objimport->array_import_tables_creator[0][$alias])) {
1096 $sqlstart .=
", " . $objimport->array_import_tables_creator[0][$alias];
1097 $sqlend .=
", " . $user->id;
1099 $sql = $sqlstart . $sqlend .
")";
1104 $resql = $this->db->query($sql);
1106 if (!$is_table_category_link) {
1107 $last_insert_id_array[$tablename] = $this->db->last_insert_id($tablename);
1112 $this->errors[$error][
'lib'] = $this->db->lasterror();
1113 $this->errors[$error][
'type'] =
'SQL';