389 public function import_insert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys)
392 global $langs, $conf, $user;
393 global $thirdparty_static;
394 global $tablewithentity_cache;
398 $this->errors = array();
399 $this->warnings = array();
406 $array_match_database_to_file = array_flip($array_match_file_to_database);
407 $sort_array_match_file_to_database = $array_match_file_to_database;
408 ksort($sort_array_match_file_to_database);
412 if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[1][
'val']))) {
414 $this->warnings[$warning][
'lib'] = $langs->trans(
'EmptyLine');
415 $this->warnings[$warning][
'type'] =
'EMPTY';
418 $last_insert_id_array = array();
422 foreach ($objimport->array_import_tables[0] as $alias => $tablename) {
425 $listfields = array();
426 $listvalues = array();
428 $errorforthistable = 0;
431 if (!isset($tablewithentity_cache[$tablename])) {
432 dol_syslog(
"Check if table " . $tablename .
" has an entity field");
433 $resql = $this->db->DDLDescTable($tablename,
'entity');
435 $obj = $this->db->fetch_object($resql);
437 $tablewithentity_cache[$tablename] = 1;
439 $tablewithentity_cache[$tablename] = 0;
449 $arrayfield = array();
450 foreach ($sort_array_match_file_to_database as $key => $val) {
451 $arrayfield[$val] = ($key);
458 foreach ($sort_array_match_file_to_database as $key => $val) {
459 $fieldalias = preg_replace(
'/\..*$/i',
'', $val);
460 $fieldname = preg_replace(
'/^.*\./i',
'', $val);
462 if ($alias != $fieldalias) {
466 if ($key <= $maxfields) {
469 if ($arrayrecord[($key)][
'type'] > 0) {
470 $newval = $arrayrecord[($key)][
'val'];
479 if (preg_match(
'/\*/', $objimport->array_import_fields[0][$val]) && ((string) $newval ==
'')) {
480 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorMissingMandatoryValue',
num2Alpha($key - 1));
481 $this->errors[$error][
'type'] =
'NOTNULL';
482 $errorforthistable++;
487 if (!empty($objimport->array_import_convertvalue[0][$val])) {
489 if ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeid'
490 || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromref'
491 || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeorlabel'
495 if (!is_numeric($newval) && $newval !=
'' && !preg_match(
'/^id:/i', $newval)) {
498 $newval = preg_replace(
'/^(id|ref):/i',
'', $newval);
501 if ($isidorref ==
'ref') {
502 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
503 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
504 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
505 if ($this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_'][$newval] !=
'') {
506 $newval = $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_'][$newval];
509 if (empty($resultload)) {
510 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method);
513 $classinstance =
new $class($this->db);
514 if ($class ==
'CGenericDic') {
515 $classinstance->element = $objimport->array_import_convertvalue[0][$val][
'element'];
516 $classinstance->table_element = $objimport->array_import_convertvalue[0][$val][
'table_element'];
520 $param_array = array(
'', $newval);
521 if ($class ==
'AccountingAccount') {
534 $param_array = array(
'', $newval, 0, $arrayrecord[0][
'val']);
537 $result = call_user_func_array(array($classinstance, $method), $param_array);
540 if (!($classinstance->id !=
'') && $result == -2) {
541 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorMultipleRecordFoundFromRef', $newval);
542 $this->errors[$error][
'type'] =
'FOREIGNKEY';
543 $errorforthistable++;
548 if (!($classinstance->id !=
'') && $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeorlabel') {
549 $param_array = array(
'',
'', $newval);
550 call_user_func_array(array($classinstance, $method), $param_array);
552 $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_'][$newval] = $classinstance->id;
555 if ($classinstance->id !=
'') {
556 $newval = $classinstance->id;
557 } elseif (! $error) {
558 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
560 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn', $key, $newval,
'code', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
561 } elseif (!empty($objimport->array_import_convertvalue[0][$val][
'element'])) {
563 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldRefNotIn', $key, $newval, $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'element']));
565 $this->errors[$error][
'lib'] =
'ErrorBadDefinitionOfImportProfile';
567 $this->errors[$error][
'type'] =
'FOREIGNKEY';
568 $errorforthistable++;
573 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeandlabel') {
575 if (!is_numeric($newval) && $newval !=
'' && !preg_match(
'/^id:/i', $newval)) {
578 $newval = preg_replace(
'/^(id|ref):/i',
'', $newval);
580 if ($isidorref ==
'ref') {
581 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
582 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
583 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
584 $codefromfield = $objimport->array_import_convertvalue[0][$val][
'codefromfield'];
585 $code = $arrayrecord[$arrayfield[$codefromfield]][
'val'];
586 if ($this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $code][$newval] !=
'') {
587 $newval = $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $code][$newval];
590 if (empty($resultload)) {
591 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method .
', code=' . $code);
594 $classinstance =
new $class($this->db);
596 $param_array = array(
'', $newval, $code);
597 call_user_func_array(array($classinstance, $method), $param_array);
598 $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $code][$newval] = $classinstance->id;
599 if ($classinstance->id > 0) {
600 $newval = $classinstance->id;
602 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
604 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn', $key, $newval,
'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
606 $this->errors[$error][
'lib'] =
'ErrorFieldValueNotIn';
608 $this->errors[$error][
'type'] =
'FOREIGNKEY';
609 $errorforthistable++;
614 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'zeroifnull') {
615 if (empty($newval)) {
618 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeunits' || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchscalefromcodeunits') {
619 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
620 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
621 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
622 $units = $objimport->array_import_convertvalue[0][$val][
'units'];
623 if ($this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $units][$newval] !=
'') {
624 $newval = $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $units][$newval];
627 if (empty($resultload)) {
628 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method .
', units=' . $units);
631 $classinstance =
new $class($this->db);
633 call_user_func_array(array($classinstance, $method), array(
'',
'', $newval, $units));
634 $scaleorid = (($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeunits') ? $classinstance->id : $classinstance->scale);
635 $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $units][$newval] = $scaleorid;
637 if ($classinstance->id > 0) {
638 $newval = $scaleorid ? $scaleorid : 0;
640 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
642 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn', $key, $newval,
'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
644 $this->errors[$error][
'lib'] =
'ErrorFieldValueNotIn';
646 $this->errors[$error][
'type'] =
'FOREIGNKEY';
647 $errorforthistable++;
651 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getcustomercodeifauto') {
652 if (strtolower($newval) ==
'auto') {
653 $this->thirdpartyobject->get_codeclient(
null, 0);
654 $newval = $this->thirdpartyobject->code_client;
657 if (empty($newval)) {
658 $arrayrecord[($key)][
'type'] = -1;
660 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getsuppliercodeifauto') {
661 if (strtolower($newval) ==
'auto') {
662 $this->thirdpartyobject->get_codefournisseur(
null, 1);
663 $newval = $this->thirdpartyobject->code_fournisseur;
666 if (empty($newval)) {
667 $arrayrecord[($key)][
'type'] = -1;
669 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getcustomeraccountancycodeifauto') {
670 if (strtolower($newval) ==
'auto') {
671 $this->thirdpartyobject->get_codecompta(
'customer');
672 $newval = $this->thirdpartyobject->code_compta_client;
675 if (empty($newval)) {
676 $arrayrecord[($key)][
'type'] = -1;
678 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getsupplieraccountancycodeifauto') {
679 if (strtolower($newval) ==
'auto') {
680 $this->thirdpartyobject->get_codecompta(
'supplier');
681 $newval = $this->thirdpartyobject->code_compta_fournisseur;
682 if (empty($newval)) {
683 $arrayrecord[($key)][
'type'] = -1;
687 if (empty($newval)) {
688 $arrayrecord[($key)][
'type'] = -1;
690 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getrefifauto') {
691 if (strtolower($newval) ==
'auto') {
694 $classModForNumber = $objimport->array_import_convertvalue[0][$val][
'class'];
695 $pathModForNumber = $objimport->array_import_convertvalue[0][$val][
'path'];
697 if (!empty($classModForNumber) && !empty($pathModForNumber) && is_readable(DOL_DOCUMENT_ROOT.$pathModForNumber)) {
698 require_once DOL_DOCUMENT_ROOT.$pathModForNumber;
699 $modForNumber =
new $classModForNumber();
700 '@phan-var-force ModeleNumRefMembers|ModeleNumRefCommandes|ModeleNumRefSuppliersInvoices|ModeleNumRefSuppliersOrders|ModeleNumRefProjects|ModeleNumRefTask|ModeleNumRefPropales $modForNumber';
704 if (!empty($objimport->array_import_convertvalue[0][$val][
'classobject'])) {
705 $pathForObject = $objimport->array_import_convertvalue[0][$val][
'pathobject'];
706 require_once DOL_DOCUMENT_ROOT.$pathForObject;
707 $tmpclassobject = $objimport->array_import_convertvalue[0][$val][
'classobject'];
708 $tmpobject =
new $tmpclassobject($this->db);
709 foreach ($arrayfield as $tmpkey => $tmpval) {
710 if (in_array($tmpkey, array(
't.date',
'c.date_commande'))) {
711 $tmpobject->date =
dol_stringtotime($arrayrecord[$arrayfield[$tmpkey]][
'val'], 1);
716 $defaultref = $modForNumber->getNextValue(
null, $tmpobject);
718 if (is_numeric($defaultref) && $defaultref <= 0) {
721 $newval = $defaultref;
723 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'compute') {
724 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
725 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
726 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
728 if (empty($resultload)) {
729 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method);
732 $classinstance =
new $class($this->db);
733 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, $key));
734 if (empty($classinstance->error) && empty($classinstance->errors)) {
737 $this->errors[$error][
'type'] =
'CLASSERROR';
738 $this->errors[$error][
'lib'] = implode(
740 array_merge([$classinstance->error], $classinstance->errors)
742 $errorforthistable++;
745 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'numeric') {
747 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'accountingaccount') {
749 $newval = rtrim(trim($newval),
"0");
751 $newval = trim($newval);
759 if (!empty($objimport->array_import_regex[0][$val]) && ($newval !=
'')) {
762 if (preg_match(
'/^(.+)@([^:]+)(:.+)?$/', $objimport->array_import_regex[0][$val], $reg)) {
765 $filter = !empty($reg[3]) ? substr($reg[3], 1) :
'';
767 $cachekey = $field .
'@' . $table;
768 if (!empty($filter)) {
769 $cachekey .=
':' . $filter;
773 if (!is_array($this->cachefieldtable[$cachekey])) {
774 $sql =
"SELECT " . $field .
" as aliasfield FROM " . $table;
775 if (!empty($filter)) {
776 $sql .=
' WHERE ' . $filter;
779 $resql = $this->db->query($sql);
781 $num = $this->db->num_rows($resql);
784 $obj = $this->db->fetch_object($resql);
786 $this->cachefieldtable[$cachekey][] = $obj->aliasfield;
796 if (!is_array($this->cachefieldtable[$cachekey]) || !in_array($newval, $this->cachefieldtable[$cachekey])) {
797 $tableforerror = $table;
798 if (!empty($filter)) {
799 $tableforerror .=
':' . $filter;
802 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorFieldValueNotIn', $key, $newval, $field, $tableforerror);
803 $this->errors[$error][
'type'] =
'FOREIGNKEY';
804 $errorforthistable++;
807 } elseif (!preg_match(
'/' . $objimport->array_import_regex[0][$val] .
'/i', $newval)) {
811 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorWrongValueForField', $key, $newval, $objimport->array_import_regex[0][$val]);
812 $this->errors[$error][
'type'] =
'REGEX';
813 $errorforthistable++;
822 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorHtmlInjectionForField', $key,
dol_trunc($newval, 100));
823 $this->errors[$error][
'type'] =
'HTMLINJECTION';
824 $errorforthistable++;
833 if (isModEnabled(
"socialnetworks") && strpos($fieldname,
"socialnetworks") !==
false) {
834 if (!in_array(
"socialnetworks", $listfields)) {
835 $listfields[] =
"socialnetworks";
836 $socialkey = array_search(
"socialnetworks", $listfields);
837 $listvalues[$socialkey] =
'';
839 if (!empty($newval) && $arrayrecord[($key)][
'type'] > 0) {
840 $socialkey = array_search(
"socialnetworks", $listfields);
841 $socialnetwork = explode(
"_", $fieldname)[1];
842 if (empty($listvalues[$socialkey]) || $listvalues[$socialkey] ==
"null") {
844 $json->$socialnetwork = $newval;
845 $listvalues[$socialkey] = json_encode($json);
847 $jsondata = $listvalues[$socialkey];
848 $json = json_decode($jsondata);
849 $json->$socialnetwork = $newval;
850 $listvalues[$socialkey] = json_encode($json);
854 $listfields[] = $fieldname;
857 if (empty($newval) && $arrayrecord[($key)][
'type'] < 0) {
858 $listvalues[] = ($newval ==
'0' ? (int) $newval :
"null");
859 } elseif (empty($newval) && $arrayrecord[($key)][
'type'] == 0) {
860 $listvalues[] =
"''";
862 $listvalues[] =
"'".$this->db->escape($newval).
"'";
872 if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0])) {
874 foreach ($objimport->array_import_fieldshidden[0] as $key => $val) {
875 if (!preg_match(
'/^' . preg_quote($alias,
'/') .
'\./', $key)) {
878 $keyfield = preg_replace(
'/^' . preg_quote($alias,
'/') .
'\./',
'', $key);
880 if (in_array($keyfield, $listfields)) {
882 } elseif ($val ==
'user->id') {
883 $listfields[] = $keyfield;
884 $listvalues[] = ((int) $user->id);
885 } elseif (preg_match(
'/^lastrowid-/', $val)) {
886 $tmp = explode(
'-', $val);
887 $lastinsertid = (isset($last_insert_id_array[$tmp[1]])) ? $last_insert_id_array[$tmp[1]] : 0;
888 $listfields[] = $keyfield;
889 $listvalues[] = (int) $lastinsertid;
891 } elseif (preg_match(
'/^const-/', $val)) {
892 $tmp = explode(
'-', $val, 2);
893 $listfields[] = $keyfield;
894 $listvalues[] =
"'".$this->db->escape($tmp[1]).
"'";
895 } elseif (preg_match(
'/^rule-/', $val)) {
897 $classinstance =
null;
898 if (!empty($objimport->array_import_convertvalue[0][$fieldname])) {
899 if ($objimport->array_import_convertvalue[0][$fieldname][
'rule'] ==
'compute') {
900 $file = (empty($objimport->array_import_convertvalue[0][$fieldname][
'classfile']) ? $objimport->array_import_convertvalue[0][$fieldname][
'file'] : $objimport->array_import_convertvalue[0][$fieldname][
'classfile']);
901 $class = $objimport->array_import_convertvalue[0][$fieldname][
'class'];
902 $method = $objimport->array_import_convertvalue[0][$fieldname][
'method'];
903 $type = $objimport->array_import_convertvalue[0][$fieldname][
'type'];
905 if (empty($resultload)) {
906 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method);
909 $classinstance =
new $class($this->db);
910 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, $key));
911 $fieldArr = explode(
'.', $fieldname);
912 if (count($fieldArr) > 0) {
913 $fieldname = $fieldArr[1];
917 $listfields[] = $fieldname;
918 if ($type ==
'int') {
919 $listvalues[] = (int) $res;
920 } elseif ($type ==
'double') {
921 $listvalues[] = (float) $res;
923 $listvalues[] =
"'".$this->db->escape($res).
"'";
926 $this->errors[$error][
'type'] =
'CLASSERROR';
927 if (is_object($classinstance)) {
928 $this->errors[$error][
'lib'] = implode(
930 array_merge([$classinstance->error], $classinstance->errors)
933 $this->errors[$error][
'lib']
934 =
"Unexpected rule ".$objimport->array_import_convertvalue[0][$fieldname][
'rule'];
937 $errorforthistable++;
942 $this->errors[$error][
'lib'] =
'Bad value of profile setup ' . $val .
' for array_import_fieldshidden';
943 $this->errors[$error][
'type'] =
'Import profile setup';
952 if (!$errorforthistable) {
954 if (!empty($listfields)) {
958 $is_table_category_link =
false;
960 if (strpos($tablename,
'_categorie_') !==
false) {
961 $is_table_category_link =
true;
965 if (!empty($updatekeys)) {
968 if (empty($lastinsertid)) {
969 $sqlSelect =
"SELECT ".$fname.
" FROM " . $tablename;
971 $data = array_combine($listfields, $listvalues);
975 '@phan-var string[] $where';
977 foreach ($updatekeys as $key) {
978 $col = $objimport->array_import_updatekeys[0][$key];
979 $key = preg_replace(
'/^.*\./i',
'', $key);
980 if (isModEnabled(
"socialnetworks") && strpos($key,
"socialnetworks") !==
false) {
981 $tmp = explode(
"_", $key);
983 $socialnetwork = $tmp[1];
984 $jsondata = $data[$key];
985 $json = json_decode($jsondata);
986 $stringtosearch = json_encode($socialnetwork).
':'.json_encode($json->$socialnetwork);
989 $where[] = $key.
" LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch)).
"%'";
990 $filters[] = $col.
" LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch)).
"%'";
993 $where[] = $key.
' = '.$data[$key];
994 $filters[] = $col.
' = '.$data[$key];
997 if (!empty($tablewithentity_cache[$tablename])) {
1001 $sqlSelect .=
" WHERE " . implode(
' AND ', $where);
1003 $resql = $this->db->query($sqlSelect);
1005 $num_rows = $this->db->num_rows($resql);
1006 if ($num_rows == 1) {
1007 $res = $this->db->fetch_object($resql);
1008 $lastinsertid = $res->rowid;
1009 if ($is_table_category_link) {
1010 $lastinsertid =
'linktable';
1012 $last_insert_id_array[$tablename] = $lastinsertid;
1013 } elseif ($num_rows > 1) {
1014 $this->errors[$error][
'lib'] = $langs->trans(
'MultipleRecordFoundWithTheseFilters', implode(
', ', $filters));
1015 $this->errors[$error][
'type'] =
'SQL';
1022 $this->errors[$error][
'lib'] = $this->db->lasterror();
1023 $this->errors[$error][
'type'] =
'SQL';
1032 $sqlSelect =
"SELECT rowid FROM " . $tablename;
1035 if (empty($keyfield)) {
1036 $keyfield =
'rowid';
1038 $sqlSelect .=
" WHERE ".$keyfield.
" = ".((int) $lastinsertid);
1040 if (!empty($tablewithentity_cache[$tablename])) {
1044 $resql = $this->db->query($sqlSelect);
1046 $res = $this->db->fetch_object($resql);
1047 if ($this->db->num_rows($resql) == 1) {
1056 $this->errors[$error][
'lib'] = $this->db->lasterror();
1057 $this->errors[$error][
'type'] =
'SQL';
1062 if (!empty($lastinsertid)) {
1064 if (in_array(
"socialnetworks", $listfields)) {
1065 $socialkey = array_search(
"socialnetworks", $listfields);
1066 $tmpsql = $listvalues[$socialkey];
1067 $listvalues[$socialkey] =
"'".$this->db->escape($tmpsql).
"'";
1071 $sqlstart =
"UPDATE " . $tablename;
1073 $data = array_combine($listfields, $listvalues);
1075 foreach ($data as $key => $val) {
1076 $set[] = $key.
" = ".$val;
1078 $sqlstart .=
" SET " . implode(
', ', $set) .
", import_key = '" . $this->db->escape($importid) .
"'";
1080 if (empty($keyfield)) {
1081 $keyfield =
'rowid';
1083 $sqlend =
" WHERE " . $keyfield .
" = ".((int) $lastinsertid);
1085 if ($is_table_category_link) {
1086 '@phan-var-force string[] $where';
1087 $sqlend =
" WHERE " . implode(
' AND ', $where);
1090 if (!empty($tablewithentity_cache[$tablename])) {
1094 $sql = $sqlstart . $sqlend;
1097 $resql = $this->db->query($sql);
1103 $this->errors[$error][
'lib'] = $this->db->lasterror();
1104 $this->errors[$error][
'type'] =
'SQL';
1111 if (!$error && !$updatedone) {
1113 if (in_array(
"socialnetworks", $listfields)) {
1114 $socialkey = array_search(
"socialnetworks", $listfields);
1115 $tmpsql = $listvalues[$socialkey];
1116 $listvalues[$socialkey] =
"'".$this->db->escape($tmpsql).
"'";
1120 $sqlstart =
"INSERT INTO " . $tablename .
"(" . implode(
", ", $listfields) .
", import_key";
1121 $sqlend =
") VALUES(" . implode(
', ', $listvalues) .
", '" . $this->db->escape($importid) .
"'";
1122 if (!empty($tablewithentity_cache[$tablename])) {
1123 $sqlstart .=
", entity";
1124 $sqlend .=
", " . $conf->entity;
1126 if (!empty($objimport->array_import_tables_creator[0][$alias])) {
1127 $sqlstart .=
", " . $objimport->array_import_tables_creator[0][$alias];
1128 $sqlend .=
", " . $user->id;
1130 $sql = $sqlstart . $sqlend .
")";
1135 $resql = $this->db->query($sql);
1137 if (!$is_table_category_link) {
1138 $last_insert_id_array[$tablename] = $this->db->last_insert_id($tablename);
1143 $this->errors[$error][
'lib'] = $this->db->lasterror();
1144 $this->errors[$error][
'type'] =
'SQL';