You are here

public function DrupalNodeMigration::__construct in Drupal-to-Drupal data migration 7.2

Parameters

array $arguments:

Overrides DrupalMigration::__construct

3 calls to DrupalNodeMigration::__construct()
DrupalNode5Migration::__construct in d5/node.inc
DrupalNode6Migration::__construct in d6/node.inc
DrupalNode7Migration::__construct in d7/node.inc
3 methods override DrupalNodeMigration::__construct()
DrupalNode5Migration::__construct in d5/node.inc
DrupalNode6Migration::__construct in d6/node.inc
DrupalNode7Migration::__construct in d7/node.inc

File

./node.inc, line 42
Base class for migrating nodes into Drupal.

Class

DrupalNodeMigration
Base class for all node migrations - handles commonalities across all supported source Drupal versions.

Code

public function __construct(array $arguments) {
  $this->destinationType = $arguments['destination_type'];
  $this->sourceType = $arguments['source_type'];
  if (!empty($arguments['user_migration'])) {
    $user_migration = $arguments['user_migration'];
    $this->dependencies[] = $user_migration;
  }
  if (!empty($arguments['default_language'])) {
    $this->defaultLanguage = $arguments['default_language'];
  }
  parent::__construct($arguments);

  // Document known core fields
  $this->sourceFields += array(
    'nid' => t('Node ID'),
    'title' => t('Title'),
    // @todo Depends on has_title, and label may be customized
    'body' => t('Body'),
    'format' => t('Format'),
    'teaser' => t('Teaser'),
    'uid' => t('Authored by (uid)'),
    'created' => t('Created timestamp'),
    'changed' => t('Modified timestamp'),
    'status' => t('Published'),
    'promote' => t('Promoted to front page'),
    'sticky' => t('Sticky at top of lists'),
    'revision' => t('Create new revision'),
    'log' => t('Revision Log message'),
    'language' => t('Language (fr, en, ...)'),
    'tnid' => t('The translation set id for this node'),
    'revision_uid' => t('Revision modified by author (uid)'),
  );
  $this->sourceFields += $this->version
    ->getSourceFields('node', $this->sourceType);
  if ($this
    ->moduleExists('path')) {
    $this->sourceFields['path'] = t('Path alias');
  }
  if ($this
    ->moduleExists('statistics')) {
    $this->sourceFields += array(
      'totalcount' => t('The total number of times the node has been viewed.'),
      'daycount' => t('The total number of times the node has been viewed today.'),
      'timestamp' => t('The most recent time the node has been viewed.'),
    );
  }
  $this->destination = new MigrateDestinationNode($this->destinationType);
  $this->map = new MigrateSQLMap($this->machineName, array(
    'nid' => array(
      'type' => 'int',
      'unsigned' => TRUE,
      'not null' => TRUE,
      'description' => 'Source node ID',
      'alias' => 'n',
    ),
  ), MigrateDestinationNode::getKeySchema(), $this->mapConnection);
  if (!$this->newOnly) {
    $this->highwaterField = array(
      'name' => 'changed',
      'alias' => 'n',
      'type' => 'int',
    );
  }

  // Setup common mappings
  $this
    ->addSimpleMappings(array(
    'title',
    'status',
    'created',
    'changed',
    'comment',
    'promote',
    'sticky',
  ));
  if (field_info_instance('node', 'body', $this->destinationType)) {
    $this
      ->addFieldMapping('body', 'body');
    $this
      ->addFieldMapping('body:language')
      ->defaultValue($this->defaultLanguage);
  }
  else {
    $this
      ->addUnmigratedSources(array(
      'body',
    ));
  }
  $this
    ->addUnmigratedSources(array(
    'vid',
  ));
  $this
    ->addUnmigratedDestinations(array(
    'is_new',
    'revision',
    'revision_uid',
    'log',
  ));
  if (isset($arguments['default_uid'])) {
    $default_uid = $arguments['default_uid'];
  }
  else {
    $default_uid = 1;
  }
  if (isset($user_migration)) {
    $this
      ->addFieldMapping('uid', 'uid')
      ->sourceMigration($user_migration)
      ->defaultValue($default_uid);
  }
  else {
    $this
      ->addFieldMapping('uid')
      ->defaultValue($default_uid);
  }
  if ($this
    ->moduleExists('path')) {
    $this
      ->addFieldMapping('path', 'path')
      ->description('Handled in prepareRow');
  }
  if (module_exists('pathauto')) {
    $this
      ->addFieldMapping('pathauto')
      ->description('By default, disable in favor of migrated paths')
      ->defaultValue(0);
  }
  if (module_exists('statistics')) {
    if ($this
      ->moduleExists('statistics')) {
      $this
        ->addSimpleMappings(array(
        'totalcount',
        'daycount',
        'timestamp',
      ));
    }
    else {
      $this
        ->addUnmigratedDestinations(array(
        'totalcount',
        'daycount',
        'timestamp',
      ));
    }
  }
  elseif ($this
    ->moduleExists('statistics')) {
    $this
      ->addUnmigratedSources(array(
      'totalcount',
      'daycount',
      'timestamp',
    ));
  }
}