XF 2.1 Upgradeable Addon

Ozzy47

Well-known member
How can I set an addon as upgradable so I can see how it looks in the ACP when viewing addons. This is the relevant HTML from the addon_list template.
HTML:
<xf:macro template="addon_list_macros" name="addon_list_block"
            arg-addOns="{$upgradeable}" arg-heading="{{ phrase('upgradeable_add_ons') }}" />
 
I still have not found a solution to this.

I tried changing a addons version number in the DB to a lower version than was installed. I also installed a older version of XFMG. Neither shows as upgradable viewing the addon list.
 
Unfortunately I still have not found a way to do this. Hopefully someone comes along that has an idea.
 
Look at src/XF/Admin/Controller/AddOn.php the actionIndex function. Or, src/XF/AddOn/AddOn.php the canUpgrade function.
 
Last edited:
Keep in mind that a good portion of the variables used in templates come from PHP. While some might be created in a template, most come from a PHP file. With a good IDE you can search the source tree and locate where the variable is coming from.
 
Look at src/XF/Admin/Controller/AddOn.php the actionIndex function. Or, src/XF/AddOn/AddOn.php the canUpgrade function.

Either I am daft or it is so blatantly obvious but I still don't see how to set a addon to show up as upgradeable.
 
Either I am daft or it is so blatantly obvious but I still don't see how to set a addon to show up as upgradeable.
Just remember you said that, not me. :D

If all you're doing is looking at a display and that is only temporary for display test purposes....

Locate this in src/XF/AddOn/AddOn.php..
Code:
public function canUpgrade()
{
    return $this->isInstalled()
        && $this->isJsonHashChanged()
        && $this->isJsonVersionNewer()
        && $this->canEdit();
}

And temporarily change it to this...
Code:
public function canUpgrade()
{
    return true;
}

That will change all add-ons to "upgradable" and display them in the upgradable list.
 
1575102770517.webp

Code:
class YourClass extends XFCP_AddOn
{
    public function actionIndex()
    {
        $reply = parent::actionIndex();

        if ($reply instanceof \XF\Mvc\Reply\View)
        {
            $disabledAddOns = [];

            $installed = $reply->getParam('installed');

            foreach ($installed AS $id => $addOn)
            {
                if(!$addOn->active)
                {
                    $disabledAddOns[$id] = $addOn;
                    unset($installed[$id]);
                }
            }

            $reply->setParam('disabled_addons', $disabledAddOns);
            $reply->setParam('installed', $installed);

            $tab = $this->filter('tab', 'str');

            if(!$tab)
            {
                switch ($reply)
                {
                    case (!empty($reply->getParam('upgradeable')) ? $tab = 'upgradeable' : '');
                        break;

                    case (!$tab && !empty($reply->getParam('installable')) ? $tab = 'installable' : '');
                        break;

                    case (!$tab && !empty($reply->getParam('installed')) ? $tab = 'installed' : '');
                        break;

                    case (!$tab && !empty($reply->getParam('legacy')) ? $tab = 'legacy' : '');
                        break;

                    case (!$tab && !empty($reply->getParam('disabled')) ? $tab = 'disabled' : '');
                        break;
                }
            }

            $reply->setParam('tab', $tab);
        }

        return $reply;
    }
}
if (false)
{
    class XFCP_AddOn extends \XF\Admin\Controller\AddOn {}
}
 
Back
Top Bottom