Advertising sustains the DA. Ads are hidden for members. Join today

Examples of use

Last updated on
2 December 2018

Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites

dbxref

Destination class: MigrateDestinationChadoDbxref.

class MyDbxrefMigration extends Migration {

  public function __construct(array $arguments) {
    parent::__construct($arguments);

    // Declare a source for this migration here.

    $this->destination = new MigrateDestinationChadoDbxref();

    $this->map = new MigrateSQLMap($this->machineName, [
      'id' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => t('Source ID'),
      ],
    ],
    MigrateDestinationChadoDbxref::getKeySchema()
    );

    $this->addFieldMapping('db_id')->defaultValue($my_db);
    $this->addFieldMapping('accession', 'dbxref_accession');
    $this->addFieldMapping('version')->defaultValue('1');
    $this->addFieldMapping('description')->defaultValue('');
  }

}

cvterm

Destination class: MigrateDestinationChadoCvterm.

class MyCvtermMigration extends Migration {

  public function __construct(array $arguments) {
    parent::__construct($arguments);

    // Declare a source for this migration here.

    $this->destination = new MigrateDestinationChadoCvterm();

    $this->map = new MigrateSQLMap($this->machineName, [
      'id' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => t('Source ID'),
      ],
    ],
    MigrateDestinationChadoCvterm::getKeySchema()
    );

    $this->addFieldMapping('cv_id')->defaultValue($my_cvterm);
    $this->addFieldMapping('name', 'source_name');
    // my_dbxref_cvterm is a previous migration which created dbxrefs
    // to be used with cvterms.
    $this->addFieldMapping('dbxref_id', 'id')->sourceMigration('my_dbxref_cvterm');
  }

}

organism

Destination class: MigrateDestinationChadoOrganism.

class MyOrganismMigration extends Migration {

  public function __construct(array $arguments) {
    parent::__construct($arguments);

    // Declare a source for this migration here.

    // Only perform lookups.
    $this->destination = new MigrateDestinationChadoOrganism(TRUE, FALSE);

    $this->map = new MigrateSQLMap($this->machineName, [
      'id' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => t('Source ID'),
      ],
    ],
    MigrateDestinationChadoOrganism::getKeySchema()
    );

    // You can break down a scientific name in two elements in a prepareRow()
    // method if needed.
    $this->addFieldMapping('genus', 'genus');
    $this->addFieldMapping('species', 'species');
  }

}

The constructor of MigrateDestinationChadoOrganism has two optional arguments:

  • the first one is TRUE (default) if mapping is allowed, that is, instead of creating new entries in the organism table, we look for a correspondence in the local database;
  • the second one is TRUE (default FALSE) if creation is allowed.

If both $mapping and $creation are true (hybrid mode), we first look for an existing correspondence in the local database, and create new organisms if none was found.

Caution: in hybrid mode, both previously existing organisms and those effectively imported will be deleted during rollback! If this is not the expected behaviour, set the mode to creation only, and use the technique described in this issue instead.

stock

Destination class: MigrateDestinationChadoStock.

class MyStockMigration extends Migration {

  public function __construct(array $arguments) {
    parent::__construct($arguments);

    // Declare a source for this migration here.

    $this->destination = new MigrateDestinationChadoStock();

    $this->map = new MigrateSQLMap($this->machineName, [
      'id' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => t('Source ID'),
      ],
    ],
    MigrateDestinationChadoStock::getKeySchema()
    );

    $this->addFieldMapping('type_id')->defaultValue($some_cvterm_id);
    $this->addFieldMapping('name', 'uniquename');
    $this->addFieldMapping('uniquename', 'uniquename');
    $this->addFieldMapping('description', 'description');
    $this->addFieldMapping('organism_id', 'organism_name')->sourceMigration('my_taxonomy');
  }

}

geolocation

Destination class: MigrateDestinationChadoGeolocation.

class MyGeolocationMigration extends Migration {

  public function __construct(array $arguments) {
    parent::__construct($arguments);

    // Declare a source for this migration here.

    $this->destination = new MigrateDestinationChadoGeolocation();

    $this->map = new MigrateSQLMap($this->machineName, [
      'id' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => t('Source ID'),
      ],
    ],
    MigrateDestinationChadoGeolocation::getKeySchema()
    );

