public function MigrateExampleOracle::__construct in Migrate 6.2
General initialization of a Migration object.
Overrides Migration::__construct
File
- migrate_example/
migrate_example_oracle/ migrate_example_oracle.migrate.inc, line 25 - 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.,
Class
- MigrateExampleOracle
- Migration class to test importing from Oracle.
Code
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',
));
}