Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Customizing the CsvBulkLoader


Go to End


2 Posts   1859 Views

Avatar
baba-papa

Community Member, 279 Posts

15 September 2009 at 3:14am

Hi,

I need to import a lot of data via CSV and discovered the CsvBulkLoader. I subclassed it for my needs:

class StudioCsvBulkLoader extends CsvBulkLoader {
    //Key=CSV colum, Value=FitnessStudio attribute
    public $columnMap = array(
        'Studioname' => 'name',
        'PLZ' => 'postcode',
        'Stadt' => 'city',
        'Strasse' => 'street',
        'Land' => 'country',
        'Vorwahl' => 'telephoncode',
        'Telefonnummer' => 'telephon',
        'URL' => 'URL',
        'Kampagne' => 'Campaign.Title',
    );
  
    public $duplicateChecks = array(
        'Studioname' => 'name'
    );
    //Define relation and function to check, if the category exists.
    public $relationCallbacks = array(
        'relationname' => 'Campaign',
        'callback' => 'getClientCategoryByTitle'
    );
    //Does the imported category already exist?
    static function getClientCategoryByTitle(&$obj, $val, $record){
        $SQL_val = Convert::raw2sql($val);
        return DataObject::get_one(
            'Campaign', "Title = '{$SQL_val}'"
        );
    }
}

I implemented the StudioCsvBulkLoader into a subclass of ModelAdmin. My problem: StudioCsvBulkLoader does not work. Any changes I do to $columnMap or any other variable does not show any effect to the backend. The system seems to fall back on CsvBulkLoader. Do I have any stupid coding mistake?

Avatar
baba-papa

Community Member, 279 Posts

15 September 2009 at 3:32am

I have this solved ;) I had an error in the headrow of my csv.