You are here

public function WineWineMigration::prepareRow in Migrate 7.2

Same name and namespace in other branches
  1. 6.2 migrate_example/wine.inc \WineWineMigration::prepareRow()

Default implementation of prepareRow(). This method is called from the source plugin upon first pulling the raw data from the source.

Parameters

$row: Object containing raw source data.

Return value

bool TRUE to process this row, FALSE to have the source skip it.

Overrides Migration::prepareRow

File

migrate_example/wine.inc, line 1392
Advanced migration examples. These serve two purposes:

Class

WineWineMigration

Code

public function prepareRow($current_row) {

  // Always start your prepareRow implementation with this clause. You need to
  // be sure your parent classes have their chance at the row, and that if
  // they return FALSE (indicating the row should be skipped) you pass that
  // on.
  if (parent::prepareRow($current_row) === FALSE) {
    return FALSE;
  }

  // We used the MySQL GROUP_CONCAT function above to handle a multi-value
  // source field - more portably, we query the related table with multiple
  // values here, so the values can run through the mapping process.
  $source_id = $current_row->wineid;
  $result = db_select('migrate_example_wine_vintages', 'v')
    ->fields('v', array(
    'vintage',
  ))
    ->condition('wineid', $source_id)
    ->execute();
  foreach ($result as $row) {
    $current_row->best_vintages[] = $row->vintage;
  }

  // We can have multiple files per node, so we pull them here along with
  // their related data (alt/title).

  /*
   * This is disabled - see http://drupal.org/node/1679798. To demonstrate
   * remote file migration, edit the migrate_example_wine_files table and enter
   * the URLs of known remote image files, then enable this code.
      $result = db_select('migrate_example_wine_files', 'f')
                ->fields('f', array('url', 'image_alt', 'image_title'))
                ->condition('wineid', $source_id)
                ->execute();
      foreach ($result as $row) {
        $current_row->url[] = $row->url;
        $current_row->image_alt[] = $row->image_alt;
        $current_row->image_title[] = $row->image_title;
      }
  */

  // We could also have used this function to decide to skip a row, in cases
  // where that couldn't easily be done through the original query. Simply
  // return FALSE in such cases.
  return TRUE;
}