396 public function import_insert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys)
399 global $langs,
$conf, $user;
400 global $thirdparty_static;
401 global $tablewithentity_cache;
405 $this->errors = array();
406 $this->warnings = array();
413 $array_match_database_to_file = array_flip($array_match_file_to_database);
414 $sort_array_match_file_to_database = $array_match_file_to_database;
415 ksort($sort_array_match_file_to_database);
419 if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[1][
'val']))) {
421 $this->warnings[$warning][
'lib'] = $langs->trans(
'EmptyLine');
422 $this->warnings[$warning][
'type'] =
'EMPTY';
425 $last_insert_id_array = array();
429 foreach ($objimport->array_import_tables[0] as $alias => $tablename) {
432 $listfields = array();
433 $listvalues = array();
435 $errorforthistable = 0;
438 if (!isset($tablewithentity_cache[$tablename])) {
439 dol_syslog(
"Check if table " . $tablename .
" has an entity field");
440 $resql = $this->db->DDLDescTable($tablename,
'entity');
442 $obj = $this->db->fetch_object($resql);
444 $tablewithentity_cache[$tablename] = 1;
446 $tablewithentity_cache[$tablename] = 0;
456 $arrayfield = array();
457 foreach ($sort_array_match_file_to_database as $key => $val) {
458 $arrayfield[$val] = ($key);
465 foreach ($sort_array_match_file_to_database as $key => $val) {
466 $fieldalias = preg_replace(
'/\..*$/i',
'', $val);
467 $fieldname = preg_replace(
'/^.*\./i',
'', $val);
469 if ($alias != $fieldalias) {
473 if ($key <= $maxfields) {
476 if ($arrayrecord[($key)][
'type'] > 0) {
477 $newval = $arrayrecord[($key)][
'val'];
486 if (preg_match(
'/\*/', $objimport->array_import_fields[0][$val]) && ((string) $newval ==
'')) {
487 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorMissingMandatoryValue',
num2Alpha($key - 1));
488 $this->errors[$error][
'type'] =
'NOTNULL';
489 $errorforthistable++;
494 if (!empty($objimport->array_import_convertvalue[0][$val])) {
496 if ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeid'
497 || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromref'
498 || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeorlabel'
502 if (!is_numeric($newval) && $newval !=
'' && !preg_match(
'/^id:/i', $newval)) {
505 $newval = preg_replace(
'/^(id|ref):/i',
'', $newval);
508 if ($isidorref ==
'ref') {
509 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
510 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
511 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
512 if ($this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_'][$newval] !=
'') {
513 $newval = $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_'][$newval];
516 if (empty($resultload)) {
517 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method);
520 $classinstance =
new $class($this->db);
521 if ($class ==
'CGenericDic') {
522 $classinstance->element = $objimport->array_import_convertvalue[0][$val][
'element'];
523 $classinstance->table_element = $objimport->array_import_convertvalue[0][$val][
'table_element'];
527 $param_array = array(
'', $newval);
528 if ($class ==
'AccountingAccount') {
541 $param_array = array(
'', $newval, 0, $arrayrecord[0][
'val']);
544 $result = call_user_func_array(array($classinstance, $method), $param_array);
547 if (!($classinstance->id !=
'') && $result == -2) {
548 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorMultipleRecordFoundFromRef', $newval);
549 $this->errors[$error][
'type'] =
'FOREIGNKEY';
550 $errorforthistable++;
555 if (!($classinstance->id !=
'') && $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeorlabel') {
556 $param_array = array(
'',
'', $newval);
557 call_user_func_array(array($classinstance, $method), $param_array);
559 $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_'][$newval] = $classinstance->id;
562 if ($classinstance->id !=
'') {
563 $newval = $classinstance->id;
564 } elseif (! $error) {
565 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
567 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn', $key, $newval,
'code', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
568 } elseif (!empty($objimport->array_import_convertvalue[0][$val][
'element'])) {
570 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldRefNotIn', $key, $newval, $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'element']));
572 $this->errors[$error][
'lib'] =
'ErrorBadDefinitionOfImportProfile';
574 $this->errors[$error][
'type'] =
'FOREIGNKEY';
575 $errorforthistable++;
580 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeandlabel') {
582 if (!is_numeric($newval) && $newval !=
'' && !preg_match(
'/^id:/i', $newval)) {
585 $newval = preg_replace(
'/^(id|ref):/i',
'', $newval);
587 if ($isidorref ==
'ref') {
588 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
589 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
590 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
591 $codefromfield = $objimport->array_import_convertvalue[0][$val][
'codefromfield'];
592 $code = $arrayrecord[$arrayfield[$codefromfield]][
'val'];
593 if ($this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $code][$newval] !=
'') {
594 $newval = $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $code][$newval];
597 if (empty($resultload)) {
598 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method .
', code=' . $code);
601 $classinstance =
new $class($this->db);
603 $param_array = array(
'', $newval, $code);
604 call_user_func_array(array($classinstance, $method), $param_array);
605 $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $code][$newval] = $classinstance->id;
606 if ($classinstance->id > 0) {
607 $newval = $classinstance->id;
609 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
611 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn', $key, $newval,
'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
613 $this->errors[$error][
'lib'] =
'ErrorFieldValueNotIn';
615 $this->errors[$error][
'type'] =
'FOREIGNKEY';
616 $errorforthistable++;
621 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'zeroifnull') {
622 if (empty($newval)) {
625 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeunits' || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchscalefromcodeunits') {
626 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
627 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
628 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
629 $units = $objimport->array_import_convertvalue[0][$val][
'units'];
630 if ($this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $units][$newval] !=
'') {
631 $newval = $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $units][$newval];
634 if (empty($resultload)) {
635 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method .
', units=' . $units);
638 $classinstance =
new $class($this->db);
640 call_user_func_array(array($classinstance, $method), array(
'',
'', $newval, $units));
641 $scaleorid = (($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeunits') ? $classinstance->id : $classinstance->scale);
642 $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $units][$newval] = $scaleorid;
644 if ($classinstance->id > 0) {
645 $newval = $scaleorid ? $scaleorid : 0;
647 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
649 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn', $key, $newval,
'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
651 $this->errors[$error][
'lib'] =
'ErrorFieldValueNotIn';
653 $this->errors[$error][
'type'] =
'FOREIGNKEY';
654 $errorforthistable++;
658 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getcustomercodeifauto') {
659 if (strtolower($newval) ==
'auto') {
660 $this->thirdpartyobject->get_codeclient(
null, 0);
661 $newval = $this->thirdpartyobject->code_client;
664 if (empty($newval)) {
665 $arrayrecord[($key)][
'type'] = -1;
667 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getsuppliercodeifauto') {
668 if (strtolower($newval) ==
'auto') {
669 $this->thirdpartyobject->get_codefournisseur(
null, 1);
670 $newval = $this->thirdpartyobject->code_fournisseur;
673 if (empty($newval)) {
674 $arrayrecord[($key)][
'type'] = -1;
676 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getcustomeraccountancycodeifauto') {
677 if (strtolower($newval) ==
'auto') {
678 $this->thirdpartyobject->get_codecompta(
'customer');
679 $newval = $this->thirdpartyobject->code_compta_client;
682 if (empty($newval)) {
683 $arrayrecord[($key)][
'type'] = -1;
685 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getsupplieraccountancycodeifauto') {
686 if (strtolower($newval) ==
'auto') {
687 $this->thirdpartyobject->get_codecompta(
'supplier');
688 $newval = $this->thirdpartyobject->code_compta_fournisseur;
689 if (empty($newval)) {
690 $arrayrecord[($key)][
'type'] = -1;
694 if (empty($newval)) {
695 $arrayrecord[($key)][
'type'] = -1;
697 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getrefifauto') {
698 if (strtolower($newval) ==
'auto') {
701 $classModForNumber = $objimport->array_import_convertvalue[0][$val][
'class'];
702 $pathModForNumber = $objimport->array_import_convertvalue[0][$val][
'path'];
704 if (!empty($classModForNumber) && !empty($pathModForNumber) && is_readable(DOL_DOCUMENT_ROOT.$pathModForNumber)) {
705 require_once DOL_DOCUMENT_ROOT.$pathModForNumber;
706 $modForNumber =
new $classModForNumber();
707 '@phan-var-force ModeleNumRefMembers|ModeleNumRefCommandes|ModeleNumRefSuppliersInvoices|ModeleNumRefSuppliersOrders|ModeleNumRefProjects|ModeleNumRefTask|ModeleNumRefPropales $modForNumber';
711 if (!empty($objimport->array_import_convertvalue[0][$val][
'classobject'])) {
712 $pathForObject = $objimport->array_import_convertvalue[0][$val][
'pathobject'];
713 require_once DOL_DOCUMENT_ROOT.$pathForObject;
714 $tmpclassobject = $objimport->array_import_convertvalue[0][$val][
'classobject'];
715 $tmpobject =
new $tmpclassobject($this->db);
716 foreach ($arrayfield as $tmpkey => $tmpval) {
717 if (in_array($tmpkey, array(
't.date',
'c.date_commande'))) {
718 $tmpobject->date =
dol_stringtotime($arrayrecord[$arrayfield[$tmpkey]][
'val'], 1);
723 $defaultref = $modForNumber->getNextValue(
null, $tmpobject);
725 if (is_numeric($defaultref) && $defaultref <= 0) {
728 $newval = $defaultref;
730 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'compute') {
731 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
732 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
733 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
735 if (empty($resultload)) {
736 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method);
739 $classinstance =
new $class($this->db);
740 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, $key));
741 if (empty($classinstance->error) && empty($classinstance->errors)) {
744 $this->errors[$error][
'type'] =
'CLASSERROR';
745 $this->errors[$error][
'lib'] = implode(
747 array_merge([$classinstance->error], $classinstance->errors)
749 $errorforthistable++;
752 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'numeric') {
754 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'accountingaccount') {
756 $newval = rtrim(trim($newval),
"0");
758 $newval = trim($newval);
766 if (!empty($objimport->array_import_regex[0][$val]) && ($newval !=
'')) {
769 if (preg_match(
'/^(.+)@([^:]+)(:.+)?$/', $objimport->array_import_regex[0][$val], $reg)) {
772 $filter = !empty($reg[3]) ? substr($reg[3], 1) :
'';
774 $cachekey = $field .
'@' . $table;
775 if (!empty($filter)) {
776 $cachekey .=
':' . $filter;
780 if (!is_array($this->cachefieldtable[$cachekey])) {
781 $sql =
"SELECT " . $field .
" as aliasfield FROM " . $table;
782 if (!empty($filter)) {
783 $sql .=
' WHERE ' . $filter;
786 $resql = $this->db->query($sql);
788 $num = $this->db->num_rows($resql);
791 $obj = $this->db->fetch_object($resql);
793 $this->cachefieldtable[$cachekey][] = $obj->aliasfield;
803 if (!is_array($this->cachefieldtable[$cachekey]) || !in_array($newval, $this->cachefieldtable[$cachekey])) {
804 $tableforerror = $table;
805 if (!empty($filter)) {
806 $tableforerror .=
':' . $filter;
809 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorFieldValueNotIn', $key, $newval, $field, $tableforerror);
810 $this->errors[$error][
'type'] =
'FOREIGNKEY';
811 $errorforthistable++;
814 } elseif (!preg_match(
'/' . $objimport->array_import_regex[0][$val] .
'/i', $newval)) {
818 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorWrongValueForField', $key, $newval, $objimport->array_import_regex[0][$val]);
819 $this->errors[$error][
'type'] =
'REGEX';
820 $errorforthistable++;
829 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorHtmlInjectionForField', $key,
dol_trunc($newval, 100));
830 $this->errors[$error][
'type'] =
'HTMLINJECTION';
831 $errorforthistable++;
840 if (isModEnabled(
"socialnetworks") && strpos($fieldname,
"socialnetworks") !==
false) {
841 if (!in_array(
"socialnetworks", $listfields)) {
842 $listfields[] =
"socialnetworks";
843 $socialkey = array_search(
"socialnetworks", $listfields);
844 $listvalues[$socialkey] =
'';
846 if (!empty($newval) && $arrayrecord[($key)][
'type'] > 0) {
847 $socialkey = array_search(
"socialnetworks", $listfields);
848 $socialnetwork = explode(
"_", $fieldname)[1];
849 if (empty($listvalues[$socialkey]) || $listvalues[$socialkey] ==
"null") {
851 $json->$socialnetwork = $newval;
852 $listvalues[$socialkey] = json_encode($json);
854 $jsondata = $listvalues[$socialkey];
855 $json = json_decode($jsondata);
856 $json->$socialnetwork = $newval;
857 $listvalues[$socialkey] = json_encode($json);
861 $listfields[] = $fieldname;
864 if (empty($newval) && $arrayrecord[($key)][
'type'] < 0) {
865 $listvalues[] = ($newval ==
'0' ? (int) $newval :
"null");
866 } elseif (empty($newval) && $arrayrecord[($key)][
'type'] == 0) {
867 $listvalues[] =
"''";
869 $listvalues[] =
"'".$this->db->escape($newval).
"'";
879 if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0])) {
881 foreach ($objimport->array_import_fieldshidden[0] as $key => $val) {
882 if (!preg_match(
'/^' . preg_quote($alias,
'/') .
'\./', $key)) {
885 $keyfield = preg_replace(
'/^' . preg_quote($alias,
'/') .
'\./',
'', $key);
887 if (in_array($keyfield, $listfields)) {
889 } elseif ($val ==
'user->id') {
890 $listfields[] = $keyfield;
891 $listvalues[] = ((int) $user->id);
892 } elseif (preg_match(
'/^lastrowid-/', $val)) {
893 $tmp = explode(
'-', $val);
894 $lastinsertid = (isset($last_insert_id_array[$tmp[1]])) ? $last_insert_id_array[$tmp[1]] : 0;
895 $listfields[] = $keyfield;
896 $listvalues[] = (int) $lastinsertid;
898 } elseif (preg_match(
'/^const-/', $val)) {
899 $tmp = explode(
'-', $val, 2);
900 $listfields[] = $keyfield;
901 $listvalues[] =
"'".$this->db->escape($tmp[1]).
"'";
902 } elseif (preg_match(
'/^rule-/', $val)) {
904 $classinstance =
null;
905 if (!empty($objimport->array_import_convertvalue[0][$fieldname])) {
906 if ($objimport->array_import_convertvalue[0][$fieldname][
'rule'] ==
'compute') {
907 $file = (empty($objimport->array_import_convertvalue[0][$fieldname][
'classfile']) ? $objimport->array_import_convertvalue[0][$fieldname][
'file'] : $objimport->array_import_convertvalue[0][$fieldname][
'classfile']);
908 $class = $objimport->array_import_convertvalue[0][$fieldname][
'class'];
909 $method = $objimport->array_import_convertvalue[0][$fieldname][
'method'];
910 $type = $objimport->array_import_convertvalue[0][$fieldname][
'type'];
912 if (empty($resultload)) {
913 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method);
916 $classinstance =
new $class($this->db);
917 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, $key));
918 $fieldArr = explode(
'.', $fieldname);
919 if (count($fieldArr) > 0) {
920 $fieldname = $fieldArr[1];
924 $listfields[] = $fieldname;
925 if ($type ==
'int') {
926 $listvalues[] = (int) $res;
927 } elseif ($type ==
'double') {
928 $listvalues[] = (float) $res;
930 $listvalues[] =
"'".$this->db->escape($res).
"'";
933 $this->errors[$error][
'type'] =
'CLASSERROR';
934 if (is_object($classinstance)) {
935 $this->errors[$error][
'lib'] = implode(
937 array_merge([$classinstance->error], $classinstance->errors)
940 $this->errors[$error][
'lib']
941 =
"Unexpected rule ".$objimport->array_import_convertvalue[0][$fieldname][
'rule'];
944 $errorforthistable++;
949 $this->errors[$error][
'lib'] =
'Bad value of profile setup ' . $val .
' for array_import_fieldshidden';
950 $this->errors[$error][
'type'] =
'Import profile setup';
959 if (!$errorforthistable) {
961 if (!empty($listfields)) {
965 $is_table_category_link =
false;
967 if (strpos($tablename,
'_categorie_') !==
false) {
968 $is_table_category_link =
true;
972 if (!empty($updatekeys)) {
975 if (empty($lastinsertid)) {
976 $sqlSelect =
"SELECT ".$fname.
" FROM " . $tablename;
978 $data = array_combine($listfields, $listvalues);
982 '@phan-var string[] $where';
984 foreach ($updatekeys as $key) {
985 $col = $objimport->array_import_updatekeys[0][$key];
986 $key = preg_replace(
'/^.*\./i',
'', $key);
987 if (isModEnabled(
"socialnetworks") && strpos($key,
"socialnetworks") !==
false) {
988 $tmp = explode(
"_", $key);
990 $socialnetwork = $tmp[1];
991 $jsondata = $data[$key];
992 $json = json_decode($jsondata);
993 $stringtosearch = json_encode($socialnetwork).
':'.json_encode($json->$socialnetwork);
996 $where[] = $key.
" LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch)).
"%'";
997 $filters[] = $col.
" LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch)).
"%'";
1000 $where[] = $key.
' = '.$data[$key];
1001 $filters[] = $col.
' = '.$data[$key];
1004 if (!empty($tablewithentity_cache[$tablename])) {
1008 $sqlSelect .=
" WHERE " . implode(
' AND ', $where);
1010 $resql = $this->db->query($sqlSelect);
1012 $num_rows = $this->db->num_rows($resql);
1013 if ($num_rows == 1) {
1014 $res = $this->db->fetch_object($resql);
1015 $lastinsertid = $res->rowid;
1016 if ($is_table_category_link) {
1017 $lastinsertid =
'linktable';
1019 $last_insert_id_array[$tablename] = $lastinsertid;
1020 } elseif ($num_rows > 1) {
1021 $this->errors[$error][
'lib'] = $langs->trans(
'MultipleRecordFoundWithTheseFilters', implode(
', ', $filters));
1022 $this->errors[$error][
'type'] =
'SQL';
1029 $this->errors[$error][
'lib'] = $this->db->lasterror();
1030 $this->errors[$error][
'type'] =
'SQL';
1039 $sqlSelect =
"SELECT rowid FROM " . $tablename;
1042 if (empty($keyfield)) {
1043 $keyfield =
'rowid';
1045 $sqlSelect .=
" WHERE ".$keyfield.
" = ".((int) $lastinsertid);
1047 if (!empty($tablewithentity_cache[$tablename])) {
1051 $resql = $this->db->query($sqlSelect);
1053 $res = $this->db->fetch_object($resql);
1054 if ($this->db->num_rows($resql) == 1) {
1063 $this->errors[$error][
'lib'] = $this->db->lasterror();
1064 $this->errors[$error][
'type'] =
'SQL';
1069 if (!empty($lastinsertid)) {
1071 if (in_array(
"socialnetworks", $listfields)) {
1072 $socialkey = array_search(
"socialnetworks", $listfields);
1073 $tmpsql = $listvalues[$socialkey];
1074 $listvalues[$socialkey] =
"'".$this->db->escape($tmpsql).
"'";
1078 $sqlstart =
"UPDATE " . $tablename;
1080 $data = array_combine($listfields, $listvalues);
1082 foreach ($data as $key => $val) {
1083 $set[] = $key.
" = ".$val;
1085 $sqlstart .=
" SET " . implode(
', ', $set) .
", import_key = '" . $this->db->escape($importid) .
"'";
1087 if (empty($keyfield)) {
1088 $keyfield =
'rowid';
1090 $sqlend =
" WHERE " . $keyfield .
" = ".((int) $lastinsertid);
1092 if ($is_table_category_link) {
1093 '@phan-var-force string[] $where';
1094 $sqlend =
" WHERE " . implode(
' AND ', $where);
1097 if (!empty($tablewithentity_cache[$tablename])) {
1101 $sql = $sqlstart . $sqlend;
1104 $resql = $this->db->query($sql);
1110 $this->errors[$error][
'lib'] = $this->db->lasterror();
1111 $this->errors[$error][
'type'] =
'SQL';
1118 if (!$error && !$updatedone) {
1120 if (in_array(
"socialnetworks", $listfields)) {
1121 $socialkey = array_search(
"socialnetworks", $listfields);
1122 $tmpsql = $listvalues[$socialkey];
1123 $listvalues[$socialkey] =
"'".$this->db->escape($tmpsql).
"'";
1127 $sqlstart =
"INSERT INTO " . $tablename .
"(" . implode(
", ", $listfields) .
", import_key";
1128 $sqlend =
") VALUES(" . implode(
', ', $listvalues) .
", '" . $this->db->escape($importid) .
"'";
1129 if (!empty($tablewithentity_cache[$tablename])) {
1130 $sqlstart .=
", entity";
1131 $sqlend .=
", " .
$conf->entity;
1133 if (!empty($objimport->array_import_tables_creator[0][$alias])) {
1134 $sqlstart .=
", " . $objimport->array_import_tables_creator[0][$alias];
1135 $sqlend .=
", " . $user->id;
1137 $sql = $sqlstart . $sqlend .
")";
1142 $resql = $this->db->query($sql);
1144 if (!$is_table_category_link) {
1145 $last_insert_id_array[$tablename] = $this->db->last_insert_id($tablename);
1150 $this->errors[$error][
'lib'] = $this->db->lasterror();
1151 $this->errors[$error][
'type'] =
'SQL';