forked from Wavyzz/dolibarr
NEW map table to element for get entity in import
This commit is contained in:
@@ -96,6 +96,8 @@ class ImportCsv extends ModeleImports
|
||||
public function __construct($db, $datatoimport)
|
||||
{
|
||||
global $conf, $langs;
|
||||
|
||||
parent::__construct();
|
||||
$this->db = $db;
|
||||
|
||||
$this->separator = (GETPOST('separator') ?GETPOST('separator') : (empty($conf->global->IMPORT_CSV_SEPARATOR_TO_USE) ? ',' : $conf->global->IMPORT_CSV_SEPARATOR_TO_USE));
|
||||
@@ -871,8 +873,8 @@ class ImportCsv extends ModeleImports
|
||||
}
|
||||
}
|
||||
if (!empty($tablewithentity_cache[$tablename])) {
|
||||
$where[] = "entity = ".((int) $conf->entity);
|
||||
$filters[] = "entity = ".((int) $conf->entity);
|
||||
$where[] = "entity IN (".getEntity($this->getElementFromTableWithPrefix($tablename)).")";
|
||||
$filters[] = "entity IN (".getEntity($this->getElementFromTableWithPrefix($tablename)).")";
|
||||
}
|
||||
$sqlSelect .= " WHERE ".implode(' AND ', $where);
|
||||
|
||||
@@ -911,7 +913,7 @@ class ImportCsv extends ModeleImports
|
||||
$sqlSelect .= " WHERE ".$keyfield." = ".((int) $lastinsertid);
|
||||
|
||||
if (!empty($tablewithentity_cache[$tablename])) {
|
||||
$sqlSelect .= " AND entity = ".((int) $conf->entity);
|
||||
$sqlSelect .= " AND entity IN (".getEntity($this->getElementFromTableWithPrefix($tablename)).")";
|
||||
}
|
||||
|
||||
$resql = $this->db->query($sqlSelect);
|
||||
@@ -960,7 +962,7 @@ class ImportCsv extends ModeleImports
|
||||
}
|
||||
|
||||
if (!empty($tablewithentity_cache[$tablename])) {
|
||||
$sqlend .= " AND entity = ".((int) $conf->entity);
|
||||
$sqlend .= " AND entity IN (".getEntity($this->getElementFromTableWithPrefix($tablename)).")";
|
||||
}
|
||||
|
||||
$sql = $sqlstart.$sqlend;
|
||||
|
||||
@@ -106,6 +106,8 @@ class ImportXlsx extends ModeleImports
|
||||
public function __construct($db, $datatoimport)
|
||||
{
|
||||
global $conf, $langs;
|
||||
|
||||
parent::__construct();
|
||||
$this->db = $db;
|
||||
|
||||
// this is used as an extension from the example file code, so we have to put xlsx here !!!
|
||||
@@ -917,8 +919,8 @@ class ImportXlsx extends ModeleImports
|
||||
}
|
||||
}
|
||||
if (!empty($tablewithentity_cache[$tablename])) {
|
||||
$where[] = "entity = ".((int) $conf->entity);
|
||||
$filters[] = "entity = ".((int) $conf->entity);
|
||||
$where[] = "entity IN (".getEntity($this->getElementFromTableWithPrefix($tablename)).")";
|
||||
$filters[] = "entity IN (".getEntity($this->getElementFromTableWithPrefix($tablename)).")";
|
||||
}
|
||||
$sqlSelect .= " WHERE " . implode(' AND ', $where);
|
||||
|
||||
@@ -958,7 +960,7 @@ class ImportXlsx extends ModeleImports
|
||||
$sqlSelect .= " WHERE ".$keyfield." = ".((int) $lastinsertid);
|
||||
|
||||
if (!empty($tablewithentity_cache[$tablename])) {
|
||||
$sqlSelect .= " AND entity = ".((int) $conf->entity);
|
||||
$sqlSelect .= " AND entity IN (".getEntity($this->getElementFromTableWithPrefix($tablename)).")";
|
||||
}
|
||||
|
||||
$resql = $this->db->query($sqlSelect);
|
||||
@@ -1007,7 +1009,7 @@ class ImportXlsx extends ModeleImports
|
||||
}
|
||||
|
||||
if (!empty($tablewithentity_cache[$tablename])) {
|
||||
$sqlend .= " AND entity = ".((int) $conf->entity);
|
||||
$sqlend .= " AND entity IN (".getEntity($this->getElementFromTableWithPrefix($tablename)).")";
|
||||
}
|
||||
|
||||
$sql = $sqlstart . $sqlend;
|
||||
|
||||
@@ -75,14 +75,53 @@ class ModeleImports
|
||||
|
||||
public $libversion = array();
|
||||
|
||||
/**
|
||||
* @var array Element mapping from table name
|
||||
*/
|
||||
public static $mapTableToElement = array(
|
||||
'actioncomm' => 'agenda',
|
||||
'adherent' => 'member',
|
||||
'adherent_type' => 'member_type',
|
||||
'bank_account' => 'bank_account',
|
||||
'categorie' => 'category',
|
||||
'commande' => 'commande',
|
||||
'commande_fournisseur' => 'commande_fournisseur',
|
||||
'contrat' => 'contract',
|
||||
'entrepot' => 'stock',
|
||||
'expensereport' => 'expensereport',
|
||||
'facture' => 'invoice',
|
||||
'facture_fourn' => 'facture_fourn',
|
||||
'fichinter' => 'intervention',
|
||||
'holiday' => 'holiday',
|
||||
'product' => 'product',
|
||||
'productprice' => 'productprice',
|
||||
'product_fournisseur_price' => 'productsupplierprice',
|
||||
'projet' => 'project',
|
||||
'propal' => 'propal',
|
||||
'societe' => 'societe',
|
||||
'socpeople' => 'contact',
|
||||
'supplier_proposal' => 'supplier_proposal',
|
||||
'ticket' => 'ticket',
|
||||
);
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
global $hookmanager;
|
||||
|
||||
if (is_object($hookmanager)) {
|
||||
$hookmanager->initHooks(array('import'));
|
||||
$parameters = array();
|
||||
$reshook = $hookmanager->executeHooks('constructModeleImports', $parameters, $this);
|
||||
if ($reshook >= 0 && !empty($hookmanager->resArray)) {
|
||||
foreach ($hookmanager->resArray as $mapList) {
|
||||
self::$mapTableToElement[$mapList['table']] = $mapList['element'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* getDriverId
|
||||
@@ -269,4 +308,22 @@ class ModeleImports
|
||||
{
|
||||
return $this->libversion[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get element from table name with prefix
|
||||
*
|
||||
* @param string $tableNameWithPrefix Table name with prefix
|
||||
* @return string Element name or '' if not found
|
||||
*/
|
||||
public function getElementFromTableWithPrefix($tableNameWithPrefix)
|
||||
{
|
||||
$element = '';
|
||||
|
||||
$tableElement = preg_replace('/^'.preg_quote($this->db->prefix(), '/').'/', '', $tableNameWithPrefix);
|
||||
if (isset(self::$mapTableToElement[$tableElement])) {
|
||||
$element = self::$mapTableToElement[$tableElement];
|
||||
}
|
||||
|
||||
return $element;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user