1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WebWiz -> XenForo importer

Discussion in 'XenForo Development Discussions' started by Jens E. Hummelmose, Mar 1, 2016.

  1. Hi.

    I've decided to write an WebWiz -> XenForo Importer, but it would be nice to have some kind of database documentation, or API description.

    Could you provide me with som info on what is "needed" and "optional" fields when I import data from other systems. And if I want to keep original ID's. what to do. Is it just done with SQL, or???

    I'm a .net/php developer / DBA, så I just need some directions so I don't need to do "to much" reengineering.

    Much appreciated.
     
    Last edited: Mar 1, 2016
  2. Chris D

    Chris D XenForo Developer Staff Member

    Ultimately, the answer to your question is already in the code, though, to be fair, there's an additional step that isn't clear.

    Last thing, first, the code you need to look for guidance is the existing importers that XF provides. You can see these listed when you go to Admin CP > Tools > Import External Data.

    Each of the listed importers code is in the following directory: library/XenForo/Importer

    I would suggest that the best ones to look at are:
    • IPBoard.php
    • MyBB.php
    • PhpBb3.php
    • SMF.php
    • vBulletin.php
    You'll notice each of these extends the abstract class in the same directory, XenForo_Importer_Abstract (Abstract.php), yours will need to extend the same class.

    This should give you an idea of what is involved in creating your own importer, but it isn't for the feint hearted if you're not familiar with XenForo. I expect you'll have further questions (which is fine).

    The additional step, however, is something you will need to "register" your importer so it appears on the Import External Data page and be able to package it up as an add-on.

    The first step is to enable debug mode by adding:
    PHP:
    $config['debug'] = true;
    To your config.php file.

    Once you do this, when you log in to your Admin CP you will see a new "Development" tab along the top.

    Click that, and in the navigation menu select "Create add-on".

    You will need to provide a short, alpha numeric add-on ID, e.g. "MyAddOn" a title, e.g. "My Add-on" and a version string and version ID.

    Next you need to create a file in the following location: library/MyAddOn/Listener.php (where MyAddOn is the add-on ID you chose above).

    In that file, you'll need the following contents. Again change the MyAddOn part in the class name to your add-on ID.

    PHP:
    <?php

    class MyAddOn_Listener
    {
       public static function 
    extendImportModel($class, array &$extend)
       {
            
    // You'll add code here later
       
    }
    }
    Then there are a few more straight forward steps:
    1. Once the add-on is created, go back to the Development tab and select "Code Event Listeners".
    2. Click "Create New Code Event Listener"
    3. For "Listen To Event" select "load_class_model"
    4. Event Hint should be "XenForo_Model_Import"
    5. Execute callback is MyAddOn_Listener :: extendImportModel
    6. Finally in the "Add-on" drop down select your add-on from the list
    Click save and that should do so without any errors.

    Finally, in the PHP file you created above, remove the // You'll add code here later comment and replace with:
    PHP:
    XenForo_Model_Import::$extraImporters[] = 'MyAddOn_Importer_WebWiz';
    XenForo uses a class proxy system to allow core XenForo classes to be extended multiple times by add-ons. Here's a good explanation:
    https://xenforo.com/community/resources/understanding-the-xenforo-class-proxy-system.2080/

    The code above will mean that when the XenForo_Model_Import class is instantiated, the static array inside that class will now contain an additional importer - yours. This is effectively registering that importer so it can be selected on the Import External Data page. So the last thing to do is to create the MyAddOn_Importer_WebWiz class (again replace MyAddOn with your add-on ID). The class names by convention are derived by the location of the code on the file system. So just like MyAddOn_Listener corresponded to library/MyAddOn/Listener.php and just like XenForo_Model_Import corresponds to library/XenForo/Model/Import.php, you will need to create your importer in the library/MyAddOn/Importer/WebWiz.php file...

    And that's the easy bit ;) You will now just need to start populating the WebWiz.php file with PHP which extends the XenForo_Import_Abstract class while closely mimicking the design of some of the importers we've already written.

    Good luck!
     
    kimchuy likes this.
  3. Thanks for the answer.

    I will look into it.

    /Jens
     

Share This Page