You are here

public function FeedsCSVParser::parse in Feeds 7

Same name and namespace in other branches
  1. 6 plugins/FeedsCSVParser.inc \FeedsCSVParser::parse()
  2. 7.2 plugins/FeedsCSVParser.inc \FeedsCSVParser::parse()

Implements FeedsParser::parse().

Overrides FeedsParser::parse

File

plugins/FeedsCSVParser.inc, line 11

Class

FeedsCSVParser
Parses a given file as a CSV file.

Code

public function parse(FeedsImportBatch $batch, FeedsSource $source) {

  // Load and configure parser.
  feeds_include_library('ParserCSV.inc', 'ParserCSV');
  $iterator = new ParserCSVIterator($batch
    ->getFilePath());
  $source_config = $source
    ->getConfigFor($this);
  $parser = new ParserCSV();
  $delimiter = $source_config['delimiter'] == 'TAB' ? "\t" : $source_config['delimiter'];
  $parser
    ->setDelimiter($delimiter);
  $header = $this
    ->parseHeader($parser, $iterator);
  if (!header) {
    return;
  }
  $parser
    ->setColumnNames($header);

  // Populate batch.
  $batch
    ->setItems($this
    ->parseItems($parser, $iterator));
}