Addons should always check their dependants before being disabled. This check does not consider dependants that
are not enabled.
public checkDependants ( |
||
$addon | The addon to check. | |
$throw | boolean | Whether or not to throw an exception or just return **false** if the check fails. |
return | boolean | Returns **true** if the addon a |
/** * Disable a plugin. * * @param string $pluginName The name of the plugin. * @return bool * @throws Exception */ public function disablePlugin($pluginName) { $addon = $this->addonManager->lookupAddon($pluginName); if (!$addon) { return false; } $pluginClassName = $addon->getPluginClass(); $pluginName = $addon->getRawKey(); $enabled = $this->addonManager->isEnabled($pluginName, Addon::TYPE_ADDON); try { $this->addonManager->checkDependants($addon, true); } catch (\Exception $ex) { throw new Gdn_UserException($ex->getMessage(), 400); } // 2. Perform necessary hook action $this->pluginHook($pluginName, self::ACTION_DISABLE, true); // 3. Disable it. saveToConfig("EnabledPlugins.{$pluginName}", false); $this->addonManager->stopAddon($addon); // 4. Unregister the plugin properly. $this->unregisterPlugin($pluginClassName); if ($enabled) { Logger::event('addon_disabled', Logger::INFO, 'The {addonName} plugin was disabled.', array('addonName' => $pluginName)); } // Redefine the locale manager's settings $Locale->Set($CurrentLocale, $EnabledApps, $EnabledPlugins, TRUE); Gdn::locale()->refresh(); $this->EventArguments['AddonName'] = $pluginName; $this->fireEvent('AddonDisabled'); return true; }
/** * Disable an application. * * @param string $applicationName The name of the application to disable. * @throws \Exception Throws an exception if the application can't be disabled. */ public function disableApplication($applicationName) { $addon = $this->addonManager->lookupAddon($applicationName); if (!$addon) { throw notFoundException('Application'); } $applicationName = $addon->getRawKey(); // 1. Check to make sure that this application is allowed to be disabled if (!$addon->getInfoValue('allowDisable', true)) { throw new Exception(sprintf(t('You cannot disable the %s application.'), $applicationName)); } // 2. Check to make sure that no other enabled applications rely on this one. try { $this->addonManager->checkDependants($addon, true); } catch (Exception $ex) { throw new Gdn_UserException($ex->getMessage(), $ex->getCode()); } // 2. Disable it removeFromConfig("EnabledApplications.{$applicationName}"); Logger::event('addon_disabled', Logger::NOTICE, 'The {addonName} application was disabled.', array('addonName' => $applicationName)); // Clear the object caches. $this->addonManager->stopAddonsByKey([$applicationName], \Vanilla\Addon::TYPE_ADDON); }