You are here

public function MigrateSourceList::getNextRow in Migrate 6.2

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

Implementation of MigrateSource::getNextRow().

Return value

null|stdClass

File

plugins/sources/list.inc, line 165
Support for migration from sources with distinct means of listing items to import and obtaining the items themselves.

Class

MigrateSourceList
Implementation of MigrateSource, providing the semantics of iterating over IDs provided by a MigrateList and retrieving data from a MigrateItem.

Code

public function getNextRow() {
  $row = NULL;
  while ($this->idIterator
    ->valid()) {
    $ids = $this->idIterator
      ->current();
    $this->idIterator
      ->next();

    // Skip empty IDs
    if (empty($ids)) {
      continue;
    }

    // Got a good ID, get the data and get out.
    $row = $this->itemClass
      ->getItem($ids);
    if ($row) {

      // No matter what $ids is, be it a string, integer, object, or array, we
      // cast it to an array so that it can be properly mapped to the source
      // keys as specified by the map. This is done after getItem is called so
      // that the ItemClass doesn't have to care about this requirement.
      $ids = (array) $ids;
      foreach (array_keys($this->activeMap
        ->getSourceKey()) as $key_name) {

        // Grab the first id and advance the array cursor. Then save the ID
        // using the map source key - it will be used for mapping.
        list(, $id) = each($ids);
        $row->{$key_name} = $id;
      }
    }
    break;
  }
  return $row;
}