Work on import module
This commit is contained in:
parent
6031b66f89
commit
1514c5a6fa
@ -72,6 +72,7 @@ $step=isset($_GET["step"])? $_GET["step"] : (isset($_POST["step"])?$_POST["step"
|
|||||||
$import_name=isset($_POST["import_name"])? $_POST["import_name"] : '';
|
$import_name=isset($_POST["import_name"])? $_POST["import_name"] : '';
|
||||||
$hexa=isset($_POST["hexa"])? $_POST["hexa"] : '';
|
$hexa=isset($_POST["hexa"])? $_POST["hexa"] : '';
|
||||||
$importmodelid=isset($_POST["importmodelid"])? $_POST["importmodelid"] : '';
|
$importmodelid=isset($_POST["importmodelid"])? $_POST["importmodelid"] : '';
|
||||||
|
$excludefirstline=isset($_GET["excludefirstline"])? $_GET["excludefirstline"] : (isset($_POST["excludefirstline"])?$_POST["excludefirstline"]:0);
|
||||||
|
|
||||||
$objimport=new Import($db);
|
$objimport=new Import($db);
|
||||||
$objimport->load_arrays($user,$datatoimport);
|
$objimport->load_arrays($user,$datatoimport);
|
||||||
@ -1040,8 +1041,6 @@ if ($step == 4 && $datatoimport)
|
|||||||
// STEP 5: Summary of choices
|
// STEP 5: Summary of choices
|
||||||
if ($step == 5 && $datatoimport)
|
if ($step == 5 && $datatoimport)
|
||||||
{
|
{
|
||||||
if (empty($dontimportfirstline)) $dontimportfirstline=0;
|
|
||||||
|
|
||||||
$model=$format;
|
$model=$format;
|
||||||
$liste=$objmodelimport->liste_modeles($db);
|
$liste=$objmodelimport->liste_modeles($db);
|
||||||
|
|
||||||
@ -1072,7 +1071,8 @@ if ($step == 5 && $datatoimport)
|
|||||||
$nboflines=dol_count_nb_of_line($conf->import->dir_temp.'/'.$filetoimport);
|
$nboflines=dol_count_nb_of_line($conf->import->dir_temp.'/'.$filetoimport);
|
||||||
|
|
||||||
$param='&format='.$format.'&datatoimport='.$datatoimport.'&filetoimport='.urlencode($filetoimport).'&nboflines='.$nboflines;
|
$param='&format='.$format.'&datatoimport='.$datatoimport.'&filetoimport='.urlencode($filetoimport).'&nboflines='.$nboflines;
|
||||||
|
if ($excludefirstline) $param.='&excludefirstline=1';
|
||||||
|
|
||||||
llxHeader('',$langs->trans("NewImport"),'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones');
|
llxHeader('',$langs->trans("NewImport"),'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones');
|
||||||
|
|
||||||
$h = 0;
|
$h = 0;
|
||||||
@ -1149,7 +1149,9 @@ if ($step == 5 && $datatoimport)
|
|||||||
print '<tr><td>';
|
print '<tr><td>';
|
||||||
print $langs->trans("DoNotImportFirstLine");
|
print $langs->trans("DoNotImportFirstLine");
|
||||||
print '</td><td>';
|
print '</td><td>';
|
||||||
print '<input type="checkbox" name="nofirstline" value='.$dontimportfirstline.'>';
|
print '<input type="checkbox" name="excludefirstline" value="1"';
|
||||||
|
print ($excludefirstline?' checked="true"':'');
|
||||||
|
print '>';
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|
||||||
print '</table>';
|
print '</table>';
|
||||||
@ -1247,8 +1249,6 @@ if ($step == 5 && $datatoimport)
|
|||||||
// STEP 6: Result of simulation
|
// STEP 6: Result of simulation
|
||||||
if ($step == 6 && $datatoimport)
|
if ($step == 6 && $datatoimport)
|
||||||
{
|
{
|
||||||
if (empty($dontimportfirstline)) $dontimportfirstline=0;
|
|
||||||
|
|
||||||
$model=$format;
|
$model=$format;
|
||||||
$liste=$objmodelimport->liste_modeles($db);
|
$liste=$objmodelimport->liste_modeles($db);
|
||||||
|
|
||||||
@ -1279,7 +1279,8 @@ if ($step == 6 && $datatoimport)
|
|||||||
$nboflines=(! empty($_GET["nboflines"])?$_GET["nboflines"]:dol_count_nb_of_line($conf->import->dir_temp.'/'.$filetoimport));
|
$nboflines=(! empty($_GET["nboflines"])?$_GET["nboflines"]:dol_count_nb_of_line($conf->import->dir_temp.'/'.$filetoimport));
|
||||||
|
|
||||||
$param='&format='.$format.'&datatoimport='.$datatoimport.'&filetoimport='.urlencode($filetoimport).'&nboflines='.$nboflines;
|
$param='&format='.$format.'&datatoimport='.$datatoimport.'&filetoimport='.urlencode($filetoimport).'&nboflines='.$nboflines;
|
||||||
|
if ($excludefirstline) $param.='&excludefirstline=1';
|
||||||
|
|
||||||
llxHeader('',$langs->trans("NewImport"),'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones');
|
llxHeader('',$langs->trans("NewImport"),'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones');
|
||||||
|
|
||||||
$h = 0;
|
$h = 0;
|
||||||
@ -1360,7 +1361,9 @@ if ($step == 6 && $datatoimport)
|
|||||||
print '<tr><td>';
|
print '<tr><td>';
|
||||||
print $langs->trans("DoNotImportFirstLine");
|
print $langs->trans("DoNotImportFirstLine");
|
||||||
print '</td><td>';
|
print '</td><td>';
|
||||||
print '<input type="checkbox" name="nofirstline" value='.$dontimportfirstline.'>';
|
print '<input type="checkbox" name="excludefirstline" value="1"';
|
||||||
|
print ($excludefirstline?' checked="true"':'');
|
||||||
|
print '>';
|
||||||
print '</td></tr>';
|
print '</td></tr>';
|
||||||
|
|
||||||
print '</table>';
|
print '</table>';
|
||||||
@ -1432,8 +1435,8 @@ if ($step == 6 && $datatoimport)
|
|||||||
// Launch import
|
// Launch import
|
||||||
$arrayoferrors=array();
|
$arrayoferrors=array();
|
||||||
$arrayofwarnings=array();
|
$arrayofwarnings=array();
|
||||||
$maxnboferrors=empty($conf->global->IMPORT_MAX_NB_OF_ERRORS)?100:$conf->global->IMPORT_MAX_NB_OF_ERRORS;
|
$maxnboferrors=empty($conf->global->IMPORT_MAX_NB_OF_ERRORS)?50:$conf->global->IMPORT_MAX_NB_OF_ERRORS;
|
||||||
$maxnbofwarnings=empty($conf->global->IMPORT_MAX_NB_OF_WARNINGS)?100:$conf->global->IMPORT_MAX_NB_OF_WARNINGS;
|
$maxnbofwarnings=empty($conf->global->IMPORT_MAX_NB_OF_WARNINGS)?50:$conf->global->IMPORT_MAX_NB_OF_WARNINGS;
|
||||||
$nboferrors=0;
|
$nboferrors=0;
|
||||||
$nbofwarnings=0;
|
$nbofwarnings=0;
|
||||||
|
|
||||||
@ -1453,6 +1456,8 @@ if ($step == 6 && $datatoimport)
|
|||||||
while ($arrayrecord=$obj->import_read_record())
|
while ($arrayrecord=$obj->import_read_record())
|
||||||
{
|
{
|
||||||
$sourcelinenb++;
|
$sourcelinenb++;
|
||||||
|
if ($excludefirstline && $sourcelinenb == 1) continue;
|
||||||
|
|
||||||
$result=$obj->import_insert($arrayrecord,$array_match_file_to_database,$objimport,sizeof($fieldssource),$importid);
|
$result=$obj->import_insert($arrayrecord,$array_match_file_to_database,$objimport,sizeof($fieldssource),$importid);
|
||||||
if (sizeof($obj->errors))
|
if (sizeof($obj->errors))
|
||||||
{
|
{
|
||||||
@ -1473,13 +1478,54 @@ if ($step == 6 && $datatoimport)
|
|||||||
|
|
||||||
$db->rollback(); // We force rollback because this was just a simulation.
|
$db->rollback(); // We force rollback because this was just a simulation.
|
||||||
|
|
||||||
var_dump($arrayoferrors);
|
// Errors
|
||||||
// Print result $arrayoferrors
|
//var_dump($arrayoferrors);
|
||||||
foreach ($arrayoferrors as $key => $val)
|
print '<b>'.$langs->trans("Errors").'</b>';
|
||||||
|
print '<hr>';
|
||||||
|
if (sizeof($arrayoferrors))
|
||||||
{
|
{
|
||||||
//print $langs->trans("Result".$key)." ".$arrayofresult[$key].'<br>';
|
foreach ($arrayoferrors as $key => $val)
|
||||||
|
{
|
||||||
|
$nboferrors++;
|
||||||
|
if ($nboferrors > $maxnboferrors)
|
||||||
|
{
|
||||||
|
print $langs->trans("TooMuchErrors",(sizeof($arrayoferrors)-$nboferrors))."<br>";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
print '* '.$langs->trans("Line").' '.$key.'<br>';
|
||||||
|
foreach($val as $i => $err)
|
||||||
|
{
|
||||||
|
print ' - '.$err['lib'].'<br>';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
else print $langs->trans("None");
|
||||||
|
|
||||||
|
print '<br>';
|
||||||
|
|
||||||
|
// Warnings
|
||||||
|
//var_dump($arrayoferrors);
|
||||||
|
print '<b>'.$langs->trans("Warnings").'</b>';
|
||||||
|
print '<hr>';
|
||||||
|
if (sizeof($arrayofwarnings))
|
||||||
|
{
|
||||||
|
foreach ($arrayofwarnings as $key => $val)
|
||||||
|
{
|
||||||
|
$nbofwarnings++;
|
||||||
|
if ($nbofwarnings > $maxnbofwarnings)
|
||||||
|
{
|
||||||
|
print $langs->trans("TooMuchWarnings",(sizeof($arrayofwarnings)-$nbofwarnings))."<br>";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
print ' * '.$langs->trans("Line").' '.$key.'<br>';
|
||||||
|
foreach($val as $i => $err)
|
||||||
|
{
|
||||||
|
print ' - '.$err['lib'].'<br>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else print $langs->trans("None");
|
||||||
|
|
||||||
$importid=dol_print_date(dol_now('tzserver'),'%Y%m%d%H%M%S');
|
$importid=dol_print_date(dol_now('tzserver'),'%Y%m%d%H%M%S');
|
||||||
|
|
||||||
print '<br>';
|
print '<br>';
|
||||||
@ -1492,7 +1538,14 @@ if ($step == 6 && $datatoimport)
|
|||||||
print '<center>';
|
print '<center>';
|
||||||
if ($user->rights->import->run)
|
if ($user->rights->import->run)
|
||||||
{
|
{
|
||||||
print '<a class="butAction" href="'.DOL_URL_ROOT.'/imports/import.php?leftmenu=import&step=7&'.$param.'">'.$langs->trans("RunImportFile").'</a>';
|
if (empty($nboferrors))
|
||||||
|
{
|
||||||
|
print '<a class="butAction" href="'.DOL_URL_ROOT.'/imports/import.php?leftmenu=import&step=7&'.$param.'">'.$langs->trans("RunImportFile").'</a>';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("CorrectErrorBeforeRunningImport")).'">'.$langs->trans("RunImportFile").'</a>';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -272,6 +272,8 @@ class ImportCsv extends ModeleImports
|
|||||||
*/
|
*/
|
||||||
function import_insert($arrayrecord,$array_match_file_to_database,$objimport,$maxfields,$importid)
|
function import_insert($arrayrecord,$array_match_file_to_database,$objimport,$maxfields,$importid)
|
||||||
{
|
{
|
||||||
|
global $langs,$conf;
|
||||||
|
|
||||||
$error=0;
|
$error=0;
|
||||||
$warning=0;
|
$warning=0;
|
||||||
$this->errors=array();
|
$this->errors=array();
|
||||||
@ -288,8 +290,8 @@ class ImportCsv extends ModeleImports
|
|||||||
if (sizeof($arrayrecord) == 0 ||
|
if (sizeof($arrayrecord) == 0 ||
|
||||||
(sizeof($arrayrecord) == 1 && empty($arrayrecord[0]['val'])))
|
(sizeof($arrayrecord) == 1 && empty($arrayrecord[0]['val'])))
|
||||||
{
|
{
|
||||||
print 'W';
|
//print 'W';
|
||||||
$this->warnings[$warning]['lib']='Empty line';
|
$this->warnings[$warning]['lib']=$langs->trans('EmptyLine');
|
||||||
$this->warnings[$warning]['type']='EMPTY';
|
$this->warnings[$warning]['type']='EMPTY';
|
||||||
$warning++;
|
$warning++;
|
||||||
}
|
}
|
||||||
@ -310,7 +312,7 @@ class ImportCsv extends ModeleImports
|
|||||||
if ($key <= $maxfields)
|
if ($key <= $maxfields)
|
||||||
{
|
{
|
||||||
if ($listfields) { $listfields.=', '; $listvalues.=', '; }
|
if ($listfields) { $listfields.=', '; $listvalues.=', '; }
|
||||||
$listfields.=$val;
|
$listfields.=eregi_replace('^.*\.','',$val);
|
||||||
$newval='';
|
$newval='';
|
||||||
if ($arrayrecord[($key-1)]['type'] < 0)
|
if ($arrayrecord[($key-1)]['type'] < 0)
|
||||||
{
|
{
|
||||||
@ -331,7 +333,7 @@ class ImportCsv extends ModeleImports
|
|||||||
// Required field is ok
|
// Required field is ok
|
||||||
if (eregi('\*',$objimport->array_import_fields[0][$val]) && empty($newval))
|
if (eregi('\*',$objimport->array_import_fields[0][$val]) && empty($newval))
|
||||||
{
|
{
|
||||||
$this->errors[$error]['lib']='ErrorMissingMandatoryValue field nb '.$key.' target='.$val;
|
$this->errors[$error]['lib']=$langs->trans('ErrorMissingMandatoryValue',$key);
|
||||||
$this->errors[$error]['type']='NOTNULL';
|
$this->errors[$error]['type']='NOTNULL';
|
||||||
$errorforthistable++;
|
$errorforthistable++;
|
||||||
$error++;
|
$error++;
|
||||||
@ -349,7 +351,7 @@ class ImportCsv extends ModeleImports
|
|||||||
{
|
{
|
||||||
if ($listfields)
|
if ($listfields)
|
||||||
{
|
{
|
||||||
$sql='INSERT INTO '.$tablename.'('.$listfields.') VALUES('.$listvalues.')';
|
$sql='INSERT INTO '.$tablename.'('.$listfields.',import_key) VALUES('.$listvalues.",'".$importid."')";
|
||||||
dol_syslog("import_csv.modules sql=".$sql);
|
dol_syslog("import_csv.modules sql=".$sql);
|
||||||
|
|
||||||
//print '> '.join(',',$arrayrecord);
|
//print '> '.join(',',$arrayrecord);
|
||||||
@ -362,12 +364,13 @@ class ImportCsv extends ModeleImports
|
|||||||
$resql=$this->db->query($sql);
|
$resql=$this->db->query($sql);
|
||||||
if ($resql)
|
if ($resql)
|
||||||
{
|
{
|
||||||
print '.';
|
//print '.';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
print 'E';
|
//print 'E';
|
||||||
$this->errors[$error]['lib']='ErrorSQL '.$this->db->lasterror();
|
print $sql;
|
||||||
|
$this->errors[$error]['lib']=$this->db->lasterror();
|
||||||
$this->errors[$error]['type']='SQL';
|
$this->errors[$error]['type']='SQL';
|
||||||
$error++;
|
$error++;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -86,3 +86,8 @@ SelectFormat=Choose this import file format
|
|||||||
RunImportFile=Launch import file
|
RunImportFile=Launch import file
|
||||||
NowClickToRunTheImport=Check result of import simulation. If everything is ok, launch the definitive import.
|
NowClickToRunTheImport=Check result of import simulation. If everything is ok, launch the definitive import.
|
||||||
DataLoadedWithId=All data will be loaded with the following import id: <b>%s<b>
|
DataLoadedWithId=All data will be loaded with the following import id: <b>%s<b>
|
||||||
|
ErrorMissingMandatoryValue=Mandatory data is empty in source file for field <b>%s</b>.
|
||||||
|
TooMuchErrors=There is still <b>%s</b> other source lines with errors but output has been limited.
|
||||||
|
TooMuchWarnings=There is still <b>%s</b> other source lines with warnings but output has been limited.
|
||||||
|
EmptyLine=Empty line
|
||||||
|
CorrectErrorBeforeRunningImport=You must first correct all errors before running definitive import.
|
||||||
@ -85,4 +85,9 @@ SelectAtLeastOneField=Basculer au moins un champ source dans la colonne des cham
|
|||||||
SelectFormat=Choisir ce format de fichier import
|
SelectFormat=Choisir ce format de fichier import
|
||||||
RunImportFile=Lancer l'import en base
|
RunImportFile=Lancer l'import en base
|
||||||
NowClickToRunTheImport=Vérifiez le résultat de la simulation. Si tout est ok, lancer l'import définitif en base.
|
NowClickToRunTheImport=Vérifiez le résultat de la simulation. Si tout est ok, lancer l'import définitif en base.
|
||||||
DataLoadedWithId=Toutes les données seront importées avec l'id d'import suivant: <b>%s</b>
|
DataLoadedWithId=Toutes les données seront importées avec l'id d'import suivant: <b>%s</b>
|
||||||
|
ErrorMissingMandatoryValue=Donnée obligatoire non renseignées dans le fichier source, champ numéro <b>%s</b>.
|
||||||
|
TooMuchErrors=Il y a encore <b>%s</b> autres lignes en erreur mais leur affichage a été limité.
|
||||||
|
TooMuchWarnings=Il y a encore <b>%s</b> autres lignes en warnings mais leur affichage a été limité.
|
||||||
|
EmptyLine=Ligne vide
|
||||||
|
CorrectErrorBeforeRunningImport=Vous devez d'abord corriger toutes les erreurs avant de pouvoir lancer l'import définitif.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user