Feeds Usermapper
grayside — Mon, 04/12/2010 - 13:14
If you are using Feeds to migrate site content, one of the stumbling blocks will be preserving content ownership.
This code is taken from a hypothetical feeds_usermapper module that provides the option to sync up node ownership on the basis of identical usernames. (Pulled from User Inheritance Issue on D.O)
<?php
/<strong>
* Implementation of hook_migrate_fields_node().
*/
function feeds_usermapper_feeds_node_processor_targets_alter(&$targets, $content_type) {
$targets['uid'] = array(
'name' => t('Node author'),
'description' => t('The owner of the node.'),
'callback' => 'feeds_usermapper_feeds_set_target',
);
}
/</strong>
* Mapping callback for author.
*/
function feeds_usermapper_feeds_set_target($node, $target, $value) {
// [insert optional username transformation here]
$user = user_load(array('name' => $value));
if (isset($user->uid)) {
$node->uid = $user->uid;
}
}
?>