Example #1
0
 /**
  * Checks if the plugin can be disabled.
  *
  * @return boolean
  */
 public function canBeDisabled()
 {
     if (!$this->isEnabled()) {
         // The plugin was not enabled thus it cannot be disabled
         return false;
     }
     // Make sure that the plugin has no enabled dependent plugins.
     foreach ($this->getDependentPlugins() as $plugin_name) {
         $plugin = new PluginInfo($plugin_name);
         if ($plugin->isEnabled()) {
             return false;
         }
     }
     return true;
 }
Example #2
0
 /**
  * Gets string representation of the current plugin state.
  *
  * @param PluginInfo $plugin Plugin to get state for.
  * @return string Human readable representation of plugin's state.
  */
 protected function getPluginState(PluginInfo $plugin)
 {
     if (!$plugin->isEnabled()) {
         // The plugin is just disabled
         return getlocal('disabled');
     }
     if (PluginManager::getInstance()->hasPlugin($plugin->getName())) {
         // The plugin is enabled and works well
         return getlocal('working');
     }
     // The plugin is enabled but something is wrong.
     if ($plugin->needsUpdate()) {
         // The plugin is not working because it needs to be updated.
         return getlocal('needs update');
     }
     // Actually we do not know why the plugin does not work. The only thing
     // that can be said is the plugin was not initialized correctly by some
     // reasons.
     return getlocal('not initialized');
 }
Example #3
0
 /**
  * Tries to disable a plugin.
  *
  * @param string $plugin_name Name of the plugin to disable.
  * @return boolean Indicates if the plugin has been disabled or not.
  */
 public function disable($plugin_name)
 {
     $plugin = new PluginInfo($plugin_name);
     if (!$plugin->isEnabled()) {
         // The plugin is not enabled
         return true;
     }
     if (!$plugin->canBeDisabled()) {
         // The plugin cannot be disabled
         return false;
     }
     $plugin->getState()->enabled = false;
     $plugin->getState()->save();
     return true;
 }