/**
  * 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)
 {
     // 1. Check to make sure that this application is allowed to be disabled
     $ApplicationInfo = (array) arrayValueI($applicationName, $this->availableApplications(), array());
     $applicationName = $ApplicationInfo['Index'];
     if (!val('AllowDisable', $ApplicationInfo, 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
     foreach ($this->enabledApplications() as $CheckingName => $CheckingInfo) {
         $RequiredApplications = val('RequiredApplications', $CheckingInfo, false);
         if (is_array($RequiredApplications) && array_key_exists($applicationName, $RequiredApplications) === true) {
             throw new Exception(sprintf(t('You cannot disable the %1$s application because the %2$s application requires it in order to function.'), $applicationName, $CheckingName));
         }
     }
     // 3. Check to make sure that no other enabled plugins rely on this one
     $DependendPlugins = array();
     foreach (Gdn::pluginManager()->enabledPlugins() as $CheckingName => $CheckingInfo) {
         $RequiredApplications = val('RequiredApplications', $CheckingInfo, false);
         if (is_array($RequiredApplications) && array_key_exists($applicationName, $RequiredApplications) === true) {
             $DependendPlugins[] = $CheckingName;
         }
     }
     if (!empty($DependendPlugins)) {
         throw new Exception(sprintf(t('You cannot disable the %1$s application because the following plugins require it in order to function: %2$s'), $applicationName, implode(', ', $DependendPlugins)));
     }
     // 2. Disable it
     removeFromConfig("EnabledApplications.{$applicationName}");
     Logger::event('addon_disabled', Logger::NOTICE, 'The {addonName} application was disabled.', array('addonName' => $applicationName));
     // Clear the object caches.
     Gdn_Autoloader::smartFree(Gdn_Autoloader::CONTEXT_APPLICATION, $ApplicationInfo);
     // Redefine the locale manager's settings $Locale->Set($CurrentLocale, $EnabledApps, $EnabledPlugins, true);
     $Locale = Gdn::locale();
     $Locale->set($Locale->current(), $this->enabledApplicationFolders(), Gdn::pluginManager()->enabledPluginFolders(), true);
     $this->EventArguments['AddonName'] = $applicationName;
     Gdn::pluginManager()->callEventHandlers($this, 'ApplicationManager', 'AddonDisabled');
 }
Example #2
0
 /**
  * Creates a VALUE attribute for a form input and returns it in this format: [ value="VALUE"]
  *
  * @param string $FieldName The name of the field that contains the value in $this->_DataArray.
  * @param array $Attributes An associative array of attributes for the input. ie. maxlength, onclick,
  *    class, etc. If $Attributes contains a 'value' key, it will override the
  *    one automatically generated by $FieldName.
  * @return string
  */
 protected function _valueAttribute($FieldName, $Attributes)
 {
     // Value from $Attributes overrides the datasource and the postback.
     return ' value="' . Gdn_Format::form(arrayValueI('value', $Attributes, $this->getValue($FieldName))) . '"';
 }
 /**
  * Test if an application can be enabled.
  *
  * @param string $applicationName The name of the application to test.
  * @return bool Returns true if the application can be enabled or false otherwise.
  * @throws Exception Throws an exception if the application is not in the correct format.
  */
 public function testApplication($applicationName)
 {
     // Add the application to the $EnabledApplications array in conf/applications.php
     $ApplicationInfo = arrayValueI($applicationName, $this->availableApplications(), array());
     $applicationName = $ApplicationInfo['Index'];
     $ApplicationFolder = val('Folder', $ApplicationInfo, '');
     if ($ApplicationFolder == '') {
         throw new Exception(t('The application folder was not properly defined.'));
     }
     // Hook directly into the autoloader and force it to load the newly tested application
     $this->addonManager->startAddonsByKey([$applicationName], \Vanilla\Addon::TYPE_ADDON);
     // Call the application's setup method
     $hooks = $applicationName . 'Hooks';
     if (!class_exists($hooks)) {
         $hooksPath = PATH_APPLICATIONS . DS . $ApplicationFolder . '/settings/class.hooks.php';
         if (file_exists($hooksPath)) {
             include_once $hooksPath;
         }
     }
     if (class_exists($hooks)) {
         /* @var Gdn_IPlugin $hooks The hooks object should be a plugin. */
         $hooks = new $hooks();
         if (method_exists($hooks, 'setup')) {
             $hooks->setup();
         }
     }
     return true;
 }