XF 2.1 How to use XF\Import\Data\LikedContent

Kirby

Well-known member
We do have several custom importers for forum systems like WBB, UBB, etc. and also for Add-ons like the popular "Post Thanks" for vBulletin.

If appropriate, those importers also have code to import data that can be transformed into Like reactions, for example
PHP:
/** @var \XF\Import\Data\LikedContent $import */
$import = $this->newHandler('XF:LikedContent');
$import->preventRetainIds();
$import->bulkSet([
    'content_type' => 'post',
    'content_id' => $newContentId,
    'content_user_id' => $newContentUserId,
    'like_user_id' => $newLikeUserId,
    'like_date' => $thank['dateline'],
    'is_counted' => 1,
]);
if ($newId = $import->save($oldId))
{
    $state->imported++;
}

This code does work just fine on XF 2.0, but does fail on XF 2.1 due to field reaction_user_id not being set.

Of course I could just change the code to use XF:ReactionContent instead, but I'd really like to know how to make this existing code work properly with XF 2.1 XF:LikedContent apparently still being supported as it got bugfixes for XF 2.1.

Does anyone know how to do that?
Or maybe @Chris D or @Mike could give some feedback on this?
 
For XF 2.1 your code would be:
PHP:
/** @var \XF\Import\Data\LikedContent $import */
$import = $this->newHandler('XF:LikedContent');
$import->preventRetainIds();
$import->bulkSet([
    'content_type' => 'post',
    'content_id' => $newContentId,
    'content_user_id' => $newContentUserId,
    'reaction_user_id' => $newLikeUserId,
    'reaction_date' => $thank['dateline'],
    'is_counted' => 1,
]);
if ($newId = $import->save($oldId))
{
    $state->imported++;
}
 
Hmm, that looks extremely strange to me - why would I use XF:LikedContent if I have to set data (reaction_user_id, etc.) that does not exist in Likes (only in Reactions)?

If that is necessary, it would seem cleaner to me to just use XF:ReactionContent instead, using it the way you posted looks like Frankenstein code to me ;)
 
We might make changes here but it's purely for backwards compatibility with older importers.

On the flip side it would be strange to be using the old column names because they no longer exist. If you're updating the code anyway for XF 2.1, of course you might as well use the ReactionContent handler (or the new column names) because that's what you're actually importing into.
 
If you're updating the code anyway for XF 2.1, of course you might as well use the ReactionContent handler (or the new column names) because that's what you're actually importing into.
Yes, that's what I tried to point out - if the code needs to be updated anyway I really does not make sense (to me) to adjust the existing Like code to make it work instead of just replacing it with a reaction handler.

IMHO you should either just remove the XF:LikedContent import data handler as it can't be used as it was in 2.0 or make it work transparently for backwards compatibility - the current state feels broken to me (hence my related bug reports).
 
Back
Top Bottom