You are here

protected function MigrateSource::prepareRow in Migrate 7.2

Same name and namespace in other branches
  1. 6.2 includes/source.inc \MigrateSource::prepareRow()

Give the calling migration a shot at manipulating, and possibly rejecting, the source row.

Return value

bool FALSE if the row is to be skipped.

1 call to MigrateSource::prepareRow()
MigrateSource::next in includes/source.inc
Implementation of Iterator::next() - subclasses of MigrateSource should implement getNextRow() to retrieve the next valid source rocord to process.

File

includes/source.inc, line 407
Define base for migration sources.

Class

MigrateSource
Abstract base class for source handling.

Code

protected function prepareRow($row) {
  migrate_instrument_start(get_class($this->activeMigration) . ' prepareRow');
  $return = $this->activeMigration
    ->prepareRow($row);
  migrate_instrument_stop(get_class($this->activeMigration) . ' prepareRow');

  // We're explicitly skipping this row - keep track in the map table
  if ($return === FALSE) {

    // Make sure we replace any previous messages for this item with any
    // new ones.
    $this->activeMigration
      ->getMap()
      ->delete($this->currentKey, TRUE);
    $this->activeMigration
      ->saveQueuedMessages();
    $this->activeMigration
      ->getMap()
      ->saveIDMapping($row, array(), MigrateMap::STATUS_IGNORED, $this->activeMigration->rollbackAction);
    $this->numIgnored++;
    $this->currentRow = NULL;
    $this->currentKey = NULL;
  }
  else {
    $return = TRUE;

    // When tracking changed data, We want to quietly skip (rather than
    // "ignore") rows with changes. The caller needs to make that decision,
    // so we need to provide them with the necessary information (before and
    // after hashes).
    if ($this->trackChanges) {
      $unhashed_row = clone $row;

      // Remove all map data, otherwise we'll have a false positive on the
      // second import (attempt) on a row.
      foreach ($unhashed_row as $field => $data) {
        if (strpos($field, 'migrate_map_') === 0) {
          unset($unhashed_row->{$field});
        }
      }
      $row->migrate_map_original_hash = isset($row->migrate_map_hash) ? $row->migrate_map_hash : '';
      $row->migrate_map_hash = $this
        ->hash($unhashed_row);
    }
    else {
      $row->migrate_map_hash = '';
    }
  }
  $this->numProcessed++;
  return $return;
}