You are here

public function DrupalNode6Migration::prepareRow in Drupal-to-Drupal data migration 7.2

Called after the query data is fetched - we'll use this to populate the source row with the CCK fields.

Overrides DrupalNodeMigration::prepareRow

1 call to DrupalNode6Migration::prepareRow()
ExampleImageMigration::prepareRow in migrate_d2d_example/node.inc
Implementation of Migration::prepareRow().
1 method overrides DrupalNode6Migration::prepareRow()
ExampleImageMigration::prepareRow in migrate_d2d_example/node.inc
Implementation of Migration::prepareRow().

File

d6/node.inc, line 125
Implementation of DrupalNodeMigration for Drupal 6 sources.

Class

DrupalNode6Migration
Handling specific to a Drupal 6 source for nodes.

Code

public function prepareRow($row) {
  if (parent::prepareRow($row) === FALSE) {
    return FALSE;
  }

  // The property 'tnid' cannot be handled via the sourceMigration() method
  // because it might be 0 or the main node of translation set. We don't want
  // to create a stub for such cases.
  if (!empty($row->tnid)) {
    $destination_ids = $this
      ->getMap()
      ->lookupDestinationID(array(
      $row->tnid,
    ));

    // There's no destination yet. Create a stub.
    if (empty($destination_ids)) {

      // Don't create stub for itself.
      if ($row->tnid != $row->nid) {

        // Check if 'tnid' is a node in the source set to prevent not
        // updatable stubs.
        $query = clone $this
          ->query();
        $query
          ->condition('n.nid', $row->tnid);
        $nid = $query
          ->execute()
          ->fetchField();
        unset($query);
        if ($nid) {
          if ($tnids = $this
            ->createStub(NULL)) {

            // Save the mapping.
            $this->map
              ->saveIDMapping((object) array(
              'nid' => $row->tnid,
            ), $tnids, MigrateMap::STATUS_NEEDS_UPDATE, $this->defaultRollbackAction);
            $row->tnid = reset($tnids);
          }
        }
      }
      else {
        $row->tnid = 0;
        $row->_is_translation_source = TRUE;
      }
    }
    else {
      $row->tnid = $destination_ids['destid1'];
    }
  }
  foreach ($this->fileDataFields as $data_field) {
    if (isset($row->{$data_field})) {
      $data = unserialize($row->{$data_field});
      $base_field = substr($data_field, 0, strpos($data_field, '_data'));
      if (!empty($data)) {
        foreach ($data as $key => $value) {
          $field_name = $base_field . '_' . $key;
          $row->{$field_name} = $value;
        }
        unset($row->{$data_field});
      }
    }
  }

  // Convert the default field names to the nice-looking ones.
  foreach ($this->fixFieldNames as $clean => $display) {
    if (isset($row->{$clean})) {
      $row->{$display} = $row->{$clean};
      unset($row->{$clean});
    }
  }

  // Don't populate summary if the teaser matches the generated summary.
  if (empty($row->teaser) || $row->teaser == text_summary($row->body)) {
    $row->teaser = '';
  }
}