You are here

public function MigrateSourceXML::getNextRow in Migrate 6.2

Same name and namespace in other branches
  1. 7.2 plugins/sources/xml.inc \MigrateSourceXML::getNextRow()

Implementation of MigrationSource::getNextRow().

Return value

stdClass data for the next row from the XML source files

File

plugins/sources/xml.inc, line 981
Support for migration from XML sources.

Class

MigrateSourceXML
Implementation of MigrateSource, to handle imports from XML files.

Code

public function getNextRow() {
  migrate_instrument_start('MigrateSourceXML::next');
  $source_key = $this->activeMap
    ->getSourceKey();
  $key_name = key($source_key);
  $row = NULL;

  // The reader is now lazy loaded, so it may not be defined yet, need to test if set
  if (isset($this->reader)) {

    // attempt to load the next row
    $this->reader
      ->next();
  }

  // Test the reader for a valid row
  if (isset($this->reader) && $this->reader
    ->valid()) {
    $row = new stdClass();
    $row->{$key_name} = $this->reader
      ->key();
    $row->xml = $this->reader
      ->current();
  }
  else {

    // The current source is at the end, try to load the next source
    if ($this
      ->getNextSource()) {
      $row = new stdClass();
      $row->{$key_name} = $this->reader
        ->key();
      $row->xml = $this->reader
        ->current();
    }
  }
  migrate_instrument_stop('MigrateSourceXML::next');
  return $row;
}