mybb / merge-system

The MyBB Merge System allows for easy merging of an existing forum (be it MyBB or another forum software) into a MyBB 1.8.x forum.
Other
32 stars 33 forks source link

Make sure that all forums have a parent category #179

Closed JN-Jones closed 9 years ago

JN-Jones commented 9 years ago

Some softwares allow forums without a parent category, however we require a category and forums without a category aren't shown. For some boards (like Vanilla) which have only categories the merge system already creates a parent category, however boards like phpBB have apparently both and only the category -> forum ones are correctly displayed. The merge system should loop through all imported forums, check whether there's a category as main parent and if not create a new category and move all of those forums below that.

$non_cat = array();
$query = $db->simple_select('forums', '*', "type='f' AND import_fid > 0"); // Probably also where parent = 0
while($forum = $db->fetch_array($query))
{
    $parent = get_main_parent($forum); // First element in parentlist?
    if($parent['type'] != 'c' && !in_array($parent, $non_cat))
         $non_cat[] = $parent;
}

if(!empty($non_cat))
{
    // Create category
    // Move **all** subforums (copy from acp?)
}
JN-Jones commented 9 years ago

Probably better:

$query = $db->simple_select('forums', '*', "type='f' AND parent=0 AND import_fid > 0");

if($db->num_rows($query) > 0)
{
    $cid = // Create category

    while($forum = $db->fetch_array($query))
    {
        // Update the parentlist of this forum.
        $db->update_query("forums", array("parent" => $cid, "parentlist" => make_parent_list($forum['fid'])), "fid='{$forum['fid']}'"); // Probably need to be split in 2 queries

        // Rebuild the parentlist of all of the subforums of this forum
        switch($db->type)
        {
            case "sqlite":
            case "pgsql":
                $query = $db->simple_select("forums", "fid", "','||parentlist||',' LIKE '%,$forum['fid'],%'");
                break;
            default:
                $query = $db->simple_select("forums", "fid", "CONCAT(',',parentlist,',') LIKE '%,$forum['fid'],%'");
        }

        while($child = $db->fetch_array($query))
        {
            $db->update_query("forums", array("parentlist" => make_parent_list($child['fid'])), "fid='{$child['fid']}'");
        }
    }
}