Merge pull request #20814 from atm-gauthier/NEW/develop_update_on_categorie_product_link_table

New/develop update on categorie product link table
This commit is contained in:
Laurent Destailleur 2022-05-29 11:30:26 +02:00 committed by GitHub
commit 0dda1d7e76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 2 deletions

View File

@ -819,11 +819,18 @@ class ImportCsv extends ModeleImports
$updatedone = false;
$insertdone = false;
$is_table_category_link = false;
$fname = 'rowid';
if (strpos($tablename, '_categorie_') !== false) {
$is_table_category_link = true;
$fname='*';
}
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)) { // No insert done yet for a parent table
$sqlSelect = "SELECT rowid FROM ".$tablename;
$sqlSelect = "SELECT ".$fname." FROM ".$tablename;
$data = array_combine($listfields, $listvalues);
$where = array();
@ -842,6 +849,7 @@ class ImportCsv extends ModeleImports
if ($num_rows == 1) {
$res = $this->db->fetch_object($resql);
$lastinsertid = $res->rowid;
if ($is_table_category_link) $lastinsertid = 'linktable'; // used to apply update on tables like llx_categorie_product and avoid being blocked for all file content if at least one entry already exists
$last_insert_id_array[$tablename] = $lastinsertid;
} elseif ($num_rows > 1) {
$this->errors[$error]['lib'] = $langs->trans('MultipleRecordFoundWithTheseFilters', implode(', ', $filters));
@ -903,6 +911,10 @@ class ImportCsv extends ModeleImports
}
$sqlend = " WHERE ".$keyfield." = ".((int) $lastinsertid);
if ($is_table_category_link) {
$sqlend = " WHERE " . implode(' AND ', $where);
}
$sql = $sqlstart.$sqlend;
// Run update request

View File

@ -863,11 +863,19 @@ class ImportXlsx extends ModeleImports
if (!empty($listfields)) {
$updatedone = false;
$insertdone = false;
$is_table_category_link = false;
$fname = 'rowid';
if (strpos($tablename, '_categorie_') !== false) {
$is_table_category_link = true;
$fname='*';
}
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)) { // No insert done yet for a parent table
$sqlSelect = "SELECT rowid FROM " . $tablename;
$sqlSelect = "SELECT ".$fname." FROM " . $tablename;
$data = array_combine($listfields, $listvalues);
$where = array();
@ -886,6 +894,7 @@ class ImportXlsx extends ModeleImports
if ($num_rows == 1) {
$res = $this->db->fetch_object($resql);
$lastinsertid = $res->rowid;
if ($is_table_category_link) $lastinsertid = 'linktable'; // used to apply update on tables like llx_categorie_product and avoid being blocked for all file content if at least one entry already exists
$last_insert_id_array[$tablename] = $lastinsertid;
} elseif ($num_rows > 1) {
$this->errors[$error]['lib'] = $langs->trans('MultipleRecordFoundWithTheseFilters', implode(', ', $filters));
@ -947,6 +956,10 @@ class ImportXlsx extends ModeleImports
}
$sqlend = " WHERE " . $keyfield . " = ".((int) $lastinsertid);
if ($is_table_category_link) {
$sqlend = " WHERE " . implode(' AND ', $where);
}
$sql = $sqlstart . $sqlend;
// Run update request

View File

@ -481,6 +481,7 @@ class modCategorie extends DolibarrModules
'cp.fk_product'=>array('rule'=>'fetchidfromref', 'classfile'=>'/product/class/product.class.php', 'class'=>'Product', 'method'=>'fetch', 'element'=>'Product')
);
$this->import_examplevalues_array[$r] = array('cp.fk_categorie'=>"rowid or label", 'cp.fk_product'=>"rowid or ref");
$this->import_updatekeys_array[$r] = array('cp.fk_categorie' => 'Category', 'cp.fk_product' => 'ProductRef');
}
// 1 Suppliers