You are here

migrate_example_oracle.migrate.inc in Migrate 6.2

Examples and test fodder for migration from Oracle sources. To use this example (and to run the corresponding tests) you must define a connection to an Oracle database in your settings.php. E.g.,

$conf['oracle_db'] = array( 'username' => 'DRUPAL', 'password' => 'DRUPAL', 'connection_string' => '//oracledb/orcl', );

The username must have the CREATE TABLE privilege, so test data can be stored for the example to import.

See http://us.php.net/manual/en/function.oci-connect.php for more information on connection_string.

File

migrate_example/migrate_example_oracle/migrate_example_oracle.migrate.inc
View source
<?php

/**
 * @file
 * Examples and test fodder for migration from Oracle sources. To use this example
 * (and to run the corresponding tests) you must define a connection to an Oracle database
 * in your settings.php. E.g.,
 *
 * $conf['oracle_db'] = array(
 *   'username' => 'DRUPAL',
 *   'password' => 'DRUPAL',
 *   'connection_string' => '//oracledb/orcl',
 * );
 *
 * The username must have the CREATE TABLE privilege, so test data can be stored for the
 * example to import.
 *
 * See http://us.php.net/manual/en/function.oci-connect.php for more information on
 * connection_string.
 */

/**
 * Migration class to test importing from Oracle.
 */
class MigrateExampleOracle extends Migration {
  public function __construct() {
    parent::__construct();
    $this->description = t('Example migration from Oracle');

    // Note that Oracle by default upper-cases all identifiers, so use upper-case
    // for the key name and for source fields below.
    $this->map = new MigrateSQLMap($this->machineName, array(
      'OID' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Content ID',
      ),
    ), MigrateDestinationNode::getKeySchema());

    // Source fields available from the Oracle table.
    $fields = array(
      'OID' => t('Source id'),
      'TITLE' => t('Title'),
      'BODY' => t('Description'),
      'CREATED' => t('Creation date'),
      'UPDATED' => t('Updated date'),
    );

    // Oracle will usually (depending on server configuration) return only a
    // date (such as 01-MAY-11) for datetime fields - you need to use TO_CHAR()
    // to extract time information as well.
    $query = "SELECT OID, TITLE, BODY, TO_CHAR(CREATED, 'yyyy/mm/dd hh24:mi:ss') CREATED,\n                TO_CHAR(UPDATED, 'yyyy/mm/dd hh24:mi:ss') UPDATED\n              FROM ORACLE_CONTENT";
    $count_query = "SELECT COUNT(*) FROM ORACLE_CONTENT";

    // Per above, the connection info should be defined in settings.php.
    global $conf;
    $this->source = new MigrateSourceOracle($conf['oracle_db'], $query, $count_query, $fields);
    $this->destination = new MigrateDestinationNode('migrate_example_oracle');

    // Basic fields
    $this
      ->addFieldMapping('title', 'TITLE');
    $this
      ->addFieldMapping('uid')
      ->defaultValue(1);
    $this
      ->addFieldMapping('body', 'BODY');
    $this
      ->addFieldMapping('created', 'CREATED');
    $this
      ->addFieldMapping('changed', 'UPDATED');

    // Unmapped destination fields
    $this
      ->addUnmigratedDestinations(array(
      'is_new',
      'status',
      'promote',
      'revision',
      'language',
      'sticky',
      'revision_uid',
      'path',
    ));
  }

}

/*
 * Implementation of hook_migrate_api().
 */
function migrate_example_oracle_migrate_api() {
  $api = array(
    'api' => 2,
    'migrations' => array(
      'MigrateExampleOracle' => array(
        'class_name' => 'MigrateExampleOracleNode',
      ),
    ),
  );
  return $api;
}

Functions

Classes

Namesort descending Description
MigrateExampleOracle Migration class to test importing from Oracle.