Hi,
I have a custom module where I have enabled data entry via csv import.
Now i need to run checks on the records i import, how do i get the errors that are possibly generated returned?
i found the file
modules/import/CsvAutoDetect.php
where there are the imported rows, these rows i would like to compare with the DB content, but i don’t know how to return the error. Any ideas? Thanks
When you start an import for any module, the function is called automatically.
You can look at the saveImportBean function in the modules/Import/Importer.php file.
sorry p.konetskiy, I am trying to follow your instructions, but it is not working, surely I am missing something.
I created the Import.php file inside custom/modules/<custom_module>/:
class Import{
public function beforeImportSave() {
$GLOBALS['log']->fatal('***** IMPORT ***** ');
}
}
Modify the importRow function in the modules/Import/Importer.php file. But it does not support upgrade.
Create a special filed for custom module and add the filed to the indexes array and set a special function to custom field in indexes array. The function should call the writeError function from object ImportDataSource of the modules/Import/sources/ImportDataSource.php file. Example for for vardefs.php of custom module:
!!! Warning !!!
The realy name of special function for custom module should be numberImportCollection not dupeChecknumberImportCollection
This is a function format.
public function numberImportCollection($index) {
...
if(<your_custom_condition>)
{
return true;
}
else
{
return false;
}
}
The custom function controls duplicate records. I think you can call the writeError function without me.
The variant will safe to upgrade.
After a lot of work on it, I decided to use the first method you suggested (changing the importRow of Importer, also because I didn’t quite understand the other method). It was just what I was looking for, here I have the records in the .csv file that I import and I can do the checks I want within the DB, issuing custom error messages.
Thank you very much!
PS just one thing, when I import a file I have to set the date format each time (by default it’s like 12/23/2020), changing it to 23/12/2020, is there any way to default to the values I want?