Created
March 29, 2011 20:50
-
-
Save lsolesen/893241 to your computer and use it in GitHub Desktop.
Migrate example for Drupal module migrate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(','); | |
} | |
} |
Have a look here: https://github.com/vih/vih.dk-features/tree/master/migrate_vih
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
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.