/** * Builds plugins list that will be passed to templates engine. * * @return array */ protected function buildPluginsList() { $plugins = array(); foreach (PluginUtils::discoverPlugins() as $plugin_name) { $plugin = new PluginInfo($plugin_name); $plugins[] = array('name' => $plugin_name, 'version' => $plugin->isInstalled() ? $plugin->getInstalledVersion() : $plugin->getVersion(), 'dependencies' => array_merge($plugin->getSystemRequirements(), $plugin->getDependencies()), 'enabled' => $plugin->isEnabled(), 'installed' => $plugin->isInstalled(), 'needsUpdate' => $plugin->needsUpdate(), 'canBeEnabled' => $plugin->canBeEnabled(), 'canBeDisabled' => $plugin->canBeDisabled(), 'canBeUninstalled' => $plugin->canBeUninstalled(), 'canBeUpdated' => $plugin->canBeUpdated(), 'state' => $this->getPluginState($plugin)); } return $plugins; }
/** * Tries to enable a plugin. * * @param string $plugin_name Name of the plugin to enable. * @return boolean Indicates if the plugin has been enabled or not. */ public function enable($plugin_name) { $plugin = new PluginInfo($plugin_name); if ($plugin->isEnabled()) { // The plugin is already enabled. There is nothing we can do. return true; } if (!$plugin->canBeEnabled()) { // The plugin cannot be enabled. return false; } if (!$plugin->isInstalled()) { // Try to install the plugin. $plugin_class = $plugin->getClass(); if (!$plugin_class::install()) { return false; } // Plugin installed successfully. Update the state $plugin->getState()->version = $plugin->getVersion(); $plugin->getState()->installed = true; } $plugin->getState()->enabled = true; $plugin->getState()->save(); return true; }