FIX Import process must stop after ending line nb to import
This commit is contained in:
parent
7f419a29e7
commit
2d252e85e6
@ -225,7 +225,7 @@ if ($step == 3 && $datatoimport)
|
||||
$param='&datatoimport='.$datatoimport.'&format='.$format;
|
||||
if ($excludefirstline) $param.='&excludefirstline='.$excludefirstline;
|
||||
if ($endatlinenb) $param.='&endatlinenb='.$endatlinenb;
|
||||
|
||||
|
||||
$file = $conf->import->dir_temp . '/' . GETPOST('urlfile'); // Do not use urldecode here ($_GET and $_REQUEST are already decoded by PHP).
|
||||
$ret=dol_delete_file($file);
|
||||
if ($ret) setEventMessages($langs->trans("FileWasRemoved", GETPOST('urlfile')), null, 'mesgs');
|
||||
@ -429,9 +429,9 @@ if ($step == 2 && $datatoimport)
|
||||
print '</table>';
|
||||
|
||||
print '</div><br>';
|
||||
|
||||
|
||||
dol_fiche_end();
|
||||
|
||||
|
||||
|
||||
print '<form name="userfile" action="'.$_SERVER["PHP_SELF"].'" enctype="multipart/form-data" METHOD="POST">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
@ -450,7 +450,7 @@ if ($step == 2 && $datatoimport)
|
||||
$liste=$objmodelimport->liste_modeles($db);
|
||||
foreach($liste as $key)
|
||||
{
|
||||
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
print '<td width="16">'.img_picto_common($key,$objmodelimport->getPictoForKey($key)).'</td>';
|
||||
$text=$objmodelimport->getDriverDescForKey($key);
|
||||
@ -495,7 +495,7 @@ if ($step == 3 && $datatoimport)
|
||||
|
||||
print '<div class="underbanner clearboth"></div>';
|
||||
print '<div class="fichecenter">';
|
||||
|
||||
|
||||
print '<table width="100%" class="border">';
|
||||
|
||||
// Module
|
||||
@ -516,11 +516,11 @@ if ($step == 3 && $datatoimport)
|
||||
|
||||
print '</table>';
|
||||
print '</div>';
|
||||
|
||||
|
||||
print '<br>';
|
||||
|
||||
|
||||
print '<b>'.$langs->trans("InformationOnSourceFile").'</b>';
|
||||
|
||||
|
||||
print '<div class="underbanner clearboth"></div>';
|
||||
print '<div class="fichecenter">';
|
||||
print '<table width="100%" class="border">';
|
||||
@ -537,15 +537,15 @@ if ($step == 3 && $datatoimport)
|
||||
|
||||
print '</table>';
|
||||
print '</div>';
|
||||
|
||||
|
||||
dol_fiche_end();
|
||||
|
||||
print '<br>';
|
||||
|
||||
|
||||
print '<form name="userfile" action="'.$_SERVER["PHP_SELF"].'" enctype="multipart/form-data" METHOD="POST">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
print '<input type="hidden" name="max_file_size" value="'.$conf->maxfilesize.'">';
|
||||
|
||||
|
||||
print '<input type="hidden" value="'.$step.'" name="step">';
|
||||
print '<input type="hidden" value="'.$format.'" name="format">';
|
||||
print '<input type="hidden" value="'.$excludefirstline.'" name="excludefirstline">';
|
||||
@ -553,7 +553,7 @@ if ($step == 3 && $datatoimport)
|
||||
print '<input type="hidden" value="'.$separator.'" name="separator">';
|
||||
print '<input type="hidden" value="'.$enclosure.'" name="enclosure">';
|
||||
print '<input type="hidden" value="'.$datatoimport.'" name="datatoimport">';
|
||||
|
||||
|
||||
print '<table class="noborder" width="100%" cellspacing="0" cellpadding="4">';
|
||||
|
||||
$filetoimport='';
|
||||
@ -613,7 +613,7 @@ if ($step == 3 && $datatoimport)
|
||||
$modulepart='import';
|
||||
$urlsource=$_SERVER["PHP_SELF"].'?step='.$step.$param.'&filetoimport='.urlencode($filetoimport);
|
||||
$relativepath=$file;
|
||||
|
||||
|
||||
print '<tr class="oddeven">';
|
||||
print '<td width="16">'.img_mime($file).'</td>';
|
||||
print '<td>';
|
||||
@ -665,9 +665,9 @@ if ($step == 4 && $datatoimport)
|
||||
header("Location: ".$_SERVER["PHP_SELF"].'?step=3'.$param.'&filetoimport='.urlencode($relativepath));
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (GETPOST('update')) {
|
||||
$array_match_file_to_database=array();
|
||||
}
|
||||
@ -772,9 +772,9 @@ if ($step == 4 && $datatoimport)
|
||||
|
||||
print '</table>';
|
||||
print '</div>';
|
||||
|
||||
|
||||
print '<br>';
|
||||
|
||||
|
||||
print '<b>'.$langs->trans("InformationOnSourceFile").'</b>';
|
||||
print '<div class="underbanner clearboth"></div>';
|
||||
print '<div class="fichecenter">';
|
||||
@ -820,9 +820,9 @@ if ($step == 4 && $datatoimport)
|
||||
|
||||
print '</table>';
|
||||
print '</div>';
|
||||
|
||||
|
||||
dol_fiche_end();
|
||||
|
||||
|
||||
print '<br>'."\n";
|
||||
|
||||
|
||||
@ -873,7 +873,7 @@ if ($step == 4 && $datatoimport)
|
||||
$lefti=1;
|
||||
foreach ($array_match_file_to_database as $key => $val)
|
||||
{
|
||||
|
||||
|
||||
show_elem($fieldssource,$key,$val,$var); // key is field number in source file
|
||||
//print '> '.$lefti.'-'.$key.'-'.$val;
|
||||
$listofkeys[$key]=1;
|
||||
@ -890,7 +890,7 @@ if ($step == 4 && $datatoimport)
|
||||
$num=count($fieldssource);
|
||||
while ($lefti <= $num)
|
||||
{
|
||||
|
||||
|
||||
$newkey=getnewkey($fieldssource,$listofkeys);
|
||||
show_elem($fieldssource,$newkey,'',$var); // key start after field number in source file
|
||||
//print '> '.$lefti.'-'.$newkey;
|
||||
@ -913,7 +913,7 @@ if ($step == 4 && $datatoimport)
|
||||
print '<table width="100%" class="nobordernopadding">';
|
||||
foreach($fieldstarget as $code=>$label)
|
||||
{
|
||||
|
||||
|
||||
print '<tr '.$bc[$var].' height="'.$height.'">';
|
||||
|
||||
$i++;
|
||||
@ -1148,7 +1148,7 @@ if ($step == 4 && $datatoimport)
|
||||
$var=false;
|
||||
while ($i < $num)
|
||||
{
|
||||
|
||||
|
||||
$obj = $db->fetch_object($resql);
|
||||
print '<tr class="oddeven"><td>';
|
||||
print $obj->label;
|
||||
@ -1213,16 +1213,16 @@ if ($step == 5 && $datatoimport)
|
||||
if ($excludefirstline) $param.='&excludefirstline='.$excludefirstline;
|
||||
if ($endatlinenb) $param.='&endatlinenb='.$endatlinenb;
|
||||
if (!empty($updatekeys)) $param.='&updatekeys[]='.implode('&updatekeys[]=', $updatekeys);
|
||||
|
||||
|
||||
llxHeader('',$langs->trans("NewImport"),'EN:Module_Imports_En|FR:Module_Imports|ES:Módulo_Importaciones');
|
||||
|
||||
$head = import_prepare_head($param,5);
|
||||
|
||||
|
||||
|
||||
print '<form action="'.$_SERVER["PHP_SELF"].'?'.$param2.'" method="POST">';
|
||||
print '<input type="hidden" name="step" value="5">'; // step 5
|
||||
print '<input type="hidden" name="action" value="launchsimu">'; // step 5
|
||||
|
||||
|
||||
dol_fiche_head($head, 'step5', $langs->trans("NewImport"), -1);
|
||||
|
||||
print '<div class="underbanner clearboth"></div>';
|
||||
@ -1248,9 +1248,9 @@ if ($step == 5 && $datatoimport)
|
||||
|
||||
print '</table>';
|
||||
print '</div>';
|
||||
|
||||
|
||||
print '<br>';
|
||||
|
||||
|
||||
print '<b>'.$langs->trans("InformationOnSourceFile").'</b>';
|
||||
print '<div class="underbanner clearboth"></div>';
|
||||
print '<div class="fichecenter">';
|
||||
@ -1274,7 +1274,7 @@ if ($step == 5 && $datatoimport)
|
||||
print htmlentities($enclosure);
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
|
||||
// File to import
|
||||
print '<tr><td>'.$langs->trans("FileToImport").'</td>';
|
||||
print '<td>';
|
||||
@ -1351,16 +1351,16 @@ if ($step == 5 && $datatoimport)
|
||||
print_r($objimport->array_import_updatekeys);
|
||||
echo '</pre>';*/
|
||||
print '</td></tr>';
|
||||
|
||||
|
||||
print '</table>';
|
||||
print '</div>';
|
||||
|
||||
|
||||
print '<br>';
|
||||
|
||||
print '<b>'.$langs->trans("InformationOnTargetTables").'</b>';
|
||||
print '<div class="underbanner clearboth"></div>';
|
||||
print '<div class="fichecenter">';
|
||||
|
||||
|
||||
print '<table width="100%" class="border">';
|
||||
//print '<tr><td colspan="2"><b>'.$langs->trans("InformationOnTargetTables").'</b></td></tr>';
|
||||
|
||||
@ -1426,7 +1426,7 @@ if ($step == 5 && $datatoimport)
|
||||
|
||||
print '</table>';
|
||||
print '</div>';
|
||||
|
||||
|
||||
dol_fiche_end();
|
||||
|
||||
|
||||
@ -1475,10 +1475,11 @@ if ($step == 5 && $datatoimport)
|
||||
$sourcelinenb=0; $endoffile=0;
|
||||
|
||||
// Loop on each input file record
|
||||
while ($sourcelinenb < $nboflines && ! $endoffile)
|
||||
while (($sourcelinenb < $nboflines) && ! $endoffile)
|
||||
{
|
||||
$sourcelinenb++;
|
||||
// Read line and stor it into $arrayrecord
|
||||
//dol_syslog("line ".$sourcelinenb.' - '.$nboflines.' - '.$excludefirstline.' - '.$endatlinenb);
|
||||
$arrayrecord=$obj->import_read_record();
|
||||
if ($arrayrecord === false)
|
||||
{
|
||||
@ -1487,11 +1488,11 @@ if ($step == 5 && $datatoimport)
|
||||
continue;
|
||||
}
|
||||
if ($excludefirstline && ($sourcelinenb < $excludefirstline)) continue;
|
||||
if ($endatlinenb && ($sourcelinenb > $endatlinenb)) continue;
|
||||
|
||||
if ($endatlinenb && ($sourcelinenb > $endatlinenb)) break;
|
||||
|
||||
// Run import
|
||||
$result=$obj->import_insert($arrayrecord,$array_match_file_to_database,$objimport,count($fieldssource),$importid,$updatekeys);
|
||||
|
||||
|
||||
if (count($obj->errors)) $arrayoferrors[$sourcelinenb]=$obj->errors;
|
||||
if (count($obj->warnings)) $arrayofwarnings[$sourcelinenb]=$obj->warnings;
|
||||
if (! count($obj->errors) && ! count($obj->warnings)) $nbok++;
|
||||
@ -1505,7 +1506,7 @@ if ($step == 5 && $datatoimport)
|
||||
}
|
||||
|
||||
$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]))
|
||||
@ -1515,14 +1516,14 @@ if ($step == 5 && $datatoimport)
|
||||
{
|
||||
$i++;
|
||||
$resqlafterimport=$db->query($sqlafterimport);
|
||||
if (! $resqlafterimport)
|
||||
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
|
||||
@ -1613,7 +1614,7 @@ if ($step == 5 && $datatoimport)
|
||||
print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->transnoentitiesnoconv("NotEnoughPermissions")).'">'.$langs->trans("RunImportFile").'</a>';
|
||||
}
|
||||
print '</div>';
|
||||
|
||||
|
||||
}
|
||||
|
||||
print '</form>';
|
||||
@ -1690,9 +1691,9 @@ if ($step == 6 && $datatoimport)
|
||||
print '</td></tr>';
|
||||
|
||||
print '</table>';
|
||||
|
||||
|
||||
print '<br>';
|
||||
|
||||
|
||||
print '<b>'.$langs->trans("InformationOnSourceFile").'</b><hr>';
|
||||
print '<table width="100%" class="border">';
|
||||
//print '<tr><td colspan="2"><b>'.$langs->trans("InformationOnSourceFile").'</b></td></tr>';
|
||||
@ -1714,7 +1715,7 @@ if ($step == 6 && $datatoimport)
|
||||
print htmlentities($enclosure);
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
|
||||
// File to import
|
||||
print '<tr><td>'.$langs->trans("FileToImport").'</td>';
|
||||
print '<td>';
|
||||
@ -1745,7 +1746,7 @@ if ($step == 6 && $datatoimport)
|
||||
print '</td><td>';
|
||||
print '<input type="text" size="4" name="endatlinenb" disabled="disabled" value="'.$endatlinenb.'">';
|
||||
print '</td></tr>';
|
||||
|
||||
|
||||
print '</table>';
|
||||
|
||||
print '<br>';
|
||||
@ -1848,11 +1849,11 @@ if ($step == 6 && $datatoimport)
|
||||
continue;
|
||||
}
|
||||
if ($excludefirstline && ($sourcelinenb < $excludefirstline)) continue;
|
||||
if ($endatlinenb && ($sourcelinenb > $endatlinenb)) continue;
|
||||
if ($endatlinenb && ($sourcelinenb > $endatlinenb)) break;
|
||||
|
||||
// Run import
|
||||
$result=$obj->import_insert($arrayrecord,$array_match_file_to_database,$objimport,count($fieldssource),$importid,$updatekeys);
|
||||
|
||||
|
||||
if (count($obj->errors)) $arrayoferrors[$sourcelinenb]=$obj->errors;
|
||||
if (count($obj->warnings)) $arrayofwarnings[$sourcelinenb]=$obj->warnings;
|
||||
if (! count($obj->errors) && ! count($obj->warnings)) $nbok++;
|
||||
@ -1866,10 +1867,10 @@ if ($step == 6 && $datatoimport)
|
||||
}
|
||||
|
||||
if (count($arrayoferrors) > 0) $db->rollback(); // We force rollback because this was errors.
|
||||
else
|
||||
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]))
|
||||
@ -1879,18 +1880,18 @@ if ($step == 6 && $datatoimport)
|
||||
{
|
||||
$i++;
|
||||
$resqlafterimport=$db->query($sqlafterimport);
|
||||
if (! $resqlafterimport)
|
||||
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();
|
||||
|
||||
|
||||
@ -1930,7 +1931,7 @@ function show_elem($fieldssource,$pos,$key,$var,$nostyle='')
|
||||
global $langs,$bc;
|
||||
|
||||
$height='24';
|
||||
|
||||
|
||||
print "\n\n<!-- Box ".$pos." start -->\n";
|
||||
print '<div class="box" style="padding: 0px 0px 0px 0px;" id="boxto_'.$pos.'">'."\n";
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user