1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. This forum is for release discussion only. Discussions that do not relate specifically to the resource release should be discussed in another, more appropriate forum.
    Dismiss Notice
  3. This forum has been archived. New threads and replies may not be made. All add-ons/resources that are active should be migrated to the Resource Manager. See this thread for more information.

Prevent the "Main Forum" from being created during installation

Discussion in 'Code Modifications [Archive]' started by Brogan, Nov 24, 2010.

  1. Brogan

    Brogan XenForo Moderator Staff Member

    If, like me, you want to reserve the first x number of node IDs for categories, here's how to stop the "Main Forum", which has a node ID of 2, from being created during installation.

    This might seem an odd thing to do at first, but categories are the only node type for which you can't (currently?) define a URL Portion/Stub and as such, the node id is always appended to the URL, for example: http://xenforo.com/community/#official-forums.1

    Open the following file: library\XenForo\Install\Data\MySql.php

    Find the following code around line 1780:
    PHP:
    $data[] = "
        INSERT INTO xf_node
            (node_id, title, description, node_type_id, parent_node_id, display_order, lft, rgt, depth)
        VALUES
            (1, 'Main Category', '', 'Category', 0, 1, 1, 4, 0),
            (2, 'Main Forum', '', 'Forum', 1, 1, 2, 3, 1)
    "
    ;

    $data[] = "
        INSERT INTO xf_forum
            (node_id, discussion_count, message_count, last_post_id, last_post_date, last_post_user_id, last_post_username)
        VALUES
            (2, 0, 0, 0, 0, 0, '')
    "
    ;
    Replace it with this:
    PHP:
    $data[] = "
        INSERT INTO xf_node
            (node_id, title, description, node_type_id, parent_node_id, display_order, lft, rgt, depth)
        VALUES
            (1, 'Main Category', '', 'Category', 0, 1, 1, 2, 0)
    "
    ;
    Install the software as normal and after installation, there will now only be 1 node which is the "Main Category", as follows:
    category.PNG

    Now you can create as many nodes as you want as categories (keeping some for later use as necessary) and the numbering will be sequential.
     
    4getmenot likes this.
  2. Shadab

    Shadab Well-Known Member

    The correct values for lft and rgt should be 1 and 2 respectively. I haven't checked if the installer rebuilds these values after each install/upgrade. If it does, you can ignore this post. :)
    PHP:
    $data[] = "
        INSERT INTO xf_node
            (node_id, title, description, node_type_id, parent_node_id, display_order, lft, rgt, depth)
        VALUES
            (1, 'Main Category', '', 'Category', 0, 1, 1, 2, 0)
    "
    ;
     
    Brogan likes this.
  3. Brogan

    Brogan XenForo Moderator Staff Member

    Thanks Shadab, nice spot :)

    I've updated the first post.
     
  4. Deepmartini

    Deepmartini Well-Known Member

    Is this still the case now that 1.1 has been released?
     
  5. fredrikse

    fredrikse Active Member

    I still don't understand why it is important to have plenty of ID's reserved for categories at the beginning :confused: Anyone who can explain it to me?
     
  6. Brogan

    Brogan XenForo Moderator Staff Member

    Because I have OCD.
     
    Dan, Fuhrmann, Vincent and 1 other person like this.
  7. fredrikse

    fredrikse Active Member

  8. Brogan

    Brogan XenForo Moderator Staff Member

  9. fredrikse

    fredrikse Active Member

    Alright. No further questions.
     

Share This Page