/**
  * Retrieves info about plugins available in the system.
  *
  * @return array Associative array of plugins info. Each key of the array is
  * fully qualified plugin's name and each value is an array with the
  * fillowing keys:
  *  - "version": string, version of the plugin which presents in the system.
  *  - "installed": boolean, indicates if the plugin is installed.
  *  - "enabled": boolean, indicates if the plugin is enabled.
  */
 protected function getPluginsInfo()
 {
     if (is_null($this->pluginsInfo)) {
         $this->pluginsInfo = [];
         $names = PluginUtils::discoverPlugins();
         foreach ($names as $plugin_name) {
             $info = new PluginInfo($plugin_name);
             $this->pluginsInfo[$plugin_name] = array('version' => $info->getVersion(), 'installed' => $info->getState()->installed, 'enabled' => $info->getState()->enabled);
         }
     }
     return $this->pluginsInfo;
 }
 /**
  * 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');
 }
Beispiel #3
0
 /**
  * Sets state related with depth-first search algorithm for a plugin.
  *
  * @param PluginInfo $plugin A plugin for which the state should be set.
  * @param string $state One of DependencyGraph::DFS_* constants.
  */
 protected function setDfsState(PluginInfo $plugin, $state)
 {
     $this->dfsState[$plugin->getName()] = $state;
 }
Beispiel #4
0
 /**
  * Checks if the plugin can be updated.
  *
  * @return boolean
  */
 public function canBeUpdated()
 {
     if (!$this->needsUpdate()) {
         return false;
     }
     foreach (array_keys($this->getDependencies()) as $dependency_name) {
         $dependency = new PluginInfo($dependency_name);
         if ($dependency->needsUpdate()) {
             return false;
         }
     }
     return true;
 }
Beispiel #5
0
 /**
  * Tries to update a plugin.
  *
  * @param string $plugin_name Name of the plugin to update.
  * @return boolean Indicates if the plugin has been updated or not.
  */
 public function update($plugin_name)
 {
     $plugin = new PluginInfo($plugin_name);
     if (!$plugin->needsUpdate()) {
         // There is no need to update the plugin
         return true;
     }
     if (!$plugin->canBeUpdated()) {
         // The plugin cannot be updated.
         return false;
     }
     try {
         // Perform incremental updates
         $updates = MaintenanceUtils::getUpdates($plugin->getClass());
         foreach ($updates as $version => $method) {
             // Skip updates to lower versions.
             if (version_compare($version, $plugin->getInstalledVersion()) <= 0) {
                 continue;
             }
             // Skip updates to versions that greater then the current plugin
             // version.
             if (version_compare($version, $plugin->getVersion()) > 0) {
                 break;
             }
             // Run the update
             if (!$method()) {
                 // By some reasons we cannot update to the next version.
                 // Stop the process here.
                 return false;
             }
             // Store new version number in the database. With this info
             // we can rerun the updating process if one of pending
             // updates fails.
             $plugin->getState()->version = $version;
             $plugin->getState()->save();
         }
     } catch (\Exception $e) {
         // Something went wrong
         trigger_error(sprintf('Update of "%s" plugin failed: %s', $plugin->getName(), $e->getMessage()), E_USER_WARNING);
         return false;
     }
     // All updates are done. Make sure the state of the plugin contains
     // current plugin version.
     $plugin->getState()->version = $plugin->getVersion();
     $plugin->getState()->save();
     return true;
 }