Skip to content

Instantly share code, notes, and snippets.

@lsolesen
Created March 29, 2011 20:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lsolesen/893241 to your computer and use it in GitHub Desktop.
Save lsolesen/893241 to your computer and use it in GitHub Desktop.
Migrate example for Drupal module migrate
<?php
class MigrateNews extends Migration {
public function __construct() {
parent::__construct();
$this->description = t('Migrate news from legacy database');
$this->team = array(
new MigrateTeamMember('Lars Olesen', 'lars@vih.dk', t('Webmaster')),
);
$query = db_select('nyhed', 'nyhed', array('target' => 'vih'))
->fields('nyhed', array('id', 'overskrift', 'tekst', 'date_created', 'date_updated', 'published'))
->where('nyhed.active = :active', array(':active' => 1));
/*
$query->leftJoin('keyword_x_object', 'kxo', 'nyhed.id = kxo.belong_to');
$query->innerJoin('keyword', 'keyword', 'keyword.id = kxo.keyword_id');
// Gives a single comma-separated list of related terms
$query->addExpression('GROUP_CONCAT(keyword.keyword)', 'terms');
*/
$this->source = new MigrateSourceSQL($query);
$this->source->setMapJoinable(false);
$this->destination = new MigrateDestinationNode('story', array('text_format' => 'full_html'));
$this->map = new MigrateSQLMap($this->machineName,
array(
'id' => array('type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
)
),
MigrateDestinationNode::getKeySchema()
);
$this->addFieldMapping('title', 'overskrift');
$this->addFieldMapping('body', 'tekst');
$this->addFieldMapping('uid')
->defaultValue(1);
$this->addFieldMapping('created', 'date_created');
$this->addFieldMapping('changed', 'date_updated');
$this->addFieldMapping('status', 'published');
//$this->addFieldMapping('field_tags', 'terms')->separator(',');
}
}
@holtzermann17
Copy link

Would you be willing to upload the other files that make this work (.info, .module, .install)? I'm having trouble adapting the examples in migrate_example, because those other files are unduly complicated.

@lsolesen
Copy link
Author

@holtzermann17
Copy link

Thank you! I have also in the mean time gotten my own simple example working: https://gist.github.com/1051550 Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment