diff --git a/htdocs/core/modules/import/import_csv.modules.php b/htdocs/core/modules/import/import_csv.modules.php index 60dc9bf6c15..34bff81e55c 100644 --- a/htdocs/core/modules/import/import_csv.modules.php +++ b/htdocs/core/modules/import/import_csv.modules.php @@ -633,6 +633,7 @@ class ImportCsv extends ModeleImports //print 'listfields='.$listfields.'
listvalues='.$listvalues.'
'; // If no error for this $alias/$tablename, we have a complete $listfields and $listvalues that are defined + // so we can try to make the insert or update now. if (! $errorforthistable) { //print "$alias/$tablename/$listfields/$listvalues
"; @@ -644,7 +645,7 @@ class ImportCsv extends ModeleImports if (!empty($updatekeys)) { // We do SELECT to get the rowid, if we already have the rowid, it's to be used below for related tables (extrafields) - if (empty($lastinsertid)) { + if (empty($lastinsertid)) { // No insert done yet for a parent table $sqlSelect = 'SELECT rowid FROM '.$tablename; $data = array_combine($listfields, $listvalues); @@ -680,10 +681,11 @@ class ImportCsv extends ModeleImports $error++; } } else { - // We have a last INSERT ID. Check if we have a row referencing this foreign key. + // We have a last INSERT ID (got by previous pass), so we check if we have a row referencing this foreign key. // This is required when updating table with some extrafields. When inserting a record in parent table, we can make // a direct insert into subtable extrafields, but when me wake an update, the insertid is defined and the child record - // may already exists. So we rescan the extrafield table to be know if record exists or not for the rowid. + // may already exists. So we rescan the extrafield table to know if record exists or not for the rowid. + // Note: For extrafield tablename, we have in importfieldshidden_array an enty 'extra.fk_object'=>'lastrowid-tableparent' so $keyfield is 'fk_object' $sqlSelect = 'SELECT rowid FROM '.$tablename; if(empty($keyfield)) $keyfield = 'rowid'; diff --git a/htdocs/core/modules/import/import_xlsx.modules.php b/htdocs/core/modules/import/import_xlsx.modules.php index 36b57e2d69a..2c37caa5d40 100644 --- a/htdocs/core/modules/import/import_xlsx.modules.php +++ b/htdocs/core/modules/import/import_xlsx.modules.php @@ -656,6 +656,7 @@ class ImportXlsx extends ModeleImports //print 'listfields='.$listfields.'
listvalues='.$listvalues.'
'; // If no error for this $alias/$tablename, we have a complete $listfields and $listvalues that are defined + // so we can try to make the insert or update now. if (! $errorforthistable) { //print "$alias/$tablename/$listfields/$listvalues
"; @@ -665,7 +666,8 @@ class ImportXlsx extends ModeleImports $insertdone = false; if (!empty($updatekeys)) { // We do SELECT to get the rowid, if we already have the rowid, it's to be used below for related tables (extrafields) - if (empty($lastinsertid)) { + + if (empty($lastinsertid)) { // No insert done yet for a parent table $sqlSelect = 'SELECT rowid FROM '.$tablename; $data = array_combine($listfields, $listvalues); @@ -704,7 +706,8 @@ class ImportXlsx extends ModeleImports // We have a last INSERT ID. Check if we have a row referencing this foreign key. // This is required when updating table with some extrafields. When inserting a record in parent table, we can make // a direct insert into subtable extrafields, but when me wake an update, the insertid is defined and the child record - // may already exists. So we rescan the extrafield table to be know if record exists or not for the rowid. + // may already exists. So we rescan the extrafield table to know if record exists or not for the rowid. + // Note: For extrafield tablename, we have in importfieldshidden_array an enty 'extra.fk_object'=>'lastrowid-tableparent' so $keyfield is 'fk_object' $sqlSelect = 'SELECT rowid FROM '.$tablename; if(empty($keyfield)) $keyfield = 'rowid';