Checking for the existance of other add-ons while installing

farang

Well-known member
Hi!

What would be a good way to check for the existance of add-on "a" when installing add-on "b"?

I started with the following code but I'm sure it will not work ...


Code:
<?php

class myAddOn_Installer
{
     
  public static function install($installedAddon)
    {
        if (class_exists('SomeOtherAddOn_Forum'))
        {
            throw new XenForo_Exception('You need to uninstall the plugin named "Someother Add-on" before installing this add-on.', true);
        }
    }

}
 
@Xon provided me this wonderful code snippet a while ago to check for an addon upon installation and uninstall it in that case:
PHP:
        $addonsToUninstall = array(...);
        $addonModel = XenForo_Model::create("XenForo_Model_AddOn");
        foreach($addonsToUninstall as $addonToUninstall)
        {
            $addon = $addonModel->getAddOnById($addonToUninstall);
            if (!empty($addon))
            {
                $dw = XenForo_DataWriter::create('XenForo_DataWriter_AddOn');
                $dw->setExistingData($addonToUninstall);
                $dw->delete();
            }
        }

In the same manner you should be able to do the following:
PHP:
  public static function install($installedAddon)
    {
        $addonModel = XenForo_Model::create("XenForo_Model_AddOn");
        if ($addonModel->getAddOnById('someOtherAddon'))
        {
            throw new XenForo_Exception('You need to uninstall the plugin named "Someother Add-on" before installing this add-on.', true);
        }
    }
 
Top Bottom