You are here

public function WordPressSource::next in WordPress Migrate 7

Implementation of Iterator::next() - called at the bottom of the loop implicitly, as well as explicitly from rewind().

Overrides MigrateSource::next

1 call to WordPressSource::next()
WordPressSource::rewind in ./wordpress_source.inc
Implementation of Iterator::rewind() - called before beginning a foreach loop.

File

./wordpress_source.inc, line 138
Common source support for migration from WordPress XML dumps.

Class

WordPressSource
@file Common source support for migration from WordPress XML dumps.

Code

public function next() {
  migrate_instrument_start('WordPressSource next');
  $migration = Migration::currentMigration();
  $this->currentRow = NULL;
  $this->currentKey = NULL;

  // If we've already hit the itemlimit, quit
  $itemlimit = $migration
    ->getOption('itemlimit');
  if ($itemlimit && $this->numProcessed >= $itemlimit) {
    return;
  }

  // Loop over the elements to be processed. Note that itemIndex is persistent,
  // so subsequent next() calls pick up where we left off.
  while ($this->itemIndex < $this->itemCount) {
    $item = $this->items[$this->itemIndex++];
    $this->currentRow = NULL;

    // Each particular source type needs to parse things in its own way. If it
    // returns FALSE, skip this item.
    if (!$this
      ->populateRow($item)) {
      continue;
    }

    // Previously migrated?
    $map_row = $migration
      ->getMap()
      ->getRowBySource($this->currentKey);
    if (!$map_row) {

      // Unmigrated row, take it
    }
    elseif ($map_row['needs_update'] == 1) {

      // We always want to take this row if needs_update = 1
    }
    else {

      // We want to skip this row if it's in the map table
      continue;
    }

    // Add map info to the row, if present
    if ($map_row) {
      foreach ($map_row as $field => $value) {
        $field = 'migrate_map_' . $field;
        $this->currentRow->{$field} = $value;
      }
    }

    // Allow the Migration to prepare this row. prepareRow() must return a
    // boolean FALSE to prevent the row from being processed.
    if (method_exists($migration, 'prepareRow')) {
      $success = $migration
        ->prepareRow($this->currentRow);
    }
    else {
      $success = TRUE;
    }
    if ($success === FALSE) {
      $this->currentRow = NULL;
    }
    else {
      $this->numProcessed++;
      break;
    }
  }
  if (!is_object($this->currentRow)) {
    $this->currentRow = NULL;
  }
  migrate_instrument_stop('WordPressSource next');
}