Migrate
Getting it into Drupal andrew morton drewish@zivtech.com
Migrate Getting it into Drupal andrew morton drewish@zivtech.com - - PowerPoint PPT Presentation
Migrate Getting it into Drupal andrew morton drewish@zivtech.com Migrate 2.0 Powerful object oriented framework for moving content into Drupal. Minimal UI, primarily code based. Steep learning curve (aka migraine module) but
Getting it into Drupal andrew morton drewish@zivtech.com
SQL, XML, JSON, CSV, etc
Node, User, Term, etc
ID Name Age 1 Larry 34 2 Curly 54 4 Moe 47
entity_id field_name field_age
32 Larry 34 33 Curly 54 34 Moe 47 Source ID Dest ID 1 32 2 33 4 34
SQL, XML, JSON, CSV, etc
Node, User, Term, etc
entity_id field_name field_age
32 Larry 34 33 Curly 54 34 Moe 47 Source Destination Name field_name Age field_age Junk NULL ID Name Age Junk 1 Larry 34 blah 2 Curly 54 4 Moe 47 Spam
$entity->field_bar[‘und’][0][‘value’] = “foo”
display their current status.
create/update destination objects.
destination objects.
// inside __construct() $query = db_select('migrate_example_beer_topic', 'met')
'style_parent', 'region', 'hoppiness'))
$this->source = new MigrateSourceSQL($query);
// The definition of the columns. Keys are integers, // values are an array of field name then description. $columns = array( 0 => array('cvs_uid', 'Id'), 1 => array('email', 'Email'), 2 => array('name', 'Name'), 3 => array('date', 'Date'), ); // Instantiate the class using the path to the CSV // file and the columns. $path = 'path/relative/to/drupal/root/your_file.csv'; $this->source = new MigrateSourceCSV($path, $columns);
IDs, and MigrateItem for fetching values
values
// inside __construct() $this->map = new MigrateSQLMap($this->machineName, array( 'style' => array( 'type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'description' => 'Topic ID', ) ), MigrateDestinationTerm::getKeySchema() );
// inside __construct() // Create terms... $this->destination = new MigrateDestinationTerm('example_beer_styles'); // ...or nodes... $this->destination = new MigrateDestinationNode('article'); // ...or $this->destination = new MigrateDestinationUser();
// inside __construct() // Can be as simple as this... $this->addFieldMapping('name', 'style'); // ...or more complicated. $this->addFieldMapping(NULL, 'region')
MigrateFieldMapping::ISSUE_PRIORITY_MEDIUM)
$this->addFieldMapping('D', 'S1')->arguments( array('A1' => array('source_field' => 'S2')), array('A2' => array('source_field' => 'S3')) );
// Files have so many arguments there’s a helper // to build the array: $arguments = MigrateFileFieldHandler::arguments( drupal_get_path('module', 'migrate_example'), 'file_copy', FILE_EXISTS_RENAME, NULL, array('source_field' => 'image_alt'), array('source_field' => 'image_description')); $this->addFieldMapping('field_image', 'image')
$this->addFieldMapping('uid', 'author_id')
$this->dependencies = array('BeerUser');
$row->name = $row->first . “ ” . $row->last; $row->created = strtotime($row->access);