You are here

public function MigrateSourceCSV::getNextRow in Migrate 7.2

Same name and namespace in other branches
  1. 6.2 plugins/sources/csv.inc \MigrateSourceCSV::getNextRow()

Implementation of MigrateSource::getNextRow(). Return the next line of the source CSV file as an object.

Return value

null|object

File

plugins/sources/csv.inc, line 415
Define a MigrateSource for importing from comma separated values files.

Class

MigrateSourceCSV
Implementation of MigrateSource, to handle imports from CSV files.

Code

public function getNextRow() {
  $row = $this
    ->getNextLine();
  if ($row) {

    // only use rows specified in $this->csvcolumns().
    $row = array_intersect_key($row, $this->csvcolumns);

    // Set meaningful keys for the columns mentioned in $this->csvcolumns().
    foreach ($this->csvcolumns as $int => $values) {
      list($key, $description) = $values;

      // Copy value to more descriptive string based key and then unset original.
      $row[$key] = isset($row[$int]) ? $row[$int] : NULL;
      unset($row[$int]);
    }
    $row['csvrownum'] = $this->rowNumber++;
    return (object) $row;
  }
  else {
    fclose($this->csvHandle);
    $this->csvHandle = NULL;
    return NULL;
  }
}