NEW A module can add, into its import profiles, a sql request to execute
at end of import. This allow to update dernormalized data after import.
This commit is contained in:
parent
3678e05270
commit
b60e90a7b7
@ -194,8 +194,12 @@ class modStock extends DolibarrModules
|
||||
$this->import_convertvalue_array[$r]=array(
|
||||
'ps.fk_product'=>array('rule'=>'fetchidfromref','classfile'=>'/product/class/product.class.php','class'=>'Product','method'=>'fetch','element'=>'product'),
|
||||
'ps.fk_entrepot'=>array('rule'=>'fetchidfromref','classfile'=>'/product/stock/class/entrepot.class.php','class'=>'Entrepot','method'=>'fetch','element'=>'label')
|
||||
);
|
||||
$this->import_examplevalues_array[$r]=array(
|
||||
'ps.fk_product'=>"PREF123456",'ps.fk_entrepot'=>"ALM001",'ps.reel'=>"10"
|
||||
);
|
||||
$this->import_examplevalues_array[$r]=array('ps.fk_product'=>"PREF123456",'ps.fk_entrepot'=>"ALM001",'ps.reel'=>"10"
|
||||
$this->import_run_sql_after_array[$r]=array( // Because we may change data that are denormalized, we must update dernormalized data after.
|
||||
'UPDATE llx_product p SET p.stock= (SELECT SUM(ps.reel) FROM llx_product_stock ps WHERE ps.fk_product = p.rowid);'
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@ -38,6 +38,7 @@ class Import
|
||||
var $array_import_regex;
|
||||
var $array_import_examplevalues;
|
||||
var $array_import_convertvalue;
|
||||
var $array_import_run_sql_after;
|
||||
|
||||
|
||||
/**
|
||||
@ -151,6 +152,8 @@ class Import
|
||||
$this->array_import_examplevalues[$i]=$module->import_examplevalues_array[$r];
|
||||
// Tableau des regles de conversion d'une valeur depuis une autre source (cle=champ, valeur=tableau des regles)
|
||||
$this->array_import_convertvalue[$i]=(isset($module->import_convertvalue_array[$r])?$module->import_convertvalue_array[$r]:'');
|
||||
// Sql request to run after import
|
||||
$this->array_import_run_sql_after[$i]=(isset($module->import_run_sql_after_array[$r])?$module->import_run_sql_after_array[$r]:'');
|
||||
// Module
|
||||
$this->array_import_module[$i]=$module;
|
||||
|
||||
|
||||
@ -1415,6 +1415,25 @@ if ($step == 5 && $datatoimport)
|
||||
print $langs->trans("ErrorFailedToOpenFile",$pathfile);
|
||||
}
|
||||
|
||||
$error=0;
|
||||
|
||||
// Run the sql after import if defined
|
||||
//var_dump($objimport->array_import_run_sql_after[0]);
|
||||
if (! empty($objimport->array_import_run_sql_after[0]) && is_array($objimport->array_import_run_sql_after[0]))
|
||||
{
|
||||
$i=0;
|
||||
foreach($objimport->array_import_run_sql_after[0] as $sqlafterimport)
|
||||
{
|
||||
$i++;
|
||||
$resqlafterimport=$db->query($sqlafterimport);
|
||||
if (! $resqlafterimport)
|
||||
{
|
||||
$arrayoferrors['none'][]=array('lib'=>$langs->trans("Error running final request: ".$sqlafterimport));
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$db->rollback(); // We force rollback because this was just a simulation.
|
||||
|
||||
// Show OK
|
||||
@ -1740,8 +1759,31 @@ if ($step == 6 && $datatoimport)
|
||||
}
|
||||
|
||||
if (count($arrayoferrors) > 0) $db->rollback(); // We force rollback because this was errors.
|
||||
else $db->commit(); // We can commit if no errors.
|
||||
|
||||
else
|
||||
{
|
||||
$error=0;
|
||||
|
||||
// Run the sql after import if defined
|
||||
//var_dump($objimport->array_import_run_sql_after[0]);
|
||||
if (! empty($objimport->array_import_run_sql_after[0]) && is_array($objimport->array_import_run_sql_after[0]))
|
||||
{
|
||||
$i=0;
|
||||
foreach($objimport->array_import_run_sql_after[0] as $sqlafterimport)
|
||||
{
|
||||
$i++;
|
||||
$resqlafterimport=$db->query($sqlafterimport);
|
||||
if (! $resqlafterimport)
|
||||
{
|
||||
$arrayoferrors['none'][]=array('lib'=>$langs->trans("Error running final request: ".$sqlafterimport));
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (! $error) $db->commit(); // We can commit if no errors.
|
||||
else $db->rollback();
|
||||
}
|
||||
|
||||
dol_fiche_end();
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user