Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lastrowid-*table* option when defining imports #2386

Merged
merged 1 commit into from Feb 24, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion htdocs/core/modules/import/import_csv.modules.php
Expand Up @@ -354,6 +354,7 @@ function import_insert($arrayrecord,$array_match_file_to_database,$objimport,$ma
}
else
{
$last_insert_id_array = array(); // store the last inserted auto_increment id for each table, so that dependent tables can be inserted with the appropriate id (eg: extrafields fk_object will be set with the last inserted object's id)
// For each table to insert, me make a separate insert
foreach($objimport->array_import_tables[0] as $alias => $tablename)
{
Expand Down Expand Up @@ -581,7 +582,7 @@ function import_insert($arrayrecord,$array_match_file_to_database,$objimport,$ma
elseif (preg_match('/^lastrowid-/',$val))
{
$tmp=explode('-',$val);
$lastinsertid=$this->db->last_insert_id($tmp[1]);
$lastinsertid=(isset($last_insert_id_array[$tmp[1]]))?$last_insert_id_array[$tmp[1]]:0;
$listfields.=preg_replace('/^'.preg_quote($alias).'\./','',$key);
$listvalues.=$lastinsertid;
//print $key."-".$val."-".$listfields."-".$listvalues."<br>";exit;
Expand Down Expand Up @@ -623,6 +624,7 @@ function import_insert($arrayrecord,$array_match_file_to_database,$objimport,$ma
if ($sql)
{
$resql=$this->db->query($sql);
$last_insert_id_array[$tablename] = $this->db->last_insert_id($tablename); // store the last inserted auto_increment id for each table, so that dependent tables can be inserted with the appropriate id. This must be done just after the INSERT request, else we risk losing the id (because another sql query will be issued somewhere in Dolibarr).
if ($resql)
{
//print '.';
Expand Down