324 public function import_insert($arrayrecord, $array_match_file_to_database, $objimport, $maxfields, $importid, $updatekeys)
327 global $langs, $conf, $user;
328 global $thirdparty_static;
329 global $tablewithentity_cache;
333 $this->errors = array();
334 $this->warnings = array();
341 $array_match_database_to_file = array_flip($array_match_file_to_database);
342 $sort_array_match_file_to_database = $array_match_file_to_database;
343 ksort($sort_array_match_file_to_database);
347 if (count($arrayrecord) == 0 || (count($arrayrecord) == 1 && empty($arrayrecord[0][
'val']))) {
349 $this->warnings[$warning][
'lib'] = $langs->trans(
'EmptyLine');
350 $this->warnings[$warning][
'type'] =
'EMPTY';
353 $last_insert_id_array = array();
357 foreach ($objimport->array_import_tables[0] as $alias => $tablename) {
360 $listfields = array();
361 $listvalues = array();
363 $errorforthistable = 0;
366 if (!isset($tablewithentity_cache[$tablename])) {
367 dol_syslog(
"Check if table ".$tablename.
" has an entity field");
368 $resql = $this->db->DDLDescTable($tablename,
'entity');
370 $obj = $this->db->fetch_object($resql);
372 $tablewithentity_cache[$tablename] = 1;
374 $tablewithentity_cache[$tablename] = 0;
384 $arrayfield = array();
385 foreach ($sort_array_match_file_to_database as $key => $val) {
386 $arrayfield[$val] = ($key - 1);
393 foreach ($sort_array_match_file_to_database as $key => $val) {
394 $fieldalias = preg_replace(
'/\..*$/i',
'', $val);
395 $fieldname = preg_replace(
'/^.*\./i',
'', $val);
397 if ($alias != $fieldalias) {
401 if ($key <= $maxfields) {
404 if ($arrayrecord[($key - 1)][
'type'] > 0) {
405 $newval = $arrayrecord[($key - 1)][
'val'];
414 if (preg_match(
'/\*/', $objimport->array_import_fields[0][$val]) && ((string) $newval ==
'')) {
416 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorMissingMandatoryValue', $key);
417 $this->errors[$error][
'type'] =
'NOTNULL';
418 $errorforthistable++;
423 if (!empty($objimport->array_import_convertvalue[0][$val])) {
425 if ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeid'
426 || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromref'
427 || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeorlabel'
431 if (!is_numeric($newval) && $newval !=
'' && !preg_match(
'/^id:/i', $newval)) {
435 $newval = preg_replace(
'/^(id|ref):/i',
'', $newval);
438 if ($isidorref ==
'ref') {
439 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
440 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
441 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
442 if ($this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'][$newval] !=
'') {
443 $newval = $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'][$newval];
446 if (empty($resultload)) {
447 dol_print_error(
null,
'Error trying to call file='.$file.
', class='.$class.
', method='.$method);
450 $classinstance =
new $class($this->db);
451 if ($class ==
'CGenericDic') {
452 $classinstance->element = $objimport->array_import_convertvalue[0][$val][
'element'];
453 $classinstance->table_element = $objimport->array_import_convertvalue[0][$val][
'table_element'];
457 $param_array = array(
'', $newval);
458 if ($class ==
'AccountingAccount') {
471 $param_array = array(
'', $newval, 0, $arrayrecord[0][
'val']);
473 if ($class ==
'CActionComm') {
474 $param_array = array($newval);
476 $result = call_user_func_array(array($classinstance, $method), $param_array);
479 if (!($classinstance->id !=
'') && $result == -2) {
480 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorMultipleRecordFoundFromRef', $newval);
481 $this->errors[$error][
'type'] =
'FOREIGNKEY';
482 $errorforthistable++;
487 if (!($classinstance->id !=
'') && $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeorlabel') {
488 $param_array = array(
'',
'', $newval);
489 call_user_func_array(array($classinstance, $method), $param_array);
491 $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'][$newval] = $classinstance->id;
494 if ($classinstance->id !=
'') {
495 $newval = $classinstance->id;
496 } elseif (! $error) {
497 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
498 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn',
num2Alpha($key - 1), $newval,
'code', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
499 } elseif (!empty($objimport->array_import_convertvalue[0][$val][
'element'])) {
500 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldRefNotIn',
num2Alpha($key - 1), $newval, $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'element']));
502 $this->errors[$error][
'lib'] =
'ErrorBadDefinitionOfImportProfile';
504 $this->errors[$error][
'type'] =
'FOREIGNKEY';
505 $errorforthistable++;
510 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeandlabel') {
512 if (!is_numeric($newval) && $newval !=
'' && !preg_match(
'/^id:/i', $newval)) {
515 $newval = preg_replace(
'/^(id|ref):/i',
'', $newval);
517 if ($isidorref ==
'ref') {
518 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
519 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
520 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
521 $codefromfield = $objimport->array_import_convertvalue[0][$val][
'codefromfield'];
522 $code = $arrayrecord[$arrayfield[$codefromfield]][
'val'];
523 if ($this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$code][$newval] !=
'') {
524 $newval = $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$code][$newval];
527 if (empty($resultload)) {
528 dol_print_error(
null,
'Error trying to call file='.$file.
', class='.$class.
', method='.$method.
', code='.$code);
531 $classinstance =
new $class($this->db);
533 $param_array = array(
'', $newval, $code);
534 call_user_func_array(array($classinstance, $method), $param_array);
535 $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$code][$newval] = $classinstance->id;
536 if ($classinstance->id > 0) {
537 $newval = $classinstance->id;
539 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
540 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn',
num2Alpha($key - 1), $newval,
'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
542 $this->errors[$error][
'lib'] =
'ErrorFieldValueNotIn';
544 $this->errors[$error][
'type'] =
'FOREIGNKEY';
545 $errorforthistable++;
550 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'zeroifnull') {
551 if (empty($newval)) {
554 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeunits' || $objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchscalefromcodeunits') {
555 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
556 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
557 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
558 $units = $objimport->array_import_convertvalue[0][$val][
'units'];
559 if ($this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$units][$newval] !=
'') {
560 $newval = $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$units][$newval];
563 if (empty($resultload)) {
564 dol_print_error(
null,
'Error trying to call file='.$file.
', class='.$class.
', method='.$method.
', units='.$units);
567 $classinstance =
new $class($this->db);
569 call_user_func_array(array($classinstance, $method), array(
'',
'', $newval, $units));
570 $scaleorid = (($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'fetchidfromcodeunits') ? $classinstance->id : $classinstance->scale);
571 $this->cacheconvert[$file.
'_'.$class.
'_'.$method.
'_'.$units][$newval] = $scaleorid;
573 if ($classinstance->id > 0) {
574 $newval = $scaleorid ? $scaleorid : 0;
576 if (!empty($objimport->array_import_convertvalue[0][$val][
'dict'])) {
577 $this->errors[$error][
'lib'] = $langs->trans(
'ErrorFieldValueNotIn',
num2Alpha($key - 1), $newval,
'scale', $langs->transnoentitiesnoconv($objimport->array_import_convertvalue[0][$val][
'dict']));
579 $this->errors[$error][
'lib'] =
'ErrorFieldValueNotIn';
581 $this->errors[$error][
'type'] =
'FOREIGNKEY';
582 $errorforthistable++;
586 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getcustomercodeifauto') {
587 if (strtolower($newval) ==
'auto') {
588 $this->thirdpartyobject->get_codeclient(0, 0);
589 $newval = $this->thirdpartyobject->code_client;
592 if (empty($newval)) {
593 $arrayrecord[($key - 1)][
'type'] = -1;
595 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getsuppliercodeifauto') {
596 if (strtolower($newval) ==
'auto') {
597 $this->thirdpartyobject->get_codefournisseur(0, 1);
598 $newval = $this->thirdpartyobject->code_fournisseur;
601 if (empty($newval)) {
602 $arrayrecord[($key - 1)][
'type'] = -1;
604 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getcustomeraccountancycodeifauto') {
605 if (strtolower($newval) ==
'auto') {
606 $this->thirdpartyobject->get_codecompta(
'customer');
607 $newval = $this->thirdpartyobject->code_compta_client;
610 if (empty($newval)) {
611 $arrayrecord[($key - 1)][
'type'] = -1;
613 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getsupplieraccountancycodeifauto') {
614 if (strtolower($newval) ==
'auto') {
615 $this->thirdpartyobject->get_codecompta(
'supplier');
616 $newval = $this->thirdpartyobject->code_compta_fournisseur;
617 if (empty($newval)) {
618 $arrayrecord[($key - 1)][
'type'] = -1;
622 if (empty($newval)) {
623 $arrayrecord[($key - 1)][
'type'] = -1;
625 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'getrefifauto') {
626 if (strtolower($newval) ==
'auto') {
629 $classModForNumber = $objimport->array_import_convertvalue[0][$val][
'class'];
630 $pathModForNumber = $objimport->array_import_convertvalue[0][$val][
'path'];
632 if (!empty($classModForNumber) && !empty($pathModForNumber) && is_readable(DOL_DOCUMENT_ROOT.$pathModForNumber)) {
633 require_once DOL_DOCUMENT_ROOT.$pathModForNumber;
634 $modForNumber =
new $classModForNumber();
635 '@phan-var-force ModeleNumRefMembers|ModeleNumRefCommandes|ModeleNumRefSuppliersInvoices|ModeleNumRefSuppliersOrders|ModeleNumRefProjects|ModeleNumRefTask|ModeleNumRefPropales $modForNumber';
639 if (!empty($objimport->array_import_convertvalue[0][$val][
'classobject'])) {
640 $pathForObject = $objimport->array_import_convertvalue[0][$val][
'pathobject'];
641 require_once DOL_DOCUMENT_ROOT.$pathForObject;
642 $tmpclassobject = $objimport->array_import_convertvalue[0][$val][
'classobject'];
643 $tmpobject =
new $tmpclassobject($this->db);
644 foreach ($arrayfield as $tmpkey => $tmpval) {
645 if (in_array($tmpkey, array(
't.date',
'c.date_commande'))) {
646 $tmpobject->date =
dol_stringtotime($arrayrecord[$arrayfield[$tmpkey]][
'val'], 1);
651 $defaultref = $modForNumber->getNextValue(
null, $tmpobject);
653 if (is_numeric($defaultref) && $defaultref <= 0) {
656 $newval = $defaultref;
658 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'compute') {
659 $file = (empty($objimport->array_import_convertvalue[0][$val][
'classfile']) ? $objimport->array_import_convertvalue[0][$val][
'file'] : $objimport->array_import_convertvalue[0][$val][
'classfile']);
660 $class = $objimport->array_import_convertvalue[0][$val][
'class'];
661 $method = $objimport->array_import_convertvalue[0][$val][
'method'];
663 if (empty($resultload)) {
664 dol_print_error(
null,
'Error trying to call file='.$file.
', class='.$class.
', method='.$method);
667 $classinstance =
new $class($this->db);
668 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, ($key - 1)));
669 if (empty($classinstance->error) && empty($classinstance->errors)) {
672 $this->errors[$error][
'type'] =
'CLASSERROR';
673 $this->errors[$error][
'lib'] = implode(
675 array_merge([$classinstance->error], $classinstance->errors)
677 $errorforthistable++;
680 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'numeric') {
682 } elseif ($objimport->array_import_convertvalue[0][$val][
'rule'] ==
'accountingaccount') {
684 $newval = rtrim(trim($newval),
"0");
686 $newval = trim($newval);
694 if (!empty($objimport->array_import_regex[0][$val]) && ($newval !=
'')) {
697 if (preg_match(
'/^(.+)@([^:]+)(:.+)?$/', $objimport->array_import_regex[0][$val], $reg)) {
700 $filter = !empty($reg[3]) ? substr($reg[3], 1) :
'';
702 $cachekey = $field.
'@'.$table;
703 if (!empty($filter)) {
704 $cachekey .=
':'.$filter;
708 if (!is_array($this->cachefieldtable[$cachekey])) {
709 $sql =
"SELECT ".$field.
" as aliasfield FROM ".$table;
710 if (!empty($filter)) {
711 $sql .=
' WHERE '.$filter;
714 $resql = $this->db->query($sql);
716 $num = $this->db->num_rows($resql);
719 $obj = $this->db->fetch_object($resql);
721 $this->cachefieldtable[$cachekey][] = $obj->aliasfield;
731 if (!is_array($this->cachefieldtable[$cachekey]) || !in_array($newval, $this->cachefieldtable[$cachekey])) {
732 $tableforerror = $table;
733 if (!empty($filter)) {
734 $tableforerror .=
':'.$filter;
736 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorFieldValueNotIn',
num2Alpha($key - 1), $newval, $field, $tableforerror);
737 $this->errors[$error][
'type'] =
'FOREIGNKEY';
738 $errorforthistable++;
741 } elseif (!preg_match(
'/'.$objimport->array_import_regex[0][$val].
'/i', $newval)) {
744 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorWrongValueForField',
num2Alpha($key - 1), $newval, $objimport->array_import_regex[0][$val]);
745 $this->errors[$error][
'type'] =
'REGEX';
746 $errorforthistable++;
754 $this->errors[$error][
'lib'] = $langs->transnoentitiesnoconv(
'ErrorHtmlInjectionForField',
num2Alpha($key - 1),
dol_trunc($newval, 100));
755 $this->errors[$error][
'type'] =
'HTMLINJECTION';
756 $errorforthistable++;
765 if (isModEnabled(
"socialnetworks") && strpos($fieldname,
"socialnetworks") !==
false) {
766 if (!in_array(
"socialnetworks", $listfields)) {
767 $listfields[] =
"socialnetworks";
768 $socialkey = array_search(
"socialnetworks", $listfields);
769 $listvalues[$socialkey] =
'';
772 if (!empty($newval) && $arrayrecord[($key - 1)][
'type'] > 0) {
773 $socialkey = array_search(
"socialnetworks", $listfields);
775 $socialnetwork = explode(
"_", $fieldname)[1];
776 if (empty($listvalues[$socialkey]) || $listvalues[$socialkey] ==
"null") {
778 $json->$socialnetwork = $newval;
779 $listvalues[$socialkey] = json_encode($json);
781 $jsondata = $listvalues[$socialkey];
782 $json = json_decode($jsondata);
783 $json->$socialnetwork = $newval;
784 $listvalues[$socialkey] = json_encode($json);
788 $listfields[] = $fieldname;
790 if (empty($newval) && $arrayrecord[($key - 1)][
'type'] < 0) {
791 $listvalues[] = ($newval ==
'0' ? (int) $newval :
"null");
792 } elseif (empty($newval) && $arrayrecord[($key - 1)][
'type'] == 0) {
793 $listvalues[] =
"''";
795 $listvalues[] =
"'".$this->db->escape($newval).
"'";
805 if (!empty($listfields) && is_array($objimport->array_import_fieldshidden[0])) {
807 foreach ($objimport->array_import_fieldshidden[0] as $tmpkey => $tmpval) {
808 if (!preg_match(
'/^' . preg_quote($alias,
'/') .
'\./', $tmpkey)) {
811 $keyfield = preg_replace(
'/^' . preg_quote($alias,
'/') .
'\./',
'', $tmpkey);
813 if (in_array($keyfield, $listfields)) {
815 } elseif ($tmpval ==
'user->id') {
816 $listfields[] = $keyfield;
817 $listvalues[] = ((int) $user->id);
818 } elseif (preg_match(
'/^lastrowid-/', $tmpval)) {
819 $tmp = explode(
'-', $tmpval);
820 $lastinsertid = (isset($last_insert_id_array[$tmp[1]])) ? $last_insert_id_array[$tmp[1]] : 0;
821 $listfields[] = $keyfield;
822 $listvalues[] = (int) $lastinsertid;
824 } elseif (preg_match(
'/^const-/', $tmpval)) {
825 $tmp = explode(
'-', $tmpval, 2);
826 $listfields[] = $keyfield;
827 $listvalues[] =
"'".$this->db->escape($tmp[1]).
"'";
828 } elseif (preg_match(
'/^rule-/', $tmpval)) {
829 $fieldname = $tmpkey;
830 if (!empty($objimport->array_import_convertvalue[0][$fieldname])) {
831 if ($objimport->array_import_convertvalue[0][$fieldname][
'rule'] ==
'compute') {
832 $file = (empty($objimport->array_import_convertvalue[0][$fieldname][
'classfile']) ? $objimport->array_import_convertvalue[0][$fieldname][
'file'] : $objimport->array_import_convertvalue[0][$fieldname][
'classfile']);
833 $class = $objimport->array_import_convertvalue[0][$fieldname][
'class'];
834 $method = $objimport->array_import_convertvalue[0][$fieldname][
'method'];
835 $type = $objimport->array_import_convertvalue[0][$fieldname][
'type'];
837 if (empty($resultload)) {
838 dol_print_error(
null,
'Error trying to call file=' . $file .
', class=' . $class .
', method=' . $method);
841 $classinstance =
new $class($this->db);
842 $res = call_user_func_array(array($classinstance, $method), array(&$arrayrecord, $arrayfield, ($key - 1)));
843 if (empty($classinstance->error) && empty($classinstance->errors)) {
844 $fieldArr = explode(
'.', $fieldname);
845 if (count($fieldArr) > 0) {
846 $fieldname = $fieldArr[1];
850 $listfields[] = $fieldname;
851 if ($type ==
'int') {
852 $listvalues[] = (int) $res;
853 } elseif ($type ==
'double') {
854 $listvalues[] = (float) $res;
856 $listvalues[] =
"'".$this->db->escape($res).
"'";
859 $this->errors[$error][
'type'] =
'CLASSERROR';
860 $this->errors[$error][
'lib'] = implode(
862 array_merge([$classinstance->error], $classinstance->errors)
864 $errorforthistable++;
870 $this->errors[$error][
'lib'] =
'Bad value of profile setup '.$tmpval.
' for array_import_fieldshidden';
871 $this->errors[$error][
'type'] =
'Import profile setup';
880 if (!$errorforthistable) {
882 if (!empty($listfields)) {
886 $is_table_category_link =
false;
888 if (strpos($tablename,
'_categorie_') !==
false) {
889 $is_table_category_link =
true;
893 if (!empty($updatekeys)) {
896 if (empty($lastinsertid)) {
897 $sqlSelect =
"SELECT ".$fname.
" FROM ".$tablename;
898 $data = array_combine($listfields, $listvalues);
901 foreach ($updatekeys as $key) {
902 $col = $objimport->array_import_updatekeys[0][$key];
903 $key = preg_replace(
'/^.*\./i',
'', $key);
904 if (isModEnabled(
"socialnetworks") && strpos($key,
"socialnetworks") !==
false) {
905 $tmp = explode(
"_", $key);
907 $socialnetwork = $tmp[1];
908 $jsondata = $data[$key];
909 $json = json_decode($jsondata);
910 $stringtosearch = json_encode($socialnetwork).
':'.json_encode($json->$socialnetwork);
913 $where[] = $key.
" LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch)).
"%'";
914 $filters[] = $col.
" LIKE '%".$this->db->escape($this->db->escapeforlike($stringtosearch)).
"%'";
917 $where[] = $key.
' = '.$data[$key];
918 $filters[] = $col.
' = '.$data[$key];
921 if (!empty($tablewithentity_cache[$tablename])) {
925 $sqlSelect .=
" WHERE ".implode(
' AND ', $where);
927 $resql = $this->db->query($sqlSelect);
929 $num_rows = $this->db->num_rows($resql);
930 if ($num_rows == 1) {
931 $res = $this->db->fetch_object($resql);
932 $lastinsertid = $res->rowid;
933 if ($is_table_category_link) {
934 $lastinsertid =
'linktable';
936 $last_insert_id_array[$tablename] = $lastinsertid;
937 } elseif ($num_rows > 1) {
938 $this->errors[$error][
'lib'] = $langs->trans(
'MultipleRecordFoundWithTheseFilters', implode(
', ', $filters));
939 $this->errors[$error][
'type'] =
'SQL';
946 $this->errors[$error][
'lib'] = $this->db->lasterror();
947 $this->errors[$error][
'type'] =
'SQL';
956 $sqlSelect =
"SELECT rowid FROM ".$tablename;
958 if (empty($keyfield)) {
961 $sqlSelect .=
" WHERE ".$keyfield.
" = ".((int) $lastinsertid);
963 if (!empty($tablewithentity_cache[$tablename])) {
967 $resql = $this->db->query($sqlSelect);
969 $res = $this->db->fetch_object($resql);
970 if ($this->db->num_rows($resql) == 1) {
979 $this->errors[$error][
'lib'] = $this->db->lasterror();
980 $this->errors[$error][
'type'] =
'SQL';
985 if (!empty($lastinsertid)) {
987 if (in_array(
"socialnetworks", $listfields)) {
988 $socialkey = array_search(
"socialnetworks", $listfields);
989 $tmpsql = $listvalues[$socialkey];
990 $listvalues[$socialkey] =
"'".$this->db->escape($tmpsql).
"'";
994 $sqlstart =
"UPDATE ".$tablename;
996 $data = array_combine($listfields, $listvalues);
998 foreach ($data as $key => $val) {
999 $set[] = $key.
" = ".$val;
1001 $sqlstart .=
" SET ".implode(
', ', $set).
", import_key = '".$this->db->escape($importid).
"'";
1003 if (empty($keyfield)) {
1004 $keyfield =
'rowid';
1006 $sqlend =
" WHERE ".$keyfield.
" = ".((int) $lastinsertid);
1008 if ($is_table_category_link) {
1009 '@phan-var-force string[] $where';
1010 $sqlend =
" WHERE " . implode(
' AND ', $where);
1013 if (!empty($tablewithentity_cache[$tablename])) {
1017 $sql = $sqlstart.$sqlend;
1020 $resql = $this->db->query($sql);
1026 $this->errors[$error][
'lib'] = $this->db->lasterror();
1027 $this->errors[$error][
'type'] =
'SQL';
1034 if (!$error && !$updatedone) {
1036 if (in_array(
"socialnetworks", $listfields)) {
1037 $socialkey = array_search(
"socialnetworks", $listfields);
1038 $tmpsql = $listvalues[$socialkey];
1039 $listvalues[$socialkey] =
"'".$this->db->escape($tmpsql).
"'";
1043 $sqlstart =
"INSERT INTO ".$tablename.
"(".implode(
", ", $listfields).
", import_key";
1044 $sqlend =
") VALUES(".implode(
', ', $listvalues).
", '".$this->db->escape($importid).
"'";
1045 if (!empty($tablewithentity_cache[$tablename])) {
1046 $sqlstart .=
", entity";
1047 $sqlend .=
", ".$conf->entity;
1049 if (!empty($objimport->array_import_tables_creator[0][$alias])) {
1050 $sqlstart .=
", ".$objimport->array_import_tables_creator[0][$alias];
1051 $sqlend .=
", ".$user->id;
1053 $sql = $sqlstart.$sqlend.
")";
1058 $resql = $this->db->query($sql);
1060 if (!$is_table_category_link) {
1061 $last_insert_id_array[$tablename] = $this->db->last_insert_id($tablename);
1066 $this->errors[$error][
'lib'] = $this->db->lasterror();
1067 $this->errors[$error][
'type'] =
'SQL';