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

XF 2.0 Setup.php - uninstall another plugin

Jumuro

Active member
#1
Hi.
Tell me if I can remove another add-on using Setup.php?
Or how to implement it?
When you install one of the add-on you want to remove the other, to resolve possible conflicts.
 

Chris D

XenForo developer
Staff member
#2
The easiest way to do this is just to block install of the new add-on if the old one is still installed. That puts the onus on the end user to remove the add-on via the UI.

To do this you can add a special method to your Setup class:
PHP:
class Setup extends XF\AddOn\AbstractSetup
{
    public function checkRequirements(&$errors = [], &$warnings = [])
    {
        $addOn = $this->app->em()->find('XF:AddOn', 'OldAddOnId');
        
        if ($addOn)
        {
            $errors[] = 'Please uninstall "Old Add-on" before continuing with the installation.';
        }
    }
    
    // other setup methods
}
If you absolutely must remove it problematically then you'd likely have to roll your own solution. A good example of how to approach uninstalling an add-on properly would be in XF\Cli\Command\AddOnActionTrait (the method name, in this case, would be uninstall.