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

How to check XenForo version during an add-on install

Explains how to check the version of XenForo during an add-on install, and throw an error.

  1. Chris D

    Chris D XenForo Developer Staff Member

    Chris Deeming submitted a new resource:

    How to check XenForo version during an add-on install - Explains how to check the version of XenForo during an add-on install, and throw an error.

    Read more about this resource...
     
  2. Jeremy

    Jeremy Well-Known Member

    You may want to add in an explanation of what the version number actually entails. Not sure its entirely necessary, but I'm sure it could help.
     
    Chris D likes this.
  3. Liam W

    Liam W Well-Known Member

    Do you know how to get the addons version integer?
     
  4. Chris D

    Chris D XenForo Developer Staff Member

    Yeah, notice how the $installedAddOn parameter is passed into the install function? Well, if the add-on is already installed, (therefore an upgrade) that then contains an array of add-on related information.

    To use it properly:

    PHP:
    $version is_array($installedAddon) ? $installedAddon['version_id'] : 0;
    That first of all checks if $installedAddon is an array. If it is an array, it will be containing add-on information, so it sets $version as the version_id. If it isn't an array, to save problems later, we just set it to version 0.

    PHP:
    if ($version 110)
    {
         
    // Do something if version ID is below 110
    }
     
    Liam W and Pereira like this.
  5. Liam W

    Liam W Well-Known Member

    Thanks :)

    (I never knew the install/uninstall functions took parameters :/)

    Also, I never did understand those one-line if statement thingies (that's what I call them, dunno what they're really called).

    Anyhow, thanks!
     
  6. Chris D

    Chris D XenForo Developer Staff Member

    It's basically a collapsed if/else statement.

    It's the equivalent of this:

    PHP:
    if (is_array($installedAddon))
    {
        
    $version $installedAddon['version_id'];
    }
    else
    {
        
    $version 0;
    }
    I know which one I'd rather use ;)
     
  7. Liam W

    Liam W Well-Known Member

    @Chris Deeming do you know know if there's a log of past version ID's?

    I need the ID for xF 1.2.0, but all my installs are on 1.2.2, so I have no way of finding it :p

    Liam

    EDIT: No worries, I found the comment explaining the system:

    Code:
    // abbccde = a.b.c d (alpha: 1, beta: 3, RC: 5, stable: 7, PL: 9) e
    So, 1.2.0 would be:

    1020070

    I think...
     
    Last edited: Oct 18, 2013
    Chris D likes this.
  8. tyteen4a03

    tyteen4a03 Well-Known Member

    Correct. You can also verify this by actually downloading the zip file of 1.2.0 from the customer area.
     
    Chris D and Liam W like this.
  9. Liam W

    Liam W Well-Known Member

    Thanks :)

    (I wonder what e is used for...)
     
    Chris D likes this.
  10. Jeremy

    Jeremy Well-Known Member

    Its used for non-stable (or PL) releases increments. So:

    1030011

    That'd be 1.3.0 Alpha 1.
     
    Chris D and Liam W like this.
  11. Liam W

    Liam W Well-Known Member

    Ah, makes sense :)

    Thanks!
     
  12. rugk

    rugk Active Member

    Just for your information:
    If you want to display the XenForo version and version ID in the footer with enabled debug mode you can use this regular expression.

    Just add a TMS to the template 'footer' and enter this:
    Search for:
    Code:
    /\h*<xen:if is="{\$debugMode}">
    \h*<xen:if hascontent="true">
    \h*<dl class="pairsInline debugInfo".*?>
    (\h*)<xen:contentcheck>/
    Replace with (RegExp):
    Code:
    $0
    $1    <!-- Adding XenForo version strings -->
    $1    <dt>XenForo version:<dt> <dd>{$xenOptions.currentVersion} ({$xenOptions.currentVersionId})</dd>
    Here is what it the settings should look like:
    RegExpXenForoFooterTMS.png

    And that's how it will look:
    RegExpXenForoFooterDisplay.png
     

Share This Page