From 578cab9a70e8e86752e9492320ef184d65884c82 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Sun, 2 Oct 2016 19:14:28 +0200 Subject: [PATCH] Error management + show nb insert/update + langs --- .../core/modules/import/import_csv.modules.php | 17 ++++++++++------- htdocs/imports/import.php | 8 ++++++-- htdocs/langs/en_US/exports.lang | 4 ++++ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/htdocs/core/modules/import/import_csv.modules.php b/htdocs/core/modules/import/import_csv.modules.php index bf923828c76..012ef84f5f1 100644 --- a/htdocs/core/modules/import/import_csv.modules.php +++ b/htdocs/core/modules/import/import_csv.modules.php @@ -54,6 +54,9 @@ class ImportCsv extends ModeleImports var $cacheconvert=array(); // Array to cache list of value found after a convertion var $cachefieldtable=array(); // Array to cache list of value found into fields@tables + + var $nbinsert = 0; // # of insert done during the import + var $nbupdate = 0; // # of update done during the import /** @@ -578,17 +581,18 @@ class ImportCsv extends ModeleImports // Run update request $resql=$this->db->query($sql); if($resql) { - echo $sql; - echo '
';
-								//print_r($this->db);
-								//print_r($this->db->db);
-								echo '
'; - echo ''.var_dump($this->db->db->affected_rows).''; if($this->db->db->affected_rows > 0) { $this->nbupdate++; $updatedone = true; } } + else + { + //print 'E'; + $this->errors[$error]['lib']=$this->db->lasterror(); + $this->errors[$error]['type']='SQL'; + $error++; + } } // Update not done, we do insert @@ -605,7 +609,6 @@ class ImportCsv extends ModeleImports $sqlend.=', '.$user->id; } $sql = $sqlstart.$sqlend.')'; - echo $sql; dol_syslog("import_csv.modules", LOG_DEBUG); // Run insert request diff --git a/htdocs/imports/import.php b/htdocs/imports/import.php index 3eefa101aea..141c83c1ba0 100644 --- a/htdocs/imports/import.php +++ b/htdocs/imports/import.php @@ -1461,7 +1461,11 @@ if ($step == 5 && $datatoimport) $db->rollback(); // We force rollback because this was just a simulation. // Show OK - if (! count($arrayoferrors) && ! count($arrayofwarnings)) print img_picto($langs->trans("OK"),'tick').' '.$langs->trans("NoError").'

'; + if (! count($arrayoferrors) && ! count($arrayofwarnings)) { + print img_picto($langs->trans("OK"),'tick').' '.$langs->trans("NoError").'
'; + print $langs->trans("NbInsert", $obj->nbinsert).'
'; + print $langs->trans("NbUpdate", $obj->nbupdate).'

'; + } else print $langs->trans("NbOfLinesOK",$nbok).'

'; // Show Errors @@ -1768,7 +1772,7 @@ if ($step == 6 && $datatoimport) if ($endatlinenb && ($sourcelinenb > $endatlinenb)) continue; // Run import - $result=$obj->import_insert($arrayrecord,$array_match_file_to_database,$objimport,count($fieldssource),$importid); + $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; diff --git a/htdocs/langs/en_US/exports.lang b/htdocs/langs/en_US/exports.lang index 55e592dc91d..2011a8a0d8e 100644 --- a/htdocs/langs/en_US/exports.lang +++ b/htdocs/langs/en_US/exports.lang @@ -122,3 +122,7 @@ SelectFilterFields=If you want to filter on some values, just input values here. FilteredFields=Filtered fields FilteredFieldsValues=Value for filter FormatControlRule=Format control rule +## imports updates +KeysToUseForUpdates=Key to use for updating data +NbInsert=Number of inserted lines: %s +NbUpdate=Number of updated lines: %s \ No newline at end of file