Fixed vBulletin: Node tree messed up after import

Kirby

Well-known member
Affected version
1.1.0
PHP:
return $this->sourceDb->fetchAll($this->prepareImportSql($this->prefix, "
    SELECT * FROM forumpermission
"));

This does not enforce any order on the forums, so it can happen that non top-level-forums are the first ones being returned.

So when building the node tree, thos forums will be the first ones being processed and thus be the first ones to start the tree
PHP:
protected function prepareForumTree(array $forums)
{
    $forumTree = [];

    foreach ($forums AS $forumId => $forum)
    {
        $forumTree[$forum['parentid']][$forumId] = $forum;
    }

    return $forumTree;
}

When the tree is finally being processed, the parent node of teh first forum will be the first node being imported
PHP:
$oldParentId = array_keys($forumTree)[0];
$state->imported += $this->importNodeTree($forumTree, $forumPermissions, $oldParentId, $stepConfig['parent_node_id']);

So at this point, the parent node does not exist in XF yet causing the forum to be incorrectly imported with no parent at all.
 
I think most of this is ok and acceptable.

I think the part that is inherently wrong is:
PHP:
$oldParentId = array_keys($forumTree)[0];
We should certainly be starting with parent ID 0 regardless, and the way the recursion is handled should figure out the rest in the correct order so that no node can be imported before its parent has been (and therefore mapped to the correct new ID).

That said, not looked at this in loads of detail, so I suspect we'll need to make some other changes to the flow of the code here.
 
It should work with starting at parent ID -1, this is basically what I've done in custom importers (WBB, etc.) and seems to work just fine.
 
Thank you for reporting this issue. It has now been resolved and we are aiming to include it in a future XFI release (1.2.1).

Change log:
Ensure the parent/child relationship of nodes is maintained when importing from vBulletin.
Any changes made as a result of this issue being resolved may not be rolled out here until later.
 
Top Bottom