Questions about Extending CSVBulkLoader

SilverStripe 4

I want to exted CSVBulkLoader.

I posted a similar question to this earlier, but have gotten a better idea of how to ask the question since the original post. Normally, I would ask a more fully formed question, but deadlines have begun to alter my brain chemistry. I’m appreciative of any insights. Perhaps there’s a module that does all/some of this stuff?

I’ve been using the default ModelAdmin CSV Import/Export tool, which works great. However, I’d like some more robust functionality, such as:

  • Export CSV with BOM (byte order mark as UTF8)
  • Read the BOM, if present, upon import, and do something with it
  • Upon import, check for duplicate records, and if there are duplicates, I’d like to only update the columns in the record that have changed.
  • Delete records that are already in the database, that are not in the CSV being imported
  • Add whatever security measures are necessary to use this custom class securely.

Are these possible? I have some more questions about the minutiae inline with the code below.
Here is the link to the tutorial I’ve been studying: CSV Import – SilverStripe Documentation

In the WineAdmin Class, I have a custom loader defined. Is it necessary to define this if using the default uploader in ModelAdmin?

//WineAdmin.php
private static $model_importers = [
  'Wine' => 'WineCsvBulkLoader'
];

So far, my WineCsvBulkLoader Class looks like this:

//WineCsvBulkLoader.php
use SilverStripe\Dev\CsvBulkLoader;

class WineCsvBulkLoader extends CsvBulkLoader 
{
   public $columnMap = [
		'ItemNumber'				=> 'ItemNumber',
		'Country'					=> 'Country',
		'Producer'					=> 'Producer',
		'BrandName'					=> 'BrandName',
		 // etc
   ];

  // What does this actually do when there is a duplicate? Does it skip the record?
  // Can I use a callback here to check for updated columns, on the record, if it is
  // a duplicate? 
   public $duplicateChecks = [
     'ItemNumber' => 'ItemNumber'
   ];

}