This module worked great for me, except that it lacked the ability to map to CCK user reference fields. My company syndicates content between multiple online properties that it owns, and we need to match users coming in via a feed to local usernames. I wrote a mapper to do that, which I think could be included in the base distribution. It is attached. (The file should be named feedapi_mapper_userreference.inc but drupal.org does not accept .inc attachments)

Great job otherwise!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alex_b’s picture

Version: 6.x-1.0-beta4 » 6.x-1.x-dev

I assume this patch applies to 6.x just as to beta 4.

xmattus’s picture

Yes -- should be drop-and-go for any version.

TKS’s picture

Status: Needs review » Needs work

I get two iterations of the following warning when I drop this in as feedapi_mapper_userreference.inc:

    * warning: Missing argument 3 for userreference_feedapi_mapper() in /home/newdev/public_html/sites/all/modules/feedapi_mapper/mappers/feedapi_mapper_userreference.inc on line 20.

Also, no user-reference option appears in the mapping-target pulldown.

I'm working with 6.x-1.0-beta12. Has something changed that requires a tweak to this .inc file? Or is $field_name variable -- which appears to be argument three on line 20 -- getting lost/not created/whatever elsewhere?

Happy to help test this addition -- and it'd be hugely useful to us! -- but I'm not sure where to start on fixing it.

Thanks

TKS’s picture

UPDATE: Found mention of the same warning in http://drupal.org/node/224235, and -- per alex_b's suggestion in http://drupal.org/node/224235#comment-1734770 -- updated line 20 to match the example in feedapi_mapper.api.php to:

function userreference_feedapi_mapper($op, $node, $feed_element = array(), $field_name = '', $sub_field = '') ...

That gets rid of the warnings, but I still get no mapping option.

I'm guessing that there were API changes for the ($op == 'list') and/or ($op == 'map') portions too, but the logical changes there aren't nearly as obvious to me as line 20 was.

xmattus’s picture

Version: 6.x-1.x-dev » 6.x-1.0-beta12
FileSize
2.05 KB

Upon inspection, it seems a number of things about hook_feedapi_mapper have changed since beta4, including which parameters are passed in. I've retooled this mapper according to the main CCK mapper, so hopefully it works for you. Give it a whirl and let me know. (Same filename caveat applies -- it should be named feedapi_mapper_userreference.inc)

xmattus’s picture

Status: Needs work » Needs review
xmattus’s picture

To clarify -- the function has to return some different stuff than it did before (namely an array rather than a boolean), so that explains you not seeing the user ref option.

TKS’s picture

Just imported about 200 nodes as a test, and xmattus' revised .inc file (from comment #5) works flawlessly for me.

I was parsing in taxonomy terms -- we have an "author" vocabulary on our current D5 site, and are moving to a user-reference structure in D6. Those terms match usernames that we've already created in the D6 site.

One important thing to note: If there's a name that doesn't match -- for example, a former staffer for whom we neglected to create a user account on the new site -- the parser just ignores it. That's ideal, IMHO, as you don't want the mapping to choke on that, and it would be kinda crazy to attempt to create new accounts on the fly. I just mention it here for others who may want to use this.

xmattus’s picture

That is correct, only extant users are matched by this mapper. It would actually not be terribly complex to create user accounts on the fly, but it requires some assumptions about what the default email address and such would be when it is not known otherwise. As this would be a more "extreme" behavior, I leave it to anyone who needs said behavior to customize further.

xmattus’s picture

Status: Needs review » Reviewed & tested by the community