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

Checking for the existance of other add-ons while installing

Discussion in 'XenForo Development Discussions' started by farang, Mar 9, 2016.

  1. farang

    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);
            }
        }
    
    }
     
  2. katsulynx

    katsulynx Well-Known Member

    @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);
            }
        }
     
    Xon and farang like this.
  3. farang

    farang Well-Known Member

    Thank You very much @katsulynx , I appreciate it a lot!
     

Share This Page