329 public function import_insert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys)
332 global $langs, $conf, $user;
333 global $thirdparty_static;
334 global $tablewithentity_cache;
338 $this->errors = array();
339 $this->warnings = array();
346 $array_match_database_to_file = array_flip($array_match_file_to_database);
347 $sort_array_match_file_to_database = $array_match_file_to_database;
348 ksort($sort_array_match_file_to_database);
352 if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[0][
'val']))) {
354 $this->warnings[$warning][
'lib'] = $langs->trans(
'EmptyLine');
355 $this->warnings[$warning][
'type'] =
'EMPTY';
358 $last_insert_id_array = array();
362 foreach ($objimport->array_import_tables[0] as $alias => $tablename) {
365 $listfields = array();
366 $listvalues = array();
368 $errorforthistable = 0;
371 if (!isset($tablewithentity_cache[$tablename])) {
372 dol_syslog(
"Check if table ".$tablename.
" has an entity field");
373 $resql = $this->db->DDLDescTable($tablename,
'entity');
375 $obj = $this->db->fetch_object($resql);
377 $tablewithentity_cache[$tablename] = 1;
379 $tablewithentity_cache[$tablename] = 0;
389 $arrayfield = array();
390 foreach ($sort_array_match_file_to_database as $key => $val) {
391 $arrayfield[$val] = ($key - 1);
398 foreach ($sort_array_match_file_to_database as $key => $val) {
399 $fieldalias = preg_replace(
'/\..*$/i',
'', $val);
400 $fieldname = preg_replace(
'/^.*\./i',
'', $val);
402 if ($alias != $fieldalias) {
406 if ($key <= $maxfields) {
409 if ($arrayrecord[($key - 1)][
'type'] > 0) {
410 $newval = $arrayrecord[($key - 1)][
'val'];
419 if (preg_match(
'/\*/', $objimport->array_import_fields[0][$val]) && ((string) $newval ==
'')) {
421 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorMissingMandatoryValue', $key);
422 $this->errors[$error][
'type'] =
'NOTNULL';
423 $errorforthistable++;
428 if (!empty($objimport->array_import_convertvalue[0][$val])) {
430 if ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeid'
431 || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromref'
432 || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeorlabel'
436 if (!is_numeric($newval) && $newval !=
'' && !preg_match(
'/^id:/i', $newval)) {
440 $newval = preg_replace(
'/^(id|ref):/i',
'', $newval);
443 if ($isidorref ==
'ref') {
444 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
445 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
446 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
447 if ($this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'][$newval] !=
'') {
448 $newval = $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'][$newval];
451 if (empty($resultload)) {
452 dol_print_error(
null,
'Error trying to call file='.$file.
', class='.$class.
', method='.$method);
455 $classinstance =
new $class($this->db);
456 if ($class ==
'CGenericDic') {
457 $classinstance->element = $objimport->array_import_convertvalue[0][$val][
'element'];
458 $classinstance->table_element = $objimport->array_import_convertvalue[0][$val][
'table_element'];
462 $param_array = array(
'', $newval);
463 if ($class ==
'AccountingAccount') {
476 $param_array = array(
'', $newval, 0, $arrayrecord[0][
'val']);
478 if ($class ==
'CActionComm') {
479 $param_array = array($newval);
481 $result = call_user_func_array(array($classinstance, $method), $param_array);
484 if (!($classinstance->id !=
'') && $result == -2) {
485 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorMultipleRecordFoundFromRef', $newval);
486 $this->errors[$error][
'type'] =
'FOREIGNKEY';
487 $errorforthistable++;
492 if (!($classinstance->id !=
'') && $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeorlabel') {
493 $param_array = array(
'',
'', $newval);
494 call_user_func_array(array($classinstance, $method), $param_array);
496 $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'][$newval] = $classinstance->id;
499 if ($classinstance->id !=
'') {
500 $newval = $classinstance->id;
501 } elseif (! $error) {
502 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
503 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn',
num2Alpha($key - 1), $newval,
'code', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
504 } elseif (!empty($objimport->array_import_convertvalue[0][$val][
'element'])) {
505 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldRefNotIn',
num2Alpha($key - 1), $newval, $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'element']));
507 $this->errors[$error][
'lib'] =
'ErrorBadDefinitionOfImportProfile';
509 $this->errors[$error][
'type'] =
'FOREIGNKEY';
510 $errorforthistable++;
515 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeandlabel') {
517 if (!is_numeric($newval) && $newval !=
'' && !preg_match(
'/^id:/i', $newval)) {
520 $newval = preg_replace(
'/^(id|ref):/i',
'', $newval);
522 if ($isidorref ==
'ref') {
523 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
524 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
525 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
526 $codefromfield = $objimport->array_import_convertvalue[0][$val][
'codefromfield'];
527 $code = $arrayrecord[$arrayfield[$codefromfield]][
'val'];
528 if ($this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$code][$newval] !=
'') {
529 $newval = $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$code][$newval];
532 if (empty($resultload)) {
533 dol_print_error(
null,
'Error trying to call file='.$file.
', class='.$class.
', method='.$method.
', code='.$code);
536 $classinstance =
new $class($this->db);
538 $param_array = array(
'', $newval, $code);
539 call_user_func_array(array($classinstance, $method), $param_array);
540 $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$code][$newval] = $classinstance->id;
541 if ($classinstance->id > 0) {
542 $newval = $classinstance->id;
544 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
545 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn',
num2Alpha($key - 1), $newval,
'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
547 $this->errors[$error][
'lib'] =
'ErrorFieldValueNotIn';
549 $this->errors[$error][
'type'] =
'FOREIGNKEY';
550 $errorforthistable++;
555 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'zeroifnull') {
556 if (empty($newval)) {
559 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeunits' || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchscalefromcodeunits') {
560 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
561 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
562 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
563 $units = $objimport->array_import_convertvalue[0][$val][
'units'];
564 if ($this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$units][$newval] !=
'') {
565 $newval = $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$units][$newval];
568 if (empty($resultload)) {
569 dol_print_error(
null,
'Error trying to call file='.$file.
', class='.$class.
', method='.$method.
', units='.$units);
572 $classinstance =
new $class($this->db);
574 call_user_func_array(array($classinstance, $method), array(
'',
'', $newval, $units));
575 $scaleorid = (($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeunits') ? $classinstance->id : $classinstance->scale);
576 $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$units][$newval] = $scaleorid;
578 if ($classinstance->id > 0) {
579 $newval = $scaleorid ? $scaleorid : 0;
581 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
582 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn',
num2Alpha($key - 1), $newval,
'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
584 $this->errors[$error][
'lib'] =
'ErrorFieldValueNotIn';
586 $this->errors[$error][
'type'] =
'FOREIGNKEY';
587 $errorforthistable++;
591 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getcustomercodeifauto') {
592 if (strtolower($newval) ==
'auto') {
593 $this->thirdpartyobject->get_codeclient(
null, 0);
594 $newval = $this->thirdpartyobject->code_client;
597 if (empty($newval)) {
598 $arrayrecord[($key - 1)][
'type'] = -1;
600 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getsuppliercodeifauto') {
601 if (strtolower($newval) ==
'auto') {
602 $this->thirdpartyobject->get_codefournisseur(
null, 1);
603 $newval = $this->thirdpartyobject->code_fournisseur;
606 if (empty($newval)) {
607 $arrayrecord[($key - 1)][
'type'] = -1;
609 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getcustomeraccountancycodeifauto') {
610 if (strtolower($newval) ==
'auto') {
611 $this->thirdpartyobject->get_codecompta(
'customer');
612 $newval = $this->thirdpartyobject->code_compta_client;
615 if (empty($newval)) {
616 $arrayrecord[($key - 1)][
'type'] = -1;
618 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getsupplieraccountancycodeifauto') {
619 if (strtolower($newval) ==
'auto') {
620 $this->thirdpartyobject->get_codecompta(
'supplier');
621 $newval = $this->thirdpartyobject->code_compta_fournisseur;
622 if (empty($newval)) {
623 $arrayrecord[($key - 1)][
'type'] = -1;
627 if (empty($newval)) {
628 $arrayrecord[($key - 1)][
'type'] = -1;
630 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getrefifauto') {
631 if (strtolower($newval) ==
'auto') {
634 $classModForNumber = $objimport->array_import_convertvalue[0][$val][
'class'];
635 $pathModForNumber = $objimport->array_import_convertvalue[0][$val][
'path'];
637 if (!empty($classModForNumber) && !empty($pathModForNumber) && is_readable(DOL_DOCUMENT_ROOT.$pathModForNumber)) {
638 require_once DOL_DOCUMENT_ROOT.$pathModForNumber;
639 $modForNumber =
new $classModForNumber();
640 '@phan-var-force ModeleNumRefMembers|ModeleNumRefCommandes|ModeleNumRefSuppliersInvoices|ModeleNumRefSuppliersOrders|ModeleNumRefProjects|ModeleNumRefTask|ModeleNumRefPropales $modForNumber';
644 if (!empty($objimport->array_import_convertvalue[0][$val][
'classobject'])) {
645 $pathForObject = $objimport->array_import_convertvalue[0][$val][
'pathobject'];
646 require_once DOL_DOCUMENT_ROOT.$pathForObject;
647 $tmpclassobject = $objimport->array_import_convertvalue[0][$val][
'classobject'];
648 $tmpobject =
new $tmpclassobject($this->db);
649 foreach ($arrayfield as $tmpkey => $tmpval) {
650 if (in_array($tmpkey, array(
't.date',
'c.date_commande'))) {
651 $tmpobject->date =
dol_stringtotime($arrayrecord[$arrayfield[$tmpkey]][
'val'], 1);
656 $defaultref = $modForNumber->getNextValue(
null, $tmpobject);
658 if (is_numeric($defaultref) && $defaultref <= 0) {
661 $newval = $defaultref;
663 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'compute') {
664 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
665 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
666 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
668 if (empty($resultload)) {
669 dol_print_error(
null,
'Error trying to call file='.$file.
', class='.$class.
', method='.$method);
672 $classinstance =
new $class($this->db);
673 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, ($key - 1)));
674 if (empty($classinstance->error) && empty($classinstance->errors)) {
677 $this->errors[$error][
'type'] =
'CLASSERROR';
678 $this->errors[$error][
'lib'] = implode(
680 array_merge([$classinstance->error], $classinstance->errors)
682 $errorforthistable++;
685 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'numeric') {
687 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'accountingaccount') {
689 $newval = rtrim(trim($newval),
"0");
691 $newval = trim($newval);
699 if (!empty($objimport->array_import_regex[0][$val]) && ($newval !=
'')) {
702 if (preg_match(
'/^(.+)@([^:]+)(:.+)?$/', $objimport->array_import_regex[0][$val], $reg)) {
705 $filter = !empty($reg[3]) ? substr($reg[3], 1) :
'';
707 $cachekey = $field.
'@'.$table;
708 if (!empty($filter)) {
709 $cachekey .=
':'.$filter;
713 if (!is_array($this->cachefieldtable[$cachekey])) {
714 $sql =
"SELECT ".$field.
" as aliasfield FROM ".$table;
715 if (!empty($filter)) {
716 $sql .=
' WHERE '.$filter;
719 $resql = $this->db->query($sql);
721 $num = $this->db->num_rows($resql);
724 $obj = $this->db->fetch_object($resql);
726 $this->cachefieldtable[$cachekey][] = $obj->aliasfield;
736 if (!is_array($this->cachefieldtable[$cachekey]) || !in_array($newval, $this->cachefieldtable[$cachekey])) {
737 $tableforerror = $table;
738 if (!empty($filter)) {
739 $tableforerror .=
':'.$filter;
741 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorFieldValueNotIn',
num2Alpha($key - 1), $newval, $field, $tableforerror);
742 $this->errors[$error][
'type'] =
'FOREIGNKEY';
743 $errorforthistable++;
746 } elseif (!preg_match(
'/'.$objimport->array_import_regex[0][$val].
'/i', $newval)) {
749 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorWrongValueForField',
num2Alpha($key - 1), $newval, $objimport->array_import_regex[0][$val]);
750 $this->errors[$error][
'type'] =
'REGEX';
751 $errorforthistable++;
759 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorHtmlInjectionForField',
num2Alpha($key - 1),
dol_trunc($newval, 100));
760 $this->errors[$error][
'type'] =
'HTMLINJECTION';
761 $errorforthistable++;
770 if (isModEnabled(
"socialnetworks") && strpos($fieldname,
"socialnetworks") !==
false) {
771 if (!in_array(
"socialnetworks", $listfields)) {
772 $listfields[] =
"socialnetworks";
773 $socialkey = array_search(
"socialnetworks", $listfields);
774 $listvalues[$socialkey] =
'';
777 if (!empty($newval) && $arrayrecord[($key - 1)][
'type'] > 0) {
778 $socialkey = array_search(
"socialnetworks", $listfields);
780 $socialnetwork = explode(
"_", $fieldname)[1];
781 if (empty($listvalues[$socialkey]) || $listvalues[$socialkey] ==
"null") {
783 $json->$socialnetwork = $newval;
784 $listvalues[$socialkey] = json_encode($json);
786 $jsondata = $listvalues[$socialkey];
787 $json = json_decode($jsondata);
788 $json->$socialnetwork = $newval;
789 $listvalues[$socialkey] = json_encode($json);
793 $listfields[] = $fieldname;
795 if (empty($newval) && $arrayrecord[($key - 1)][
'type'] < 0) {
796 $listvalues[] = ($newval ==
'0' ? (int) $newval :
"null");
797 } elseif (empty($newval) && $arrayrecord[($key - 1)][
'type'] == 0) {
798 $listvalues[] =
"''";
800 $listvalues[] =
"'".$this->db->escape($newval).
"'";
810 if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0])) {
812 foreach ($objimport->array_import_fieldshidden[0] as $tmpkey => $tmpval) {
813 if (!preg_match(
'/^' . preg_quote($alias,
'/') .
'\./', $tmpkey)) {
816 $keyfield = preg_replace(
'/^' . preg_quote($alias,
'/') .
'\./',
'', $tmpkey);
818 if (in_array($keyfield, $listfields)) {
820 } elseif ($tmpval ==
'user->id') {
821 $listfields[] = $keyfield;
822 $listvalues[] = ((int) $user->id);
823 } elseif (preg_match(
'/^lastrowid-/', $tmpval)) {
824 $tmp = explode(
'-', $tmpval);
825 $lastinsertid = (isset($last_insert_id_array[$tmp[1]])) ? $last_insert_id_array[$tmp[1]] : 0;
826 $listfields[] = $keyfield;
827 $listvalues[] = (int) $lastinsertid;
829 } elseif (preg_match(
'/^const-/', $tmpval)) {
830 $tmp = explode(
'-', $tmpval, 2);
831 $listfields[] = $keyfield;
832 $listvalues[] =
"'".$this->db->escape($tmp[1]).
"'";
833 } elseif (preg_match(
'/^rule-/', $tmpval)) {
834 $fieldname = $tmpkey;
835 if (!empty($objimport->array_import_convertvalue[0][$fieldname])) {
836 if ($objimport->array_import_convertvalue[0][$fieldname][
'rule'] ==
'compute') {
837 $file = (empty($objimport->array_import_convertvalue[0][$fieldname][
'classfile']) ? $objimport->array_import_convertvalue[0][$fieldname][
'file'] : $objimport->array_import_convertvalue[0][$fieldname][
'classfile']);
838 $class = $objimport->array_import_convertvalue[0][$fieldname][
'class'];
839 $method = $objimport->array_import_convertvalue[0][$fieldname][
'method'];
840 $type = $objimport->array_import_convertvalue[0][$fieldname][
'type'];
842 if (empty($resultload)) {
843 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method);
846 $classinstance =
new $class($this->db);
847 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, ($key - 1)));
848 if (empty($classinstance->error) && empty($classinstance->errors)) {
849 $fieldArr = explode(
'.', $fieldname);
850 if (count($fieldArr) > 0) {
851 $fieldname = $fieldArr[1];
855 $listfields[] = $fieldname;
856 if ($type ==
'int') {
857 $listvalues[] = (int) $res;
858 } elseif ($type ==
'double') {
859 $listvalues[] = (float) $res;
861 $listvalues[] =
"'".$this->db->escape($res).
"'";
864 $this->errors[$error][
'type'] =
'CLASSERROR';
865 $this->errors[$error][
'lib'] = implode(
867 array_merge([$classinstance->error], $classinstance->errors)
869 $errorforthistable++;
875 $this->errors[$error][
'lib'] =
'Bad value of profile setup '.$tmpval.
' for array_import_fieldshidden';
876 $this->errors[$error][
'type'] =
'Import profile setup';
885 if (!$errorforthistable) {
887 if (!empty($listfields)) {
891 $is_table_category_link =
false;
893 if (strpos($tablename,
'_categorie_') !==
false) {
894 $is_table_category_link =
true;
898 if (!empty($updatekeys)) {
901 if (empty($lastinsertid)) {
902 $sqlSelect =
"SELECT ".$fname.
" FROM ".$tablename;
903 $data = array_combine($listfields, $listvalues);
906 foreach ($updatekeys as $key) {
907 $col = $objimport->array_import_updatekeys[0][$key];
908 $key = preg_replace(
'/^.*\./i',
'', $key);
909 if (isModEnabled(
"socialnetworks") && strpos($key,
"socialnetworks") !==
false) {
910 $tmp = explode(
"_", $key);
912 $socialnetwork = $tmp[1];
913 $jsondata = $data[$key];
914 $json = json_decode($jsondata);
915 $stringtosearch = json_encode($socialnetwork).
':'.json_encode($json->$socialnetwork);
918 $where[] = $key.
" LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch)).
"%'";
919 $filters[] = $col.
" LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch)).
"%'";
922 $where[] = $key.
' = '.$data[$key];
923 $filters[] = $col.
' = '.$data[$key];
926 if (!empty($tablewithentity_cache[$tablename])) {
930 $sqlSelect .=
" WHERE ".implode(
' AND ', $where);
932 $resql = $this->db->query($sqlSelect);
934 $num_rows = $this->db->num_rows($resql);
935 if ($num_rows == 1) {
936 $res = $this->db->fetch_object($resql);
937 $lastinsertid = $res->rowid;
938 if ($is_table_category_link) {
939 $lastinsertid =
'linktable';
941 $last_insert_id_array[$tablename] = $lastinsertid;
942 } elseif ($num_rows > 1) {
943 $this->errors[$error][
'lib'] = $langs->trans(
'MultipleRecordFoundWithTheseFilters', implode(
', ', $filters));
944 $this->errors[$error][
'type'] =
'SQL';
951 $this->errors[$error][
'lib'] = $this->db->lasterror();
952 $this->errors[$error][
'type'] =
'SQL';
961 $sqlSelect =
"SELECT rowid FROM ".$tablename;
963 if (empty($keyfield)) {
966 $sqlSelect .=
" WHERE ".$keyfield.
" = ".((int) $lastinsertid);
968 if (!empty($tablewithentity_cache[$tablename])) {
972 $resql = $this->db->query($sqlSelect);
974 $res = $this->db->fetch_object($resql);
975 if ($this->db->num_rows($resql) == 1) {
984 $this->errors[$error][
'lib'] = $this->db->lasterror();
985 $this->errors[$error][
'type'] =
'SQL';
990 if (!empty($lastinsertid)) {
992 if (in_array(
"socialnetworks", $listfields)) {
993 $socialkey = array_search(
"socialnetworks", $listfields);
994 $tmpsql = $listvalues[$socialkey];
995 $listvalues[$socialkey] =
"'".$this->db->escape($tmpsql).
"'";
999 $sqlstart =
"UPDATE ".$tablename;
1001 $data = array_combine($listfields, $listvalues);
1003 foreach ($data as $key => $val) {
1004 $set[] = $key.
" = ".$val;
1006 $sqlstart .=
" SET ".implode(
', ', $set).
", import_key = '".$this->db->escape($importid).
"'";
1008 if (empty($keyfield)) {
1009 $keyfield =
'rowid';
1011 $sqlend =
" WHERE ".$keyfield.
" = ".((int) $lastinsertid);
1013 if ($is_table_category_link) {
1014 '@phan-var-force string[] $where';
1015 $sqlend =
" WHERE " . implode(
' AND ', $where);
1018 if (!empty($tablewithentity_cache[$tablename])) {
1022 $sql = $sqlstart.$sqlend;
1025 $resql = $this->db->query($sql);
1031 $this->errors[$error][
'lib'] = $this->db->lasterror();
1032 $this->errors[$error][
'type'] =
'SQL';
1039 if (!$error && !$updatedone) {
1041 if (in_array(
"socialnetworks", $listfields)) {
1042 $socialkey = array_search(
"socialnetworks", $listfields);
1043 $tmpsql = $listvalues[$socialkey];
1044 $listvalues[$socialkey] =
"'".$this->db->escape($tmpsql).
"'";
1048 $sqlstart =
"INSERT INTO ".$tablename.
"(".implode(
", ", $listfields).
", import_key";
1049 $sqlend =
") VALUES(".implode(
', ', $listvalues).
", '".$this->db->escape($importid).
"'";
1050 if (!empty($tablewithentity_cache[$tablename])) {
1051 $sqlstart .=
", entity";
1052 $sqlend .=
", ".$conf->entity;
1054 if (!empty($objimport->array_import_tables_creator[0][$alias])) {
1055 $sqlstart .=
", ".$objimport->array_import_tables_creator[0][$alias];
1056 $sqlend .=
", ".$user->id;
1058 $sql = $sqlstart.$sqlend.
")";
1063 $resql = $this->db->query($sql);
1065 if (!$is_table_category_link) {
1066 $last_insert_id_array[$tablename] = $this->db->last_insert_id($tablename);
1071 $this->errors[$error][
'lib'] = $this->db->lasterror();
1072 $this->errors[$error][
'type'] =
'SQL';