    $this->addFieldMapping('latitude', 'latitude');
    $this->addFieldMapping('longitude', 'longitude');
    $this->addFieldMapping('geodetic_datum')->defaultValue('WGS84');
  }

}

experiment

Destination class: MigrateDestinationChadoExperiment.

class MyExperimentMigration extends Migration {

  public function __construct(array $arguments) {
    parent::__construct($arguments);

    // Declare a source for this migration here.

    $this->destination = new MigrateDestinationChadoExperiment();

    $this->map = new MigrateSQLMap($this->machineName, [
      'id' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => t('Source ID'),
      ],
    ],
    MigrateDestinationChadoExperiment::getKeySchema()
    );

    $this->addFieldMapping('nd_geolocation_id', 'id')->sourceMigration('my_geolocation');
    $this->addFieldMapping('type_id')->defaultValue($relevant_cvterm_id);
  }

}

experiment_stock

Destination class: MigrateDestinationChadoExperimentStock.

class MyExperimentStockMigration extends Migration {

  public function __construct(array $arguments) {
    parent::__construct($arguments);

    // Declare a source for this migration here.

    $this->destination = new MigrateDestinationChadoExperimentStock();

    $this->map = new MigrateSQLMap($this->machineName, [
      'id' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => t('Source ID'),
      ],
    ],
    MigrateDestinationChadoExperimentStock::getKeySchema()
    );

    $this->addFieldMapping('nd_experiment_id', 'id')->sourceMigration('my_experiment');
    $this->addFieldMapping('stock_id', 'id')->sourceMigration('my_stock');
    $this->addFieldMapping('type_id')->defaultValue($relevant_cvterm_id);
  }

}

foo_dbxref

Destination class: MigrateDestinationChadoFooDbxref. Unlike previous classes, this one needs the name of the base table to use as an argument.

class MyStockDbxrefMigration extends Migration {

  public function __construct(array $arguments) {
    parent::__construct($arguments);

    // Declare a source for this migration here.

    $this->destination = new MigrateDestinationChadoFooDbxref('stock');

    $this->map = new MigrateSQLMap($this->machineName, [
      'id' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => t('Source ID'),
      ],
    ],
    MigrateDestinationChadoFooDbxref::getKeySchema('stock')
    );

    $this->addFieldMapping('stock_id', 'id')->sourceMigration('my_stock');
    $this->addFieldMapping('dbxref_id', 'id')->sourceMigration('my_dbxref_stock');

  }

}

foo_cvterm

Destination class: MigrateDestinationChadoFooCvterm. Like the previous class, it needs the name of the base table to use as an argument.

class MyStockCvtermMigration extends Migration {

  public function __construct(array $arguments) {
    parent::__construct($arguments);

    // Declare a source for this migration here.

    $this->destination = new MigrateDestinationChadoFooCvterm('stock');

    $this->map = new MigrateSQLMap($this->machineName, [
      'id' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => t('Source ID'),
      ],
    ],
    MigrateDestinationChadoFooCvterm::getKeySchema('stock')
    );

    $this->addFieldMapping('stock_id', 'id')->sourceMigration('my_stock');
    $this->addFieldMapping('pub_id')->defaultValue(1);
  }

}

prop

Destination class: MigrateDestinationChadoProp. Same remark about the base table name.

class MyExperimentStockMigration extends Migration {

  public function __construct(array $arguments) {
    parent::__construct($arguments);

    // Declare a source for this migration here.

    $this->destination = new MigrateDestinationChadoProp('stock');

    $this->map = new MigrateSQLMap($this->machineName, [
      'id' => [
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => t('Source ID'),
      ],
    ],
    MigrateDestinationChadoProp::getKeySchema('stock')
    );

    $this->addFieldMapping('stock_id', 'id')->sourceMigration('my_stock');
    $this->addFieldMapping('type_id')->defaultValue($relevant_cvterm_id);
    $this->addFieldMapping('value', 'additional_details');
  }

}

Help improve this page

Page status: No known problems

You can: