Resource icon

How to check XenForo version during an add-on install

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.

With the public availability of XenForo 1.2 Beta 1, there will be times where add-ons are released that simply should not be installed on earlier versions of XenForo 1.1.x.

These may be add-ons that utilise some new XenForo 1.2.x feature such as Template Modifications, or you may simply be not supporting older versions of XenForo.

First, you need to create a file called Install.php and place this inside your add-ons library directory, e.g:

<xenforo...

Read more about this resource...
 
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.
 
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
}
 
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
}

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!
 
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 ;)
 
@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:
@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, 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...
Correct. You can also verify this by actually downloading the zip file of 1.2.0 from the customer area.
 
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.webp

And that's how it will look:
RegExpXenForoFooterDisplay.webp
 
Back
Top Bottom