XF 1.4 Restoring a deleted users conversations

Warchamp7

Active member
Due to an admin's error we lost one of our oldest users and I'm trying to restore what I can without digging into backups or cross referenced queries.

I got posts/thread data restored using the username column to relink their new accounts user_id. I'm currently trying to figure out the process for restoring conversations.

Looking at xf_conversation_user, I don't really have something concrete to work with here. Is this table generated though? Do I need to restore anything there?

Alternatively: Is there an elegant query I can use to dump conversation data for user_id 111 and then import into the production database into user 2222?
 
There's a lot of complex and interlinked data here. Unfortunately, our recommendation is always going to be restoring from a backup.
 
I just had to do this for one of my users. I needed to add them as a recipient to all conversations where they previously made messages or that they were previously recipients to (need to check for both). The code that worked was:
Code:
// change the following lines as needed
$olduserid = 1;
$newuserid = 2;

$targetuser = \XF::finder('XF:User')->where('user_id', $newuserid)->fetchOne();

$fixer = \XF::finder('XF:ConversationMessage');
$fixer->where('user_id', $olduserid);
$messages = $fixer->fetch();

$convos = [];
foreach ($messages AS $message)
{
    $convos[$message['conversation_id']] = $message['conversation_id'];
}

$fixer = \XF::finder('XF:ConversationRecipient');
$fixer->where('user_id', $olduserid);
$fixer->where('recipient_state', 'deleted');
$recipients = $fixer->fetch();

foreach ($recipients AS $message)
{
    $convos[$message['conversation_id']] = $message['conversation_id'];
}

$masters = \XF::finder('XF:ConversationMaster')->where('conversation_id', $convos)->fetch();

foreach ($masters AS $master)
{
    \XF::repository('XF:Conversation')->insertRecipients($master, [$targetuser]);
}
 
Back
Top Bottom