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;
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();
679 if (!empty($objimport->array_import_convertvalue[0][$val][
'classobject'])) {
680 $pathForObject = $objimport->array_import_convertvalue[0][$val][
'pathobject'];
681 require_once DOL_DOCUMENT_ROOT.$pathForObject;
682 $tmpclassobject = $objimport->array_import_convertvalue[0][$val][
'classobject'];
683 $tmpobject =
new $tmpclassobject($this->db);
684 foreach ($arrayfield as $tmpkey => $tmpval) {
685 if (in_array($tmpkey, array(
't.date',
'c.date_commande'))) {
686 $tmpobject->date =
dol_stringtotime($arrayrecord[$arrayfield[$tmpkey]][
'val'], 1);
691 $defaultref = $modForNumber->getNextValue(
null, $tmpobject);
693 if (is_numeric($defaultref) && $defaultref <= 0) {
696 $newval = $defaultref;
698 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'compute') {
699 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
700 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
701 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
703 if (empty($resultload)) {
704 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method);
707 $classinstance =
new $class($this->db);
708 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, $key));
709 if (empty($classinstance->error) && empty($classinstance->errors)) {
712 $this->errors[$error][
'type'] =
'CLASSERROR';
713 $this->errors[$error][
'lib'] = implode(
715 array_merge([$classinstance->error], $classinstance->errors)
717 $errorforthistable++;
720 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'numeric') {
722 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'accountingaccount') {
724 $newval = rtrim(trim($newval),
"0");
726 $newval = trim($newval);
734 if (!empty($objimport->array_import_regex[0][$val]) && ($newval !=
'')) {
737 if (preg_match(
'/^(.+)@([^:]+)(:.+)?$/', $objimport->array_import_regex[0][$val], $reg)) {
740 $filter = !empty($reg[3]) ? substr($reg[3], 1) :
'';
742 $cachekey = $field .
'@' . $table;
743 if (!empty($filter)) {
744 $cachekey .=
':' . $filter;
748 if (!is_array($this->cachefieldtable[$cachekey])) {
749 $sql =
"SELECT " . $field .
" as aliasfield FROM " . $table;
750 if (!empty($filter)) {
751 $sql .=
' WHERE ' . $filter;
754 $resql = $this->db->query($sql);
756 $num = $this->db->num_rows($resql);
759 $obj = $this->db->fetch_object($resql);
761 $this->cachefieldtable[$cachekey][] = $obj->aliasfield;
771 if (!is_array($this->cachefieldtable[$cachekey]) || !in_array($newval, $this->cachefieldtable[$cachekey])) {
772 $tableforerror = $table;
773 if (!empty($filter)) {
774 $tableforerror .=
':' . $filter;
777 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorFieldValueNotIn', $key, $newval, $field, $tableforerror);
778 $this->errors[$error][
'type'] =
'FOREIGNKEY';
779 $errorforthistable++;
782 } elseif (!preg_match(
'/' . $objimport->array_import_regex[0][$val] .
'/i', $newval)) {
786 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorWrongValueForField', $key, $newval, $objimport->array_import_regex[0][$val]);
787 $this->errors[$error][
'type'] =
'REGEX';
788 $errorforthistable++;
797 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorHtmlInjectionForField', $key,
dol_trunc($newval, 100));
798 $this->errors[$error][
'type'] =
'HTMLINJECTION';
799 $errorforthistable++;
808 if (isModEnabled(
"socialnetworks") && strpos($fieldname,
"socialnetworks") !==
false) {
809 if (!in_array(
"socialnetworks", $listfields)) {
810 $listfields[] =
"socialnetworks";
811 $socialkey = array_search(
"socialnetworks", $listfields);
812 $listvalues[$socialkey] =
'';
814 if (!empty($newval) && $arrayrecord[($key)][
'type'] > 0) {
815 $socialkey = array_search(
"socialnetworks", $listfields);
816 $socialnetwork = explode(
"_", $fieldname)[1];
817 if (empty($listvalues[$socialkey]) || $listvalues[$socialkey] ==
"null") {
819 $json->$socialnetwork = $newval;
820 $listvalues[$socialkey] = json_encode($json);
822 $jsondata = $listvalues[$socialkey];
823 $json = json_decode($jsondata);
824 $json->$socialnetwork = $newval;
825 $listvalues[$socialkey] = json_encode($json);
829 $listfields[] = $fieldname;
832 if (empty($newval) && $arrayrecord[($key)][
'type'] < 0) {
833 $listvalues[] = ($newval ==
'0' ? (int) $newval :
"null");
834 } elseif (empty($newval) && $arrayrecord[($key)][
'type'] == 0) {
835 $listvalues[] =
"''";
837 $listvalues[] =
"'".$this->db->escape($newval).
"'";
847 if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0])) {
849 foreach ($objimport->array_import_fieldshidden[0] as $key => $val) {
850 if (!preg_match(
'/^' . preg_quote($alias,
'/') .
'\./', $key)) {
853 $keyfield = preg_replace(
'/^' . preg_quote($alias,
'/') .
'\./',
'', $key);
855 if (in_array($keyfield, $listfields)) {
857 } elseif ($val ==
'user->id') {
858 $listfields[] = $keyfield;
859 $listvalues[] = ((int) $user->id);
860 } elseif (preg_match(
'/^lastrowid-/', $val)) {
861 $tmp = explode(
'-', $val);
862 $lastinsertid = (isset($last_insert_id_array[$tmp[1]])) ? $last_insert_id_array[$tmp[1]] : 0;
863 $listfields[] = $keyfield;
864 $listvalues[] = (int) $lastinsertid;
866 } elseif (preg_match(
'/^const-/', $val)) {
867 $tmp = explode(
'-', $val, 2);
868 $listfields[] = $keyfield;
869 $listvalues[] =
"'".$this->db->escape($tmp[1]).
"'";
870 } elseif (preg_match(
'/^rule-/', $val)) {
872 if (!empty($objimport->array_import_convertvalue[0][$fieldname])) {
873 if ($objimport->array_import_convertvalue[0][$fieldname][
'rule'] ==
'compute') {
874 $file = (empty($objimport->array_import_convertvalue[0][$fieldname][
'classfile']) ? $objimport->array_import_convertvalue[0][$fieldname][
'file'] : $objimport->array_import_convertvalue[0][$fieldname][
'classfile']);
875 $class = $objimport->array_import_convertvalue[0][$fieldname][
'class'];
876 $method = $objimport->array_import_convertvalue[0][$fieldname][
'method'];
877 $type = $objimport->array_import_convertvalue[0][$fieldname][
'type'];
879 if (empty($resultload)) {
880 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method);
883 $classinstance =
new $class($this->db);
884 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, $key));
885 $fieldArr = explode(
'.', $fieldname);
886 if (count($fieldArr) > 0) {
887 $fieldname = $fieldArr[1];
891 $listfields[] = $fieldname;
892 if ($type ==
'int') {
893 $listvalues[] = (int) $res;
894 } elseif ($type ==
'double') {
895 $listvalues[] = (float) $res;
897 $listvalues[] =
"'".$this->db->escape($res).
"'";
900 $this->errors[$error][
'type'] =
'CLASSERROR';
901 $this->errors[$error][
'lib'] = implode(
903 array_merge([$classinstance->error], $classinstance->errors)
905 $errorforthistable++;
910 $this->errors[$error][
'lib'] =
'Bad value of profile setup ' . $val .
' for array_import_fieldshidden';
911 $this->errors[$error][
'type'] =
'Import profile setup';
920 if (!$errorforthistable) {
922 if (!empty($listfields)) {
926 $is_table_category_link =
false;
928 if (strpos($tablename,
'_categorie_') !==
false) {
929 $is_table_category_link =
true;
933 if (!empty($updatekeys)) {
936 if (empty($lastinsertid)) {
937 $sqlSelect =
"SELECT ".$fname.
" FROM " . $tablename;
939 $data = array_combine($listfields, $listvalues);
943 '@phan-var string[] $where';
945 foreach ($updatekeys as $key) {
946 $col = $objimport->array_import_updatekeys[0][$key];
947 $key = preg_replace(
'/^.*\./i',
'', $key);
948 if (isModEnabled(
"socialnetworks") && strpos($key,
"socialnetworks") !==
false) {
949 $tmp = explode(
"_", $key);
951 $socialnetwork = $tmp[1];
952 $jsondata = $data[$key];
953 $json = json_decode($jsondata);
954 $stringtosearch = json_encode($socialnetwork).
':'.json_encode($json->$socialnetwork);
957 $where[] = $key.
" LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch)).
"%'";
958 $filters[] = $col.
" LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch)).
"%'";
961 $where[] = $key.
' = '.$data[$key];
962 $filters[] = $col.
' = '.$data[$key];
965 if (!empty($tablewithentity_cache[$tablename])) {
969 $sqlSelect .=
" WHERE " . implode(
' AND ', $where);
971 $resql = $this->db->query($sqlSelect);
973 $num_rows = $this->db->num_rows($resql);
974 if ($num_rows == 1) {
975 $res = $this->db->fetch_object($resql);
976 $lastinsertid = $res->rowid;
977 if ($is_table_category_link) {
978 $lastinsertid =
'linktable';
980 $last_insert_id_array[$tablename] = $lastinsertid;
981 } elseif ($num_rows > 1) {
982 $this->errors[$error][
'lib'] = $langs->trans(
'MultipleRecordFoundWithTheseFilters', implode(
', ', $filters));
983 $this->errors[$error][
'type'] =
'SQL';
990 $this->errors[$error][
'lib'] = $this->db->lasterror();
991 $this->errors[$error][
'type'] =
'SQL';
1000 $sqlSelect =
"SELECT rowid FROM " . $tablename;
1003 if (empty($keyfield)) {
1004 $keyfield =
'rowid';
1006 $sqlSelect .=
" WHERE ".$keyfield.
" = ".((int) $lastinsertid);
1008 if (!empty($tablewithentity_cache[$tablename])) {
1012 $resql = $this->db->query($sqlSelect);
1014 $res = $this->db->fetch_object($resql);
1015 if ($this->db->num_rows($resql) == 1) {
1024 $this->errors[$error][
'lib'] = $this->db->lasterror();
1025 $this->errors[$error][
'type'] =
'SQL';
1030 if (!empty($lastinsertid)) {
1032 if (in_array(
"socialnetworks", $listfields)) {
1033 $socialkey = array_search(
"socialnetworks", $listfields);
1034 $tmpsql = $listvalues[$socialkey];
1035 $listvalues[$socialkey] =
"'".$this->db->escape($tmpsql).
"'";
1039 $sqlstart =
"UPDATE " . $tablename;
1041 $data = array_combine($listfields, $listvalues);
1043 foreach ($data as $key => $val) {
1044 $set[] = $key.
" = ".$val;
1046 $sqlstart .=
" SET " . implode(
', ', $set) .
", import_key = '" . $this->db->escape($importid) .
"'";
1048 if (empty($keyfield)) {
1049 $keyfield =
'rowid';
1051 $sqlend =
" WHERE " . $keyfield .
" = ".((int) $lastinsertid);
1053 if ($is_table_category_link) {
1054 '@phan-var-force string[] $where';
1055 $sqlend =
" WHERE " . implode(
' AND ', $where);
1058 if (!empty($tablewithentity_cache[$tablename])) {
1062 $sql = $sqlstart . $sqlend;
1065 $resql = $this->db->query($sql);
1071 $this->errors[$error][
'lib'] = $this->db->lasterror();
1072 $this->errors[$error][
'type'] =
'SQL';
1079 if (!$error && !$updatedone) {
1081 if (in_array(
"socialnetworks", $listfields)) {
1082 $socialkey = array_search(
"socialnetworks", $listfields);
1083 $tmpsql = $listvalues[$socialkey];
1084 $listvalues[$socialkey] =
"'".$this->db->escape($tmpsql).
"'";
1088 $sqlstart =
"INSERT INTO " . $tablename .
"(" . implode(
", ", $listfields) .
", import_key";
1089 $sqlend =
") VALUES(" . implode(
', ', $listvalues) .
", '" . $this->db->escape($importid) .
"'";
1090 if (!empty($tablewithentity_cache[$tablename])) {
1091 $sqlstart .=
", entity";
1092 $sqlend .=
", " . $conf->entity;
1094 if (!empty($objimport->array_import_tables_creator[0][$alias])) {
1095 $sqlstart .=
", " . $objimport->array_import_tables_creator[0][$alias];
1096 $sqlend .=
", " . $user->id;
1098 $sql = $sqlstart . $sqlend .
")";
1103 $resql = $this->db->query($sql);
1105 if (!$is_table_category_link) {
1106 $last_insert_id_array[$tablename] = $this->db->last_insert_id($tablename);
1111 $this->errors[$error][
'lib'] = $this->db->lasterror();
1112 $this->errors[$error][
'type'] =
'SQL';