395 public function import_insert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys)
398 global $langs,
$conf, $user;
399 global $thirdparty_static;
400 global $tablewithentity_cache;
404 $this->errors = array();
405 $this->warnings = array();
412 $array_match_database_to_file = array_flip($array_match_file_to_database);
413 $sort_array_match_file_to_database = $array_match_file_to_database;
414 ksort($sort_array_match_file_to_database);
418 if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[1][
'val']))) {
420 $this->warnings[$warning][
'lib'] = $langs->trans(
'EmptyLine');
421 $this->warnings[$warning][
'type'] =
'EMPTY';
424 $last_insert_id_array = array();
428 foreach ($objimport->array_import_tables[0] as $alias => $tablename) {
431 $listfields = array();
432 $listvalues = array();
434 $errorforthistable = 0;
437 if (!isset($tablewithentity_cache[$tablename])) {
438 dol_syslog(
"Check if table " . $tablename .
" has an entity field");
439 $resql = $this->db->DDLDescTable($tablename,
'entity');
441 $obj = $this->db->fetch_object($resql);
443 $tablewithentity_cache[$tablename] = 1;
445 $tablewithentity_cache[$tablename] = 0;
455 $arrayfield = array();
456 foreach ($sort_array_match_file_to_database as $key => $val) {
457 $arrayfield[$val] = ($key);
464 foreach ($sort_array_match_file_to_database as $key => $val) {
465 $fieldalias = preg_replace(
'/\..*$/i',
'', $val);
466 $fieldname = preg_replace(
'/^.*\./i',
'', $val);
468 if ($alias != $fieldalias) {
472 if ($key <= $maxfields) {
475 if ($arrayrecord[($key)][
'type'] > 0) {
476 $newval = $arrayrecord[($key)][
'val'];
485 if (preg_match(
'/\*/', $objimport->array_import_fields[0][$val]) && ((string) $newval ==
'')) {
486 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorMissingMandatoryValue',
num2Alpha($key - 1));
487 $this->errors[$error][
'type'] =
'NOTNULL';
488 $errorforthistable++;
493 if (!empty($objimport->array_import_convertvalue[0][$val])) {
495 if ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeid'
496 || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromref'
497 || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeorlabel'
501 if (!is_numeric($newval) && $newval !=
'' && !preg_match(
'/^id:/i', $newval)) {
504 $newval = preg_replace(
'/^(id|ref):/i',
'', $newval);
507 if ($isidorref ==
'ref') {
508 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
509 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
510 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
511 if ($this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_'][$newval] !=
'') {
512 $newval = $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_'][$newval];
515 if (empty($resultload)) {
516 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method);
519 $classinstance =
new $class($this->db);
520 if ($class ==
'CGenericDic') {
521 $classinstance->element = $objimport->array_import_convertvalue[0][$val][
'element'];
522 $classinstance->table_element = $objimport->array_import_convertvalue[0][$val][
'table_element'];
526 $param_array = array(
'', $newval);
527 if ($class ==
'AccountingAccount') {
540 $param_array = array(
'', $newval, 0, $arrayrecord[0][
'val']);
543 $result = call_user_func_array(array($classinstance, $method), $param_array);
546 if (!($classinstance->id !=
'') && $result == -2) {
547 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorMultipleRecordFoundFromRef', $newval);
548 $this->errors[$error][
'type'] =
'FOREIGNKEY';
549 $errorforthistable++;
554 if (!($classinstance->id !=
'') && $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeorlabel') {
555 $param_array = array(
'',
'', $newval);
556 call_user_func_array(array($classinstance, $method), $param_array);
558 $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_'][$newval] = $classinstance->id;
561 if ($classinstance->id !=
'') {
562 $newval = $classinstance->id;
563 } elseif (! $error) {
564 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
566 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn', $key, $newval,
'code', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
567 } elseif (!empty($objimport->array_import_convertvalue[0][$val][
'element'])) {
569 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldRefNotIn', $key, $newval, $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'element']));
571 $this->errors[$error][
'lib'] =
'ErrorBadDefinitionOfImportProfile';
573 $this->errors[$error][
'type'] =
'FOREIGNKEY';
574 $errorforthistable++;
579 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeandlabel') {
581 if (!is_numeric($newval) && $newval !=
'' && !preg_match(
'/^id:/i', $newval)) {
584 $newval = preg_replace(
'/^(id|ref):/i',
'', $newval);
586 if ($isidorref ==
'ref') {
587 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
588 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
589 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
590 $codefromfield = $objimport->array_import_convertvalue[0][$val][
'codefromfield'];
591 $code = $arrayrecord[$arrayfield[$codefromfield]][
'val'];
592 if ($this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $code][$newval] !=
'') {
593 $newval = $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $code][$newval];
596 if (empty($resultload)) {
597 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method .
', code=' . $code);
600 $classinstance =
new $class($this->db);
602 $param_array = array(
'', $newval, $code);
603 call_user_func_array(array($classinstance, $method), $param_array);
604 $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $code][$newval] = $classinstance->id;
605 if ($classinstance->id > 0) {
606 $newval = $classinstance->id;
608 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
610 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn', $key, $newval,
'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
612 $this->errors[$error][
'lib'] =
'ErrorFieldValueNotIn';
614 $this->errors[$error][
'type'] =
'FOREIGNKEY';
615 $errorforthistable++;
620 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'zeroifnull') {
621 if (empty($newval)) {
624 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeunits' || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchscalefromcodeunits') {
625 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
626 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
627 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
628 $units = $objimport->array_import_convertvalue[0][$val][
'units'];
629 if ($this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $units][$newval] !=
'') {
630 $newval = $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $units][$newval];
633 if (empty($resultload)) {
634 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method .
', units=' . $units);
637 $classinstance =
new $class($this->db);
639 call_user_func_array(array($classinstance, $method), array(
'',
'', $newval, $units));
640 $scaleorid = (($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeunits') ? $classinstance->id : $classinstance->scale);
641 $this->cacheconvert[$file .
'_' . $class .
'_' . $method .
'_' . $units][$newval] = $scaleorid;
643 if ($classinstance->id > 0) {
644 $newval = $scaleorid ? $scaleorid : 0;
646 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
648 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn', $key, $newval,
'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
650 $this->errors[$error][
'lib'] =
'ErrorFieldValueNotIn';
652 $this->errors[$error][
'type'] =
'FOREIGNKEY';
653 $errorforthistable++;
657 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getcustomercodeifauto') {
658 if (strtolower($newval) ==
'auto') {
659 $this->thirdpartyobject->get_codeclient(
null, 0);
660 $newval = $this->thirdpartyobject->code_client;
663 if (empty($newval)) {
664 $arrayrecord[($key)][
'type'] = -1;
666 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getsuppliercodeifauto') {
667 if (strtolower($newval) ==
'auto') {
668 $this->thirdpartyobject->get_codefournisseur(
null, 1);
669 $newval = $this->thirdpartyobject->code_fournisseur;
672 if (empty($newval)) {
673 $arrayrecord[($key)][
'type'] = -1;
675 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getcustomeraccountancycodeifauto') {
676 if (strtolower($newval) ==
'auto') {
677 $this->thirdpartyobject->get_codecompta(
'customer');
678 $newval = $this->thirdpartyobject->code_compta_client;
681 if (empty($newval)) {
682 $arrayrecord[($key)][
'type'] = -1;
684 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getsupplieraccountancycodeifauto') {
685 if (strtolower($newval) ==
'auto') {
686 $this->thirdpartyobject->get_codecompta(
'supplier');
687 $newval = $this->thirdpartyobject->code_compta_fournisseur;
688 if (empty($newval)) {
689 $arrayrecord[($key)][
'type'] = -1;
693 if (empty($newval)) {
694 $arrayrecord[($key)][
'type'] = -1;
696 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getrefifauto') {
697 if (strtolower($newval) ==
'auto') {
700 $classModForNumber = $objimport->array_import_convertvalue[0][$val][
'class'];
701 $pathModForNumber = $objimport->array_import_convertvalue[0][$val][
'path'];
703 if (!empty($classModForNumber) && !empty($pathModForNumber) && is_readable(DOL_DOCUMENT_ROOT.$pathModForNumber)) {
704 require_once DOL_DOCUMENT_ROOT.$pathModForNumber;
705 $modForNumber =
new $classModForNumber();
706 '@phan-var-force ModeleNumRefMembers|ModeleNumRefCommandes|ModeleNumRefSuppliersInvoices|ModeleNumRefSuppliersOrders|ModeleNumRefProjects|ModeleNumRefTask|ModeleNumRefPropales $modForNumber';
710 if (!empty($objimport->array_import_convertvalue[0][$val][
'classobject'])) {
711 $pathForObject = $objimport->array_import_convertvalue[0][$val][
'pathobject'];
712 require_once DOL_DOCUMENT_ROOT.$pathForObject;
713 $tmpclassobject = $objimport->array_import_convertvalue[0][$val][
'classobject'];
714 $tmpobject =
new $tmpclassobject($this->db);
715 foreach ($arrayfield as $tmpkey => $tmpval) {
716 if (in_array($tmpkey, array(
't.date',
'c.date_commande'))) {
717 $tmpobject->date =
dol_stringtotime($arrayrecord[$arrayfield[$tmpkey]][
'val'], 1);
722 $defaultref = $modForNumber->getNextValue(
null, $tmpobject);
724 if (is_numeric($defaultref) && $defaultref <= 0) {
727 $newval = $defaultref;
729 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'compute') {
730 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
731 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
732 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
734 if (empty($resultload)) {
735 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method);
738 $classinstance =
new $class($this->db);
739 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, $key));
740 if (empty($classinstance->error) && empty($classinstance->errors)) {
743 $this->errors[$error][
'type'] =
'CLASSERROR';
744 $this->errors[$error][
'lib'] = implode(
746 array_merge([$classinstance->error], $classinstance->errors)
748 $errorforthistable++;
751 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'numeric') {
753 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'accountingaccount') {
755 $newval = rtrim(trim($newval),
"0");
757 $newval = trim($newval);
765 if (!empty($objimport->array_import_regex[0][$val]) && ($newval !=
'')) {
768 if (preg_match(
'/^(.+)@([^:]+)(:.+)?$/', $objimport->array_import_regex[0][$val], $reg)) {
771 $filter = !empty($reg[3]) ? substr($reg[3], 1) :
'';
773 $cachekey = $field .
'@' . $table;
774 if (!empty($filter)) {
775 $cachekey .=
':' . $filter;
779 if (!is_array($this->cachefieldtable[$cachekey])) {
780 $sql =
"SELECT " . $field .
" as aliasfield FROM " . $table;
781 if (!empty($filter)) {
782 $sql .=
' WHERE ' . $filter;
785 $resql = $this->db->query($sql);
787 $num = $this->db->num_rows($resql);
790 $obj = $this->db->fetch_object($resql);
792 $this->cachefieldtable[$cachekey][] = $obj->aliasfield;
802 if (!is_array($this->cachefieldtable[$cachekey]) || !in_array($newval, $this->cachefieldtable[$cachekey])) {
803 $tableforerror = $table;
804 if (!empty($filter)) {
805 $tableforerror .=
':' . $filter;
808 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorFieldValueNotIn', $key, $newval, $field, $tableforerror);
809 $this->errors[$error][
'type'] =
'FOREIGNKEY';
810 $errorforthistable++;
813 } elseif (!preg_match(
'/' . $objimport->array_import_regex[0][$val] .
'/i', $newval)) {
817 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorWrongValueForField', $key, $newval, $objimport->array_import_regex[0][$val]);
818 $this->errors[$error][
'type'] =
'REGEX';
819 $errorforthistable++;
828 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorHtmlInjectionForField', $key,
dol_trunc($newval, 100));
829 $this->errors[$error][
'type'] =
'HTMLINJECTION';
830 $errorforthistable++;
839 if (isModEnabled(
"socialnetworks") && strpos($fieldname,
"socialnetworks") !==
false) {
840 if (!in_array(
"socialnetworks", $listfields)) {
841 $listfields[] =
"socialnetworks";
842 $socialkey = array_search(
"socialnetworks", $listfields);
843 $listvalues[$socialkey] =
'';
845 if (!empty($newval) && $arrayrecord[($key)][
'type'] > 0) {
846 $socialkey = array_search(
"socialnetworks", $listfields);
847 $socialnetwork = explode(
"_", $fieldname)[1];
848 if (empty($listvalues[$socialkey]) || $listvalues[$socialkey] ==
"null") {
850 $json->$socialnetwork = $newval;
851 $listvalues[$socialkey] = json_encode($json);
853 $jsondata = $listvalues[$socialkey];
854 $json = json_decode($jsondata);
855 $json->$socialnetwork = $newval;
856 $listvalues[$socialkey] = json_encode($json);
860 $listfields[] = $fieldname;
863 if (empty($newval) && $arrayrecord[($key)][
'type'] < 0) {
864 $listvalues[] = ($newval ==
'0' ? (int) $newval :
"null");
865 } elseif (empty($newval) && $arrayrecord[($key)][
'type'] == 0) {
866 $listvalues[] =
"''";
868 $listvalues[] =
"'".$this->db->escape($newval).
"'";
878 if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0])) {
880 foreach ($objimport->array_import_fieldshidden[0] as $key => $val) {
881 if (!preg_match(
'/^' . preg_quote($alias,
'/') .
'\./', $key)) {
884 $keyfield = preg_replace(
'/^' . preg_quote($alias,
'/') .
'\./',
'', $key);
886 if (in_array($keyfield, $listfields)) {
888 } elseif ($val ==
'user->id') {
889 $listfields[] = $keyfield;
890 $listvalues[] = ((int) $user->id);
891 } elseif (preg_match(
'/^lastrowid-/', $val)) {
892 $tmp = explode(
'-', $val);
893 $lastinsertid = (isset($last_insert_id_array[$tmp[1]])) ? $last_insert_id_array[$tmp[1]] : 0;
894 $listfields[] = $keyfield;
895 $listvalues[] = (int) $lastinsertid;
897 } elseif (preg_match(
'/^const-/', $val)) {
898 $tmp = explode(
'-', $val, 2);
899 $listfields[] = $keyfield;
900 $listvalues[] =
"'".$this->db->escape($tmp[1]).
"'";
901 } elseif (preg_match(
'/^rule-/', $val)) {
903 $classinstance =
null;
904 if (!empty($objimport->array_import_convertvalue[0][$fieldname])) {
905 if ($objimport->array_import_convertvalue[0][$fieldname][
'rule'] ==
'compute') {
906 $file = (empty($objimport->array_import_convertvalue[0][$fieldname][
'classfile']) ? $objimport->array_import_convertvalue[0][$fieldname][
'file'] : $objimport->array_import_convertvalue[0][$fieldname][
'classfile']);
907 $class = $objimport->array_import_convertvalue[0][$fieldname][
'class'];
908 $method = $objimport->array_import_convertvalue[0][$fieldname][
'method'];
909 $type = $objimport->array_import_convertvalue[0][$fieldname][
'type'];
911 if (empty($resultload)) {
912 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method);
915 $classinstance =
new $class($this->db);
916 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, $key));
917 $fieldArr = explode(
'.', $fieldname);
918 if (count($fieldArr) > 0) {
919 $fieldname = $fieldArr[1];
923 $listfields[] = $fieldname;
924 if ($type ==
'int') {
925 $listvalues[] = (int) $res;
926 } elseif ($type ==
'double') {
927 $listvalues[] = (float) $res;
929 $listvalues[] =
"'".$this->db->escape($res).
"'";
932 $this->errors[$error][
'type'] =
'CLASSERROR';
933 if (is_object($classinstance)) {
934 $this->errors[$error][
'lib'] = implode(
936 array_merge([$classinstance->error], $classinstance->errors)
939 $this->errors[$error][
'lib']
940 =
"Unexpected rule ".$objimport->array_import_convertvalue[0][$fieldname][
'rule'];
943 $errorforthistable++;
948 $this->errors[$error][
'lib'] =
'Bad value of profile setup ' . $val .
' for array_import_fieldshidden';
949 $this->errors[$error][
'type'] =
'Import profile setup';
958 if (!$errorforthistable) {
960 if (!empty($listfields)) {
964 $is_table_category_link =
false;
966 if (strpos($tablename,
'_categorie_') !==
false) {
967 $is_table_category_link =
true;
971 if (!empty($updatekeys)) {
974 if (empty($lastinsertid)) {
975 $sqlSelect =
"SELECT ".$fname.
" FROM " . $tablename;
977 $data = array_combine($listfields, $listvalues);
981 '@phan-var string[] $where';
983 foreach ($updatekeys as $key) {
984 $col = $objimport->array_import_updatekeys[0][$key];
985 $key = preg_replace(
'/^.*\./i',
'', $key);
986 if (isModEnabled(
"socialnetworks") && strpos($key,
"socialnetworks") !==
false) {
987 $tmp = explode(
"_", $key);
989 $socialnetwork = $tmp[1];
990 $jsondata = $data[$key];
991 $json = json_decode($jsondata);
992 $stringtosearch = json_encode($socialnetwork).
':'.json_encode($json->$socialnetwork);
995 $where[] = $key.
" LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch)).
"%'";
996 $filters[] = $col.
" LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch)).
"%'";
999 $where[] = $key.
' = '.$data[$key];
1000 $filters[] = $col.
' = '.$data[$key];
1003 if (!empty($tablewithentity_cache[$tablename])) {
1007 $sqlSelect .=
" WHERE " . implode(
' AND ', $where);
1009 $resql = $this->db->query($sqlSelect);
1011 $num_rows = $this->db->num_rows($resql);
1012 if ($num_rows == 1) {
1013 $res = $this->db->fetch_object($resql);
1014 $lastinsertid = $res->rowid;
1015 if ($is_table_category_link) {
1016 $lastinsertid =
'linktable';
1018 $last_insert_id_array[$tablename] = $lastinsertid;
1019 } elseif ($num_rows > 1) {
1020 $this->errors[$error][
'lib'] = $langs->trans(
'MultipleRecordFoundWithTheseFilters', implode(
', ', $filters));
1021 $this->errors[$error][
'type'] =
'SQL';
1028 $this->errors[$error][
'lib'] = $this->db->lasterror();
1029 $this->errors[$error][
'type'] =
'SQL';
1038 $sqlSelect =
"SELECT rowid FROM " . $tablename;
1041 if (empty($keyfield)) {
1042 $keyfield =
'rowid';
1044 $sqlSelect .=
" WHERE ".$keyfield.
" = ".((int) $lastinsertid);
1046 if (!empty($tablewithentity_cache[$tablename])) {
1050 $resql = $this->db->query($sqlSelect);
1052 $res = $this->db->fetch_object($resql);
1053 if ($this->db->num_rows($resql) == 1) {
1062 $this->errors[$error][
'lib'] = $this->db->lasterror();
1063 $this->errors[$error][
'type'] =
'SQL';
1068 if (!empty($lastinsertid)) {
1070 if (in_array(
"socialnetworks", $listfields)) {
1071 $socialkey = array_search(
"socialnetworks", $listfields);
1072 $tmpsql = $listvalues[$socialkey];
1073 $listvalues[$socialkey] =
"'".$this->db->escape($tmpsql).
"'";
1077 $sqlstart =
"UPDATE " . $tablename;
1079 $data = array_combine($listfields, $listvalues);
1081 foreach ($data as $key => $val) {
1082 $set[] = $key.
" = ".$val;
1084 $sqlstart .=
" SET " . implode(
', ', $set) .
", import_key = '" . $this->db->escape($importid) .
"'";
1086 if (empty($keyfield)) {
1087 $keyfield =
'rowid';
1089 $sqlend =
" WHERE " . $keyfield .
" = ".((int) $lastinsertid);
1091 if ($is_table_category_link) {
1092 '@phan-var-force string[] $where';
1093 $sqlend =
" WHERE " . implode(
' AND ', $where);
1096 if (!empty($tablewithentity_cache[$tablename])) {
1100 $sql = $sqlstart . $sqlend;
1103 $resql = $this->db->query($sql);
1109 $this->errors[$error][
'lib'] = $this->db->lasterror();
1110 $this->errors[$error][
'type'] =
'SQL';
1117 if (!$error && !$updatedone) {
1119 if (in_array(
"socialnetworks", $listfields)) {
1120 $socialkey = array_search(
"socialnetworks", $listfields);
1121 $tmpsql = $listvalues[$socialkey];
1122 $listvalues[$socialkey] =
"'".$this->db->escape($tmpsql).
"'";
1126 $sqlstart =
"INSERT INTO " . $tablename .
"(" . implode(
", ", $listfields) .
", import_key";
1127 $sqlend =
") VALUES(" . implode(
', ', $listvalues) .
", '" . $this->db->escape($importid) .
"'";
1128 if (!empty($tablewithentity_cache[$tablename])) {
1129 $sqlstart .=
", entity";
1130 $sqlend .=
", " .
$conf->entity;
1132 if (!empty($objimport->array_import_tables_creator[0][$alias])) {
1133 $sqlstart .=
", " . $objimport->array_import_tables_creator[0][$alias];
1134 $sqlend .=
", " . $user->id;
1136 $sql = $sqlstart . $sqlend .
")";
1141 $resql = $this->db->query($sql);
1143 if (!$is_table_category_link) {
1144 $last_insert_id_array[$tablename] = $this->db->last_insert_id($tablename);
1149 $this->errors[$error][
'lib'] = $this->db->lasterror();
1150 $this->errors[$error][
'type'] =
'SQL';