Jump to:

5453 Posts in 1674 Topics by 1198 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Customizing the CsvBulkLoader

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

Page: 1
Go to End
Author Topic: 1246 Views
  • baba-papa
    Avatar
    Community Member
    279 Posts

    Customizing the CsvBulkLoader Link to this post

    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?

  • baba-papa
    Avatar
    Community Member
    279 Posts

    Re: Customizing the CsvBulkLoader Link to this post

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

    1246 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.