Closed (won't fix)
Project:
Migrate Extras
Version:
master
Component:
Documentation
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
15 Jan 2010 at 01:14 UTC
Updated:
23 Jun 2011 at 23:21 UTC
I've created a small library of functions, which help me with common tasks that I need to do repetitively within prepare hooks in my migrate scripts. These tasks include:
My function library is attached here, as a patch which adds a new file to migrate_extras called migrate_extras.snippets.inc.
Some sample code of how I use this function library in a custom module:
/**
* Implementation of hook_migrate_prepare_user().
*/
function migrate_dummy_migrate_prepare_user(&$account, $tblinfo, $row) {
$errors = array();
switch ($tblinfo->view_name) {
case 'dummydata_people':
module_load_include('inc', 'migrate_extras', 'migrate_extras.snippets');
// snip
$account['pass'] = migrate_extras_rand_str();
// snip
if ($tid = migrate_extras_lookup_taxonomy_tid($row->dummydata_people_tags, array(1))) {
$account['profile|taxonomy'][1] = array($tid);
}
// snip
if ($nid = migrate_extras_lookup_node_nid($row->dummydata_people_foo, array('foo'))) {
$account['profile|field_foo_nid'] = $nid;
}
// snip
$refs = migrate_extras_prepare_nodereferences($row->dummydata_people_bar, array('bar'));
if (!empty($refs)) {
$account['profile|field_bar'] = $refs;
}
// snip
$src_dir = 'import/images/profile';
$dest_dir = variable_get('file_directory_path', 'files') . '/images/profile';
$filename = $row->dummydata_people_image;
migrate_extras_copy_files($src_dir, $dest_dir);
if ($image = migrate_extras_prepare_filefield($filename, $dest_dir, $name)) {
$account['profile|field_profile_image'][0] = $image;
}
else {
$errors[] = array('level' => MIGRATE_MESSAGE_NOTICE, 'message' => t('Failed to find profile image file %file, not importing record with id %id.', array('%file' => $filename, '%id' => $row->dummydata_people_legacyid)));
}
break;
}
return $errors;
}
/**
* Implementation of hook_migrate_prepare_user().
*/
function migrate_dummy_migrate_complete_user(&$account, $tblinfo, $row) {
$errors = array();
switch ($tblinfo->view_name) {
case 'dummydata_people':
module_load_include('inc', 'migrate_extras', 'migrate_extras.snippets');
$dest_dir = variable_get('file_directory_path', 'files') . '/images/profile';
migrate_extras_complete_filefield($row->dummydata_people_image, $account->uid, $dest_dir);
break;
}
return $errors;
}
I think this would be a very useful addition to the migrate_extras module. Hoping you will consider adding my include file to the module.
| Comment | File | Size | Author |
|---|---|---|---|
| migrate_extras_snippets.patch | 6.68 KB | Jaza |
Comments
Comment #1
Jaza commentedNote: the sample code above (and, basically, the snippets library) depends on these two patches:
#684232: Remove content_profile integration from 2.x
#685256: md5pass feature causes fatal errors
Comment #2
edrauta commentedSubscribe
how is file snippet?
you can upload de module?
Comment #3
eloivaqueI need the code nodereference to multiple values
But I not where to put the inside the module of migrate_extras, can you help me please? :)
Comment #4
mikeryanMigrate and Migrate Extras V1 are no longer supported, so these snippets are obsolete. For Migrate V2, please submit useful snippets to the Cookbook in the documentation at http://drupal.org/node/1007002.