You are here

public function WineWineMigration::prepareRow in Migrate 6.2

Same name and namespace in other branches
  1. 7.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 669
Advanced migration examples. These serve two purposes:

Class

WineWineMigration

Code

public function prepareRow($current_row) {

  // 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;
  }

  // An advanced feature of the file field handler is that in addition to the
  // path to the image itself, we can add image properties like ALT text,
  // encapsulating them as JSON

  /*
       * 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();
      $current_row->images = array();
      foreach ($result as $row) {
        $image_data = array(
          'path' => $row->url,
          'alt' => $row->image_alt,
          'title' => $row->image_title,
        );
        $current_row->images[] = drupal_to_js($image_data);
      }
  */

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