예제 #1
0
 /**
  * Checks if the plugin can be enabled.
  *
  * @return boolean
  */
 public function canBeEnabled()
 {
     if ($this->isEnabled()) {
         // The plugin cannot be enabled twice
         return false;
     }
     if ($this->hasUnsatisfiedSystemRequirements()) {
         return false;
     }
     // Make sure all plugin's dependencies exist, are enabled and have
     // appropriate versions
     foreach ($this->getDependencies() as $plugin_name => $required_version) {
         if (!Utils::pluginExists($plugin_name)) {
             return false;
         }
         $plugin = new PluginInfo($plugin_name);
         if (!$plugin->isInstalled() || !$plugin->isEnabled()) {
             return false;
         }
         $version_constrain = new VersionExpression($required_version);
         if (!$version_constrain->satisfiedBy(new Version($plugin->getInstalledVersion()))) {
             return false;
         }
     }
     return true;
 }
예제 #2
0
 /**
  * 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;
 }
예제 #3
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;
 }