330 public function import_insert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys)
333 global $langs, $conf, $user;
334 global $thirdparty_static;
335 global $tablewithentity_cache;
339 $this->errors = array();
340 $this->warnings = array();
347 $array_match_database_to_file = array_flip($array_match_file_to_database);
348 $sort_array_match_file_to_database = $array_match_file_to_database;
349 ksort($sort_array_match_file_to_database);
353 if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[0][
'val']))) {
355 $this->warnings[$warning][
'lib'] = $langs->trans(
'EmptyLine');
356 $this->warnings[$warning][
'type'] =
'EMPTY';
359 $last_insert_id_array = array();
363 foreach ($objimport->array_import_tables[0] as $alias => $tablename) {
366 $listfields = array();
367 $listvalues = array();
369 $errorforthistable = 0;
372 if (!isset($tablewithentity_cache[$tablename])) {
373 dol_syslog(
"Check if table ".$tablename.
" has an entity field");
374 $resql = $this->db->DDLDescTable($tablename,
'entity');
376 $obj = $this->db->fetch_object($resql);
378 $tablewithentity_cache[$tablename] = 1;
380 $tablewithentity_cache[$tablename] = 0;
390 $arrayfield = array();
391 foreach ($sort_array_match_file_to_database as $key => $val) {
392 $arrayfield[$val] = ($key - 1);
399 foreach ($sort_array_match_file_to_database as $key => $val) {
400 $fieldalias = preg_replace(
'/\..*$/i',
'', $val);
401 $fieldname = preg_replace(
'/^.*\./i',
'', $val);
403 if ($alias != $fieldalias) {
407 if ($key <= $maxfields) {
410 if ($arrayrecord[($key - 1)][
'type'] > 0) {
411 $newval = $arrayrecord[($key - 1)][
'val'];
420 if (preg_match(
'/\*/', $objimport->array_import_fields[0][$val]) && ((string) $newval ==
'')) {
422 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorMissingMandatoryValue', $key);
423 $this->errors[$error][
'type'] =
'NOTNULL';
424 $errorforthistable++;
429 if (!empty($objimport->array_import_convertvalue[0][$val])) {
431 if ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeid'
432 || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromref'
433 || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeorlabel'
437 if (!is_numeric($newval) && $newval !=
'' && !preg_match(
'/^id:/i', $newval)) {
441 $newval = preg_replace(
'/^(id|ref):/i',
'', $newval);
444 if ($isidorref ==
'ref') {
445 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
446 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
447 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
448 if (isset($this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'][$newval]) && $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'][$newval] != $newval) {
449 $newval = $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'][$newval];
452 if (empty($resultload)) {
453 dol_print_error(
null,
'Error trying to call file='.$file.
', class='.$class.
', method='.$method);
456 $classinstance =
new $class($this->db);
457 if ($class ==
'CGenericDic') {
458 $classinstance->element = $objimport->array_import_convertvalue[0][$val][
'element'];
459 $classinstance->table_element = $objimport->array_import_convertvalue[0][$val][
'table_element'];
463 $param_array = array(
'', $newval);
464 if ($class ==
'AccountingAccount') {
477 $param_array = array(
'', $newval, 0, $arrayrecord[0][
'val']);
479 if ($class ==
'CActionComm') {
480 $param_array = array($newval);
482 $result = call_user_func_array(array($classinstance, $method), $param_array);
485 if (!($classinstance->id !=
'') && $result == -2) {
486 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorMultipleRecordFoundFromRef', $newval);
487 $this->errors[$error][
'type'] =
'FOREIGNKEY';
488 $errorforthistable++;
493 if (!($classinstance->id !=
'') && $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeorlabel') {
494 $param_array = array(
'',
'', $newval);
495 call_user_func_array(array($classinstance, $method), $param_array);
497 $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'][$newval] = $classinstance->id;
500 if ($classinstance->id !=
'') {
501 $newval = $classinstance->id;
502 } elseif (! $error) {
503 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
504 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn',
num2Alpha($key - 1), $newval,
'code', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
505 } elseif (!empty($objimport->array_import_convertvalue[0][$val][
'element'])) {
506 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldRefNotIn',
num2Alpha($key - 1), $newval, $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'element']));
508 $this->errors[$error][
'lib'] =
'ErrorBadDefinitionOfImportProfile';
510 $this->errors[$error][
'type'] =
'FOREIGNKEY';
511 $errorforthistable++;
516 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeandlabel') {
518 if (!is_numeric($newval) && $newval !=
'' && !preg_match(
'/^id:/i', $newval)) {
521 $newval = preg_replace(
'/^(id|ref):/i',
'', $newval);
523 if ($isidorref ==
'ref') {
524 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
525 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
526 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
527 $codefromfield = $objimport->array_import_convertvalue[0][$val][
'codefromfield'];
528 $code = $arrayrecord[$arrayfield[$codefromfield]][
'val'];
529 if ($this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$code][$newval] !=
'') {
530 $newval = $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$code][$newval];
533 if (empty($resultload)) {
534 dol_print_error(
null,
'Error trying to call file='.$file.
', class='.$class.
', method='.$method.
', code='.$code);
537 $classinstance =
new $class($this->db);
539 $param_array = array(
'', $newval, $code);
540 call_user_func_array(array($classinstance, $method), $param_array);
541 $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$code][$newval] = $classinstance->id;
542 if ($classinstance->id > 0) {
543 $newval = $classinstance->id;
545 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
546 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn',
num2Alpha($key - 1), $newval,
'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
548 $this->errors[$error][
'lib'] =
'ErrorFieldValueNotIn';
550 $this->errors[$error][
'type'] =
'FOREIGNKEY';
551 $errorforthistable++;
556 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'zeroifnull') {
557 if (empty($newval)) {
560 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeunits' || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchscalefromcodeunits') {
561 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
562 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
563 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
564 $units = $objimport->array_import_convertvalue[0][$val][
'units'];
565 if ($this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$units][$newval] !=
'') {
566 $newval = $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$units][$newval];
569 if (empty($resultload)) {
570 dol_print_error(
null,
'Error trying to call file='.$file.
', class='.$class.
', method='.$method.
', units='.$units);
573 $classinstance =
new $class($this->db);
575 call_user_func_array(array($classinstance, $method), array(
'',
'', $newval, $units));
576 $scaleorid = (($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeunits') ? $classinstance->id : $classinstance->scale);
577 $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$units][$newval] = $scaleorid;
579 if ($classinstance->id > 0) {
580 $newval = $scaleorid ? $scaleorid : 0;
582 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
583 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn',
num2Alpha($key - 1), $newval,
'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
585 $this->errors[$error][
'lib'] =
'ErrorFieldValueNotIn';
587 $this->errors[$error][
'type'] =
'FOREIGNKEY';
588 $errorforthistable++;
592 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getcustomercodeifauto') {
593 if (strtolower($newval) ==
'auto') {
594 $this->thirdpartyobject->get_codeclient(
null, 0);
595 $newval = $this->thirdpartyobject->code_client;
598 if (empty($newval)) {
599 $arrayrecord[($key - 1)][
'type'] = -1;
601 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getsuppliercodeifauto') {
602 if (strtolower($newval) ==
'auto') {
603 $this->thirdpartyobject->get_codefournisseur(
null, 1);
604 $newval = $this->thirdpartyobject->code_fournisseur;
607 if (empty($newval)) {
608 $arrayrecord[($key - 1)][
'type'] = -1;
610 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getcustomeraccountancycodeifauto') {
611 if (strtolower($newval) ==
'auto') {
612 $this->thirdpartyobject->get_codecompta(
'customer');
613 $newval = $this->thirdpartyobject->code_compta_client;
616 if (empty($newval)) {
617 $arrayrecord[($key - 1)][
'type'] = -1;
619 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getsupplieraccountancycodeifauto') {
620 if (strtolower($newval) ==
'auto') {
621 $this->thirdpartyobject->get_codecompta(
'supplier');
622 $newval = $this->thirdpartyobject->code_compta_fournisseur;
623 if (empty($newval)) {
624 $arrayrecord[($key - 1)][
'type'] = -1;
628 if (empty($newval)) {
629 $arrayrecord[($key - 1)][
'type'] = -1;
631 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getrefifauto') {
632 if (strtolower($newval) ==
'auto') {
635 $classModForNumber = $objimport->array_import_convertvalue[0][$val][
'class'];
636 $pathModForNumber = $objimport->array_import_convertvalue[0][$val][
'path'];
638 if (!empty($classModForNumber) && !empty($pathModForNumber) && is_readable(DOL_DOCUMENT_ROOT.$pathModForNumber)) {
639 require_once DOL_DOCUMENT_ROOT.$pathModForNumber;
640 $modForNumber =
new $classModForNumber();
641 '@phan-var-force ModeleNumRefMembers|ModeleNumRefCommandes|ModeleNumRefSuppliersInvoices|ModeleNumRefSuppliersOrders|ModeleNumRefProjects|ModeleNumRefTask|ModeleNumRefPropales $modForNumber';
645 if (!empty($objimport->array_import_convertvalue[0][$val][
'classobject'])) {
646 $pathForObject = $objimport->array_import_convertvalue[0][$val][
'pathobject'];
647 require_once DOL_DOCUMENT_ROOT.$pathForObject;
648 $tmpclassobject = $objimport->array_import_convertvalue[0][$val][
'classobject'];
649 $tmpobject =
new $tmpclassobject($this->db);
650 foreach ($arrayfield as $tmpkey => $tmpval) {
651 if (in_array($tmpkey, array(
't.date',
'c.date_commande'))) {
652 $tmpobject->date =
dol_stringtotime($arrayrecord[$arrayfield[$tmpkey]][
'val'], 1);
657 $defaultref = $modForNumber->getNextValue(
null, $tmpobject);
659 if (is_numeric($defaultref) && $defaultref <= 0) {
662 $newval = $defaultref;
664 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'compute') {
665 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
666 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
667 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
669 if (empty($resultload)) {
670 dol_print_error(
null,
'Error trying to call file='.$file.
', class='.$class.
', method='.$method);
673 $classinstance =
new $class($this->db);
674 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, ($key - 1)));
675 if (empty($classinstance->error) && empty($classinstance->errors)) {
678 $this->errors[$error][
'type'] =
'CLASSERROR';
679 $this->errors[$error][
'lib'] = implode(
681 array_merge([$classinstance->error], $classinstance->errors)
683 $errorforthistable++;
686 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'numeric') {
688 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'accountingaccount') {
690 $newval = rtrim(trim($newval),
"0");
692 $newval = trim($newval);
700 if (!empty($objimport->array_import_regex[0][$val]) && ($newval !=
'')) {
703 if (preg_match(
'/^(.+)@([^:]+)(:.+)?$/', $objimport->array_import_regex[0][$val], $reg)) {
706 $filter = !empty($reg[3]) ? substr($reg[3], 1) :
'';
708 $cachekey = $field.
'@'.$table;
709 if (!empty($filter)) {
710 $cachekey .=
':'.$filter;
714 if (!is_array($this->cachefieldtable[$cachekey])) {
715 $sql =
"SELECT ".$field.
" as aliasfield FROM ".$table;
716 if (!empty($filter)) {
717 $sql .=
' WHERE '.$filter;
720 $resql = $this->db->query($sql);
722 $num = $this->db->num_rows($resql);
725 $obj = $this->db->fetch_object($resql);
727 $this->cachefieldtable[$cachekey][] = $obj->aliasfield;
737 if (!is_array($this->cachefieldtable[$cachekey]) || !in_array($newval, $this->cachefieldtable[$cachekey])) {
738 $tableforerror = $table;
739 if (!empty($filter)) {
740 $tableforerror .=
':'.$filter;
742 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorFieldValueNotIn',
num2Alpha($key - 1), $newval, $field, $tableforerror);
743 $this->errors[$error][
'type'] =
'FOREIGNKEY';
744 $errorforthistable++;
747 } elseif (!preg_match(
'/'.$objimport->array_import_regex[0][$val].
'/i', $newval)) {
750 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorWrongValueForField',
num2Alpha($key - 1), $newval, $objimport->array_import_regex[0][$val]);
751 $this->errors[$error][
'type'] =
'REGEX';
752 $errorforthistable++;
760 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorHtmlInjectionForField',
num2Alpha($key - 1),
dol_trunc($newval, 100));
761 $this->errors[$error][
'type'] =
'HTMLINJECTION';
762 $errorforthistable++;
771 if (
isModEnabled(
"socialnetworks") && strpos($fieldname,
"socialnetworks") !==
false) {
772 if (!in_array(
"socialnetworks", $listfields)) {
773 $listfields[] =
"socialnetworks";
774 $socialkey = array_search(
"socialnetworks", $listfields);
775 $listvalues[$socialkey] =
'';
778 if (!empty($newval) && $arrayrecord[($key - 1)][
'type'] > 0) {
779 $socialkey = array_search(
"socialnetworks", $listfields);
781 $socialnetwork = explode(
"_", $fieldname)[1];
782 if (empty($listvalues[$socialkey]) || $listvalues[$socialkey] ==
"null") {
784 $json->$socialnetwork = $newval;
785 $listvalues[$socialkey] = json_encode($json);
787 $jsondata = $listvalues[$socialkey];
788 $json = json_decode($jsondata);
789 $json->$socialnetwork = $newval;
790 $listvalues[$socialkey] = json_encode($json);
794 $listfields[] = $fieldname;
796 if (empty($newval) && $arrayrecord[($key - 1)][
'type'] < 0) {
797 $listvalues[] = ($newval ==
'0' ? (int) $newval :
"null");
798 } elseif (empty($newval) && $arrayrecord[($key - 1)][
'type'] == 0) {
799 $listvalues[] =
"''";
801 $listvalues[] =
"'".$this->db->escape($newval).
"'";
811 if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0])) {
813 foreach ($objimport->array_import_fieldshidden[0] as $tmpkey => $tmpval) {
814 if (!preg_match(
'/^' . preg_quote($alias,
'/') .
'\./', $tmpkey)) {
817 $keyfieldcache = preg_replace(
'/^' . preg_quote($alias,
'/') .
'\./',
'', $tmpkey);
819 if (in_array($keyfieldcache, $listfields)) {
821 } elseif ($tmpval ==
'user->id') {
822 $listfields[] = $keyfieldcache;
823 $listvalues[] = ((int) $user->id);
824 } elseif (preg_match(
'/^lastrowid-/', $tmpval)) {
825 $tmp = explode(
'-', $tmpval);
826 $lastinsertid = (isset($last_insert_id_array[$tmp[1]])) ? $last_insert_id_array[$tmp[1]] : 0;
827 $listfields[] = $keyfieldcache;
828 $listvalues[] = (int) $lastinsertid;
829 $keyfield = $keyfieldcache;
831 } elseif (preg_match(
'/^const-/', $tmpval)) {
832 $tmp = explode(
'-', $tmpval, 2);
833 $listfields[] = $keyfieldcache;
834 $listvalues[] =
"'".$this->db->escape($tmp[1]).
"'";
835 } elseif (preg_match(
'/^rule-/', $tmpval)) {
836 $fieldname = $tmpkey;
837 if (!empty($objimport->array_import_convertvalue[0][$fieldname])) {
838 if ($objimport->array_import_convertvalue[0][$fieldname][
'rule'] ==
'compute') {
839 $file = (empty($objimport->array_import_convertvalue[0][$fieldname][
'classfile']) ? $objimport->array_import_convertvalue[0][$fieldname][
'file'] : $objimport->array_import_convertvalue[0][$fieldname][
'classfile']);
840 $class = $objimport->array_import_convertvalue[0][$fieldname][
'class'];
841 $method = $objimport->array_import_convertvalue[0][$fieldname][
'method'];
842 $type = $objimport->array_import_convertvalue[0][$fieldname][
'type'];
844 if (empty($resultload)) {
845 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method);
848 $classinstance =
new $class($this->db);
849 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, ($key - 1)));
850 if (empty($classinstance->error) && empty($classinstance->errors)) {
851 $fieldArr = explode(
'.', $fieldname);
852 if (count($fieldArr) > 0) {
853 $fieldname = $fieldArr[1];
857 $listfields[] = $fieldname;
858 if ($type ==
'int') {
859 $listvalues[] = (int) $res;
860 } elseif ($type ==
'double') {
861 $listvalues[] = (float) $res;
863 $listvalues[] =
"'".$this->db->escape($res).
"'";
866 $this->errors[$error][
'type'] =
'CLASSERROR';
867 $this->errors[$error][
'lib'] = implode(
869 array_merge([$classinstance->error], $classinstance->errors)
871 $errorforthistable++;
877 $this->errors[$error][
'lib'] =
'Bad value of profile setup '.$tmpval.
' for array_import_fieldshidden';
878 $this->errors[$error][
'type'] =
'Import profile setup';
887 if (!$errorforthistable) {
889 if (!empty($listfields)) {
893 $is_table_category_link =
false;
895 if (strpos($tablename,
'_categorie_') !==
false) {
896 $is_table_category_link =
true;
900 if (!empty($updatekeys)) {
903 if (empty($lastinsertid)) {
904 $sqlSelect =
"SELECT ".$fname.
" FROM ".$tablename;
905 $data = array_combine($listfields, $listvalues);
908 foreach ($updatekeys as $key) {
909 $col = $objimport->array_import_updatekeys[0][$key];
910 $key = preg_replace(
'/^.*\./i',
'', $key);
911 if (
isModEnabled(
"socialnetworks") && strpos($key,
"socialnetworks") !==
false) {
912 $tmp = explode(
"_", $key);
914 $socialnetwork = $tmp[1];
915 $jsondata = $data[$key];
916 $json = json_decode($jsondata);
917 $stringtosearch = json_encode($socialnetwork).
':'.json_encode($json->$socialnetwork);
920 $where[] = $key.
" LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch)).
"%'";
921 $filters[] = $col.
" LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch)).
"%'";
924 $where[] = $key.
' = '.$data[$key];
925 $filters[] = $col.
' = '.$data[$key];
928 if (!empty($tablewithentity_cache[$tablename])) {
932 $sqlSelect .=
" WHERE ".implode(
' AND ', $where);
934 $resql = $this->db->query($sqlSelect);
936 $num_rows = $this->db->num_rows($resql);
937 if ($num_rows == 1) {
938 $res = $this->db->fetch_object($resql);
939 $lastinsertid = $res->rowid;
941 if ($is_table_category_link) {
942 $lastinsertid =
'linktable';
944 $last_insert_id_array[$tablename] = $lastinsertid;
945 } elseif ($num_rows > 1) {
946 $this->errors[$error][
'lib'] = $langs->trans(
'MultipleRecordFoundWithTheseFilters', implode(
', ', $filters));
947 $this->errors[$error][
'type'] =
'SQL';
954 $this->errors[$error][
'lib'] = $this->db->lasterror();
955 $this->errors[$error][
'type'] =
'SQL';
964 $sqlSelect =
"SELECT rowid FROM ".$tablename;
965 if (empty($keyfield)) {
969 $sqlSelect .=
" WHERE ".$keyfield.
" = ".((int) $lastinsertid);
971 if (!empty($tablewithentity_cache[$tablename])) {
975 $resql = $this->db->query($sqlSelect);
977 $res = $this->db->fetch_object($resql);
978 if ($this->db->num_rows($resql) == 1) {
987 $this->errors[$error][
'lib'] = $this->db->lasterror();
988 $this->errors[$error][
'type'] =
'SQL';
993 if (!empty($lastinsertid)) {
995 if (in_array(
"socialnetworks", $listfields)) {
996 $socialkey = array_search(
"socialnetworks", $listfields);
997 $tmpsql = $listvalues[$socialkey];
998 $listvalues[$socialkey] =
"'".$this->db->escape($tmpsql).
"'";
1002 $sqlstart =
"UPDATE ".$tablename;
1004 $data = array_combine($listfields, $listvalues);
1006 foreach ($data as $key => $val) {
1007 $set[] = $key.
" = ".$val;
1009 $sqlstart .=
" SET ".implode(
', ', $set).
", import_key = '".$this->db->escape($importid).
"'";
1010 if (empty($keyfield)) {
1011 $keyfield =
'rowid';
1014 $sqlend =
" WHERE ".$keyfield.
" = ".((int) $lastinsertid);
1016 if ($is_table_category_link) {
1017 '@phan-var-force string[] $where';
1018 $sqlend =
" WHERE " . implode(
' AND ', $where);
1021 if (!empty($tablewithentity_cache[$tablename])) {
1025 $sql = $sqlstart.$sqlend;
1028 $resql = $this->db->query($sql);
1034 $this->errors[$error][
'lib'] = $this->db->lasterror();
1035 $this->errors[$error][
'type'] =
'SQL';
1042 if (!$error && !$updatedone) {
1044 if (in_array(
"socialnetworks", $listfields)) {
1045 $socialkey = array_search(
"socialnetworks", $listfields);
1046 $tmpsql = $listvalues[$socialkey];
1047 $listvalues[$socialkey] =
"'".$this->db->escape($tmpsql).
"'";
1051 $sqlstart =
"INSERT INTO ".$tablename.
"(".implode(
", ", $listfields).
", import_key";
1052 $sqlend =
") VALUES(".implode(
', ', $listvalues).
", '".$this->db->escape($importid).
"'";
1053 if (!empty($tablewithentity_cache[$tablename])) {
1054 $sqlstart .=
", entity";
1055 $sqlend .=
", ".$conf->entity;
1057 if (!empty($objimport->array_import_tables_creator[0][$alias])) {
1058 $sqlstart .=
", ".$objimport->array_import_tables_creator[0][$alias];
1059 $sqlend .=
", ".$user->id;
1061 $sql = $sqlstart.$sqlend.
")";
1066 $resql = $this->db->query($sql);
1068 if (!$is_table_category_link) {
1069 $last_insert_id_array[$tablename] = $this->db->last_insert_id($tablename);
1074 $this->errors[$error][
'lib'] = $this->db->lasterror();
1075 $this->errors[$error][
'type'] =
'SQL';