402 public function import_insert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys)
405 global $langs,
$conf, $user;
406 global $thirdparty_static;
407 global $tablewithentity_cache;
411 $this->errors = array();
412 $this->warnings = array();
419 $array_match_database_to_file = array_flip($array_match_file_to_database);
420 $sort_array_match_file_to_database = $array_match_file_to_database;
421 ksort($sort_array_match_file_to_database);
425 if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[1][
'val']))) {
427 $this->warnings[$warning][
'lib'] = $langs->trans(
'EmptyLine');
428 $this->warnings[$warning][
'type'] =
'EMPTY';
431 $last_insert_id_array = array();
435 foreach ($objimport->array_import_tables[0] as $alias => $tablename) {
438 $listfields = array();
439 $listvalues = array();
441 $errorforthistable = 0;
444 if (!isset($tablewithentity_cache[$tablename])) {
445 dol_syslog(
"Check if table " . $tablename .
" has an entity field");
446 $resql = $this->db->DDLDescTable($tablename,
'entity');
448 $obj = $this->db->fetch_object($resql);
450 $tablewithentity_cache[$tablename] = 1;
452 $tablewithentity_cache[$tablename] = 0;
462 $arrayfield = array();
463 foreach ($sort_array_match_file_to_database as $key => $val) {
464 $arrayfield[$val] = ($key);
471 foreach ($sort_array_match_file_to_database as $key => $val) {
472 $fieldalias = preg_replace(
'/\..*$/i',
'', $val);
473 $fieldname = preg_replace(
'/^.*\./i',
'', $val);
475 if ($alias != $fieldalias) {
479 if ($key <= $maxfields) {
482 if ($arrayrecord[($key)][
'type'] > 0) {
483 $newval = $arrayrecord[($key)][
'val'];
492 if (preg_match(
'/\*/', $objimport->array_import_fields[0][$val]) && ((string) $newval ==
'')) {
493 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorMissingMandatoryValue',
num2Alpha($key - 1));
494 $this->errors[$error][
'type'] =
'NOTNULL';
495 $errorforthistable++;
500 if (!empty($objimport->array_import_convertvalue[0][$val])) {
502 if ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeid'
503 || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromref'
504 || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeorlabel'
508 if (!is_numeric($newval) && $newval !=
'' && !preg_match(
'/^id:/i', $newval)) {
511 $newval = preg_replace(
'/^(id|ref):/i',
'', $newval);
514 if ($isidorref ==
'ref') {
515 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
516 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
517 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
518 if ($this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_'][$newval] !=
'') {
519 $newval = $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_'][$newval];
522 if (empty($resultload)) {
523 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method);
526 $classinstance =
new $class($this->db);
527 if ($class ==
'CGenericDic') {
528 $classinstance->element = $objimport->array_import_convertvalue[0][$val][
'element'];
529 $classinstance->table_element = $objimport->array_import_convertvalue[0][$val][
'table_element'];
533 $param_array = array(
'', $newval);
534 if ($class ==
'AccountingAccount') {
547 $param_array = array(
'', $newval, 0, $arrayrecord[0][
'val']);
550 $result = call_user_func_array(array($classinstance, $method), $param_array);
553 if (!($classinstance->id !=
'') && $result == -2) {
554 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorMultipleRecordFoundFromRef', $newval);
555 $this->errors[$error][
'type'] =
'FOREIGNKEY';
556 $errorforthistable++;
561 if (!($classinstance->id !=
'') && $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeorlabel') {
562 $param_array = array(
'',
'', $newval);
563 call_user_func_array(array($classinstance, $method), $param_array);
565 $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_'][$newval] = $classinstance->id;
568 if ($classinstance->id !=
'') {
569 $newval = $classinstance->id;
570 } elseif (! $error) {
571 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
573 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn', $key, $newval,
'code', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
574 } elseif (!empty($objimport->array_import_convertvalue[0][$val][
'element'])) {
576 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldRefNotIn', $key, $newval, $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'element']));
578 $this->errors[$error][
'lib'] =
'ErrorBadDefinitionOfImportProfile';
580 $this->errors[$error][
'type'] =
'FOREIGNKEY';
581 $errorforthistable++;
586 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeandlabel') {
588 if (!is_numeric($newval) && $newval !=
'' && !preg_match(
'/^id:/i', $newval)) {
591 $newval = preg_replace(
'/^(id|ref):/i',
'', $newval);
593 if ($isidorref ==
'ref') {
594 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
595 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
596 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
597 $codefromfield = $objimport->array_import_convertvalue[0][$val][
'codefromfield'];
598 $code = $arrayrecord[$arrayfield[$codefromfield]][
'val'];
599 if ($this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $code][$newval] !=
'') {
600 $newval = $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $code][$newval];
603 if (empty($resultload)) {
604 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method .
', code=' . $code);
607 $classinstance =
new $class($this->db);
609 $param_array = array(
'', $newval, $code);
610 call_user_func_array(array($classinstance, $method), $param_array);
611 $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $code][$newval] = $classinstance->id;
612 if ($classinstance->id > 0) {
613 $newval = $classinstance->id;
615 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
617 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn', $key, $newval,
'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
619 $this->errors[$error][
'lib'] =
'ErrorFieldValueNotIn';
621 $this->errors[$error][
'type'] =
'FOREIGNKEY';
622 $errorforthistable++;
627 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'zeroifnull') {
628 if (empty($newval)) {
631 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeunits' || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchscalefromcodeunits') {
632 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
633 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
634 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
635 $units = $objimport->array_import_convertvalue[0][$val][
'units'];
636 if ($this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $units][$newval] !=
'') {
637 $newval = $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $units][$newval];
640 if (empty($resultload)) {
641 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method .
', units=' . $units);
644 $classinstance =
new $class($this->db);
646 call_user_func_array(array($classinstance, $method), array(
'',
'', $newval, $units));
647 $scaleorid = (($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeunits') ? $classinstance->id : $classinstance->scale);
648 $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $units][$newval] = $scaleorid;
650 if ($classinstance->id > 0) {
651 $newval = $scaleorid ? $scaleorid : 0;
653 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
655 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn', $key, $newval,
'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
657 $this->errors[$error][
'lib'] =
'ErrorFieldValueNotIn';
659 $this->errors[$error][
'type'] =
'FOREIGNKEY';
660 $errorforthistable++;
664 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getcustomercodeifauto') {
665 if (strtolower($newval) ==
'auto') {
666 $this->thirdpartyobject->get_codeclient(
null, 0);
667 $newval = $this->thirdpartyobject->code_client;
670 if (empty($newval)) {
671 $arrayrecord[($key)][
'type'] = -1;
673 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getsuppliercodeifauto') {
674 if (strtolower($newval) ==
'auto') {
675 $this->thirdpartyobject->get_codefournisseur(
null, 1);
676 $newval = $this->thirdpartyobject->code_fournisseur;
679 if (empty($newval)) {
680 $arrayrecord[($key)][
'type'] = -1;
682 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getcustomeraccountancycodeifauto') {
683 if (strtolower($newval) ==
'auto') {
684 $this->thirdpartyobject->get_codecompta(
'customer');
685 $newval = $this->thirdpartyobject->code_compta_client;
688 if (empty($newval)) {
689 $arrayrecord[($key)][
'type'] = -1;
691 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getsupplieraccountancycodeifauto') {
692 if (strtolower($newval) ==
'auto') {
693 $this->thirdpartyobject->get_codecompta(
'supplier');
694 $newval = $this->thirdpartyobject->code_compta_fournisseur;
695 if (empty($newval)) {
696 $arrayrecord[($key)][
'type'] = -1;
700 if (empty($newval)) {
701 $arrayrecord[($key)][
'type'] = -1;
703 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getrefifauto') {
704 if (strtolower($newval) ==
'auto') {
707 $classModForNumber = $objimport->array_import_convertvalue[0][$val][
'class'];
708 $pathModForNumber = $objimport->array_import_convertvalue[0][$val][
'path'];
710 if (!empty($classModForNumber) && !empty($pathModForNumber) && is_readable(DOL_DOCUMENT_ROOT.$pathModForNumber)) {
711 require_once DOL_DOCUMENT_ROOT.$pathModForNumber;
712 $modForNumber =
new $classModForNumber();
713 '@phan-var-force ModeleNumRefMembers|ModeleNumRefCommandes|ModeleNumRefSuppliersInvoices|ModeleNumRefSuppliersOrders|ModeleNumRefProjects|ModeleNumRefTask|ModeleNumRefPropales $modForNumber';
717 if (!empty($objimport->array_import_convertvalue[0][$val][
'classobject'])) {
718 $pathForObject = $objimport->array_import_convertvalue[0][$val][
'pathobject'];
719 require_once DOL_DOCUMENT_ROOT.$pathForObject;
720 $tmpclassobject = $objimport->array_import_convertvalue[0][$val][
'classobject'];
721 $tmpobject =
new $tmpclassobject($this->db);
722 foreach ($arrayfield as $tmpkey => $tmpval) {
723 if (in_array($tmpkey, array(
't.date',
'c.date_commande'))) {
724 $tmpobject->date =
dol_stringtotime($arrayrecord[$arrayfield[$tmpkey]][
'val'], 1);
729 $defaultref = $modForNumber->getNextValue(
null, $tmpobject);
731 if (is_numeric($defaultref) && $defaultref <= 0) {
734 $newval = $defaultref;
736 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'compute') {
737 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
738 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
739 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
741 if (empty($resultload)) {
742 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method);
745 $classinstance =
new $class($this->db);
746 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, $key));
747 if (empty($classinstance->error) && empty($classinstance->errors)) {
750 $this->errors[$error][
'type'] =
'CLASSERROR';
751 $this->errors[$error][
'lib'] = implode(
753 array_merge([$classinstance->error], $classinstance->errors)
755 $errorforthistable++;
758 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'numeric') {
760 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'accountingaccount') {
762 $newval = rtrim(trim($newval),
"0");
764 $newval = trim($newval);
772 if (!empty($objimport->array_import_regex[0][$val]) && ($newval !=
'')) {
775 if (preg_match(
'/^(.+)@([^:]+)(:.+)?$/', $objimport->array_import_regex[0][$val], $reg)) {
778 $filter = !empty($reg[3]) ? substr($reg[3], 1) :
'';
780 $cachekey = $field .
'@' . $table;
781 if (!empty($filter)) {
782 $cachekey .=
':' . $filter;
786 if (!is_array($this->cachefieldtable[$cachekey])) {
787 $sql =
"SELECT " . $field .
" as aliasfield FROM " . $table;
788 if (!empty($filter)) {
789 $sql .=
' WHERE ' . $filter;
793 $resql = $this->db->query($sql);
795 $num = $this->db->num_rows($resql);
798 $obj = $this->db->fetch_object($resql);
800 $this->cachefieldtable[$cachekey][] = $obj->aliasfield;
810 if (!is_array($this->cachefieldtable[$cachekey]) || !in_array($newval, $this->cachefieldtable[$cachekey])) {
811 $tableforerror = $table;
812 if (!empty($filter)) {
813 $tableforerror .=
':' . $filter;
816 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorFieldValueNotIn', $key, $newval, $field, $tableforerror);
817 $this->errors[$error][
'type'] =
'FOREIGNKEY';
818 $errorforthistable++;
821 } elseif (!preg_match(
'/' . $objimport->array_import_regex[0][$val] .
'/i', $newval)) {
825 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorWrongValueForField', $key, $newval, $objimport->array_import_regex[0][$val]);
826 $this->errors[$error][
'type'] =
'REGEX';
827 $errorforthistable++;
836 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorHtmlInjectionForField', $key,
dol_trunc($newval, 100));
837 $this->errors[$error][
'type'] =
'HTMLINJECTION';
838 $errorforthistable++;
847 if (isModEnabled(
"socialnetworks") && strpos($fieldname,
"socialnetworks") !==
false) {
848 if (!in_array(
"socialnetworks", $listfields)) {
849 $listfields[] =
"socialnetworks";
850 $socialkey = array_search(
"socialnetworks", $listfields);
851 $listvalues[$socialkey] =
'';
853 if (!empty($newval) && $arrayrecord[($key)][
'type'] > 0) {
854 $socialkey = array_search(
"socialnetworks", $listfields);
855 $socialnetwork = explode(
"_", $fieldname)[1];
856 if (empty($listvalues[$socialkey]) || $listvalues[$socialkey] ==
"null") {
858 $json->$socialnetwork = $newval;
859 $listvalues[$socialkey] = json_encode($json);
861 $jsondata = $listvalues[$socialkey];
862 $json = json_decode($jsondata);
863 $json->$socialnetwork = $newval;
864 $listvalues[$socialkey] = json_encode($json);
868 $listfields[] = $fieldname;
871 if (empty($newval) && $arrayrecord[($key)][
'type'] < 0) {
872 $listvalues[] = ($newval ==
'0' ? (int) $newval :
"null");
873 } elseif (empty($newval) && $arrayrecord[($key)][
'type'] == 0) {
874 $listvalues[] =
"''";
876 $listvalues[] =
"'".$this->db->escape($newval).
"'";
886 if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0])) {
888 foreach ($objimport->array_import_fieldshidden[0] as $key => $val) {
889 if (!preg_match(
'/^' . preg_quote($alias,
'/') .
'\./', $key)) {
892 $keyfieldcache = preg_replace(
'/^' . preg_quote($alias,
'/') .
'\./',
'', $key);
893 if (in_array($keyfieldcache, $listfields)) {
895 } elseif ($val ==
'user->id') {
896 $listfields[] = $keyfieldcache;
897 $listvalues[] = ((int) $user->id);
898 } elseif (preg_match(
'/^lastrowid-/', $val)) {
899 $tmp = explode(
'-', $val);
900 $lastinsertid = (isset($last_insert_id_array[$tmp[1]])) ? $last_insert_id_array[$tmp[1]] : 0;
901 $listfields[] = $keyfieldcache;
902 $keyfield = $keyfieldcache;
903 $listvalues[] = (int) $lastinsertid;
905 } elseif (preg_match(
'/^const-/', $val)) {
906 $tmp = explode(
'-', $val, 2);
907 $listfields[] = $keyfieldcache;
908 $listvalues[] =
"'".$this->db->escape($tmp[1]).
"'";
909 } elseif (preg_match(
'/^rule-/', $val)) {
911 $classinstance =
null;
912 if (!empty($objimport->array_import_convertvalue[0][$fieldname])) {
913 if ($objimport->array_import_convertvalue[0][$fieldname][
'rule'] ==
'compute') {
914 $file = (empty($objimport->array_import_convertvalue[0][$fieldname][
'classfile']) ? $objimport->array_import_convertvalue[0][$fieldname][
'file'] : $objimport->array_import_convertvalue[0][$fieldname][
'classfile']);
915 $class = $objimport->array_import_convertvalue[0][$fieldname][
'class'];
916 $method = $objimport->array_import_convertvalue[0][$fieldname][
'method'];
917 $type = $objimport->array_import_convertvalue[0][$fieldname][
'type'];
919 if (empty($resultload)) {
920 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method);
923 $classinstance =
new $class($this->db);
924 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, $key));
925 $fieldArr = explode(
'.', $fieldname);
926 if (count($fieldArr) > 0) {
927 $fieldname = $fieldArr[1];
931 $listfields[] = $fieldname;
932 if ($type ==
'int') {
933 $listvalues[] = (int) $res;
934 } elseif ($type ==
'double') {
935 $listvalues[] = (float) $res;
937 $listvalues[] =
"'".$this->db->escape($res).
"'";
940 $this->errors[$error][
'type'] =
'CLASSERROR';
941 if (is_object($classinstance)) {
942 $this->errors[$error][
'lib'] = implode(
944 array_merge([$classinstance->error], $classinstance->errors)
947 $this->errors[$error][
'lib']
948 =
"Unexpected rule ".$objimport->array_import_convertvalue[0][$fieldname][
'rule'];
951 $errorforthistable++;
956 $this->errors[$error][
'lib'] =
'Bad value of profile setup ' . $val .
' for array_import_fieldshidden';
957 $this->errors[$error][
'type'] =
'Import profile setup';
966 if (!$errorforthistable) {
968 if (!empty($listfields)) {
972 $is_table_category_link =
false;
974 if (strpos($tablename,
'_categorie_') !==
false) {
975 $is_table_category_link =
true;
979 if (!empty($updatekeys)) {
982 if (empty($lastinsertid)) {
983 $sqlSelect =
"SELECT ".$fname.
" FROM " . $tablename;
985 $data = array_combine($listfields, $listvalues);
989 '@phan-var string[] $where';
991 foreach ($updatekeys as $key) {
992 $col = $objimport->array_import_updatekeys[0][$key];
993 $key = preg_replace(
'/^.*\./i',
'', $key);
994 if (isModEnabled(
"socialnetworks") && strpos($key,
"socialnetworks") !==
false) {
995 $tmp = explode(
"_", $key);
997 $socialnetwork = $tmp[1];
998 $jsondata = $data[$key];
999 $json = json_decode($jsondata);
1000 $stringtosearch = json_encode($socialnetwork).
':'.json_encode($json->$socialnetwork);
1003 $where[] = $key.
" LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch)).
"%'";
1004 $filters[] = $col.
" LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch)).
"%'";
1007 $where[] = $key.
' = '.$data[$key];
1008 $filters[] = $col.
' = '.$data[$key];
1011 if (!empty($tablewithentity_cache[$tablename])) {
1015 $sqlSelect .=
" WHERE " . implode(
' AND ', $where);
1017 $resql = $this->db->query($sqlSelect);
1019 $num_rows = $this->db->num_rows($resql);
1020 if ($num_rows == 1) {
1021 $res = $this->db->fetch_object($resql);
1022 $lastinsertid = $res->rowid;
1023 $keyfield =
'rowid';
1024 if ($is_table_category_link) {
1025 $lastinsertid =
'linktable';
1027 $last_insert_id_array[$tablename] = $lastinsertid;
1028 } elseif ($num_rows > 1) {
1029 $this->errors[$error][
'lib'] = $langs->trans(
'MultipleRecordFoundWithTheseFilters', implode(
', ', $filters));
1030 $this->errors[$error][
'type'] =
'SQL';
1037 $this->errors[$error][
'lib'] = $this->db->lasterror();
1038 $this->errors[$error][
'type'] =
'SQL';
1047 $sqlSelect =
"SELECT rowid FROM " . $tablename;
1048 if (empty($keyfield)) {
1049 $keyfield =
'rowid';
1052 $sqlSelect .=
" WHERE ".$keyfield.
" = ".((int) $lastinsertid);
1054 if (!empty($tablewithentity_cache[$tablename])) {
1058 $resql = $this->db->query($sqlSelect);
1060 $res = $this->db->fetch_object($resql);
1061 if ($this->db->num_rows($resql) == 1) {
1070 $this->errors[$error][
'lib'] = $this->db->lasterror();
1071 $this->errors[$error][
'type'] =
'SQL';
1076 if (!empty($lastinsertid)) {
1078 if (in_array(
"socialnetworks", $listfields)) {
1079 $socialkey = array_search(
"socialnetworks", $listfields);
1080 $tmpsql = $listvalues[$socialkey];
1081 $listvalues[$socialkey] =
"'".$this->db->escape($tmpsql).
"'";
1085 $sqlstart =
"UPDATE " . $tablename;
1087 $data = array_combine($listfields, $listvalues);
1089 foreach ($data as $key => $val) {
1090 $set[] = $key.
" = ".$val;
1092 $sqlstart .=
" SET " . implode(
', ', $set) .
", import_key = '" . $this->db->escape($importid) .
"'";
1093 if (empty($keyfield)) {
1094 $keyfield =
'rowid';
1097 $sqlend =
" WHERE " . $keyfield .
" = ".((int) $lastinsertid);
1099 if ($is_table_category_link) {
1100 '@phan-var-force string[] $where';
1101 $sqlend =
" WHERE " . implode(
' AND ', $where);
1104 if (!empty($tablewithentity_cache[$tablename])) {
1108 $sql = $sqlstart . $sqlend;
1111 $resql = $this->db->query($sql);
1117 $this->errors[$error][
'lib'] = $this->db->lasterror();
1118 $this->errors[$error][
'type'] =
'SQL';
1125 if (!$error && !$updatedone) {
1127 if (in_array(
"socialnetworks", $listfields)) {
1128 $socialkey = array_search(
"socialnetworks", $listfields);
1129 $tmpsql = $listvalues[$socialkey];
1130 $listvalues[$socialkey] =
"'".$this->db->escape($tmpsql).
"'";
1134 $sqlstart =
"INSERT INTO " . $tablename .
"(" . implode(
", ", $listfields) .
", import_key";
1135 $sqlend =
") VALUES(" . implode(
', ', $listvalues) .
", '" . $this->db->escape($importid) .
"'";
1136 if (!empty($tablewithentity_cache[$tablename])) {
1137 $sqlstart .=
", entity";
1138 $sqlend .=
", " .
$conf->entity;
1140 if (!empty($objimport->array_import_tables_creator[0][$alias])) {
1141 $sqlstart .=
", " . $objimport->array_import_tables_creator[0][$alias];
1142 $sqlend .=
", " . $user->id;
1144 $sql = $sqlstart . $sqlend .
")";
1149 $resql = $this->db->query($sql);
1151 if (!$is_table_category_link) {
1152 $last_insert_id_array[$tablename] = $this->db->last_insert_id($tablename);
1157 $this->errors[$error][
'lib'] = $this->db->lasterror();
1158 $this->errors[$error][
'type'] =
'SQL';