Development

Changeset 8813

You must first sign up to be able to contribute.

Changeset 8813

Show
Ignore:
Timestamp:
05/06/08 18:05:48 (2 months ago)
Author:
fabien
Message:

added a check for license when install a plugin with the plugin:install task (closes #2316)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/plugin/sfPearRestPlugin.class.php

    r5250 r8813  
    7373 
    7474  /** 
     75   * Returns the license for a given plugin and version. 
     76   * 
     77   * @param string The plugin name 
     78   * @param string The version 
     79   * 
     80   * @param string The license 
     81   */ 
     82  public function getPluginLicense($plugin, $version) 
     83  { 
     84    $info = $this->packageInfo($this->restBase, $plugin); 
     85 
     86    if (is_null($info)) 
     87    { 
     88      // plugin does not exist 
     89      return null; 
     90    } 
     91 
     92    if (!isset($info['license']) || is_null($info['license'])) 
     93    { 
     94      throw new Exception('No license found for this plugin!'); 
     95    } 
     96 
     97    return $info['releases'][$version]['license']; 
     98  } 
     99 
     100  /** 
    75101   * Gets the all available versions for a given plugin. 
    76102   * 
  • branches/1.1/lib/plugin/sfPluginManager.class.php

    r7662 r8813  
    413413 
    414414  /** 
     415   * Returns the license for a given plugin. 
     416   * 
     417   * @param string The plugin name 
     418   * @param array  An array of options 
     419   * 
     420   * @param string The license 
     421   * 
     422   * @see installPlugin() for available options 
     423   */ 
     424  public function getPluginLicense($plugin, $options = array()) 
     425  { 
     426    $channel   = isset($options['channel']) ? $options['channel'] : $this->environment->getConfig()->get('default_channel'); 
     427    $stability = isset($options['stability']) ? $options['stability'] : $this->environment->getConfig()->get('preferred_state', null, $channel); 
     428    $version   = isset($options['version']) ? $options['version'] : null; 
     429 
     430    $rest = $this->environment->getRest(); 
     431    $rest->setChannel(is_null($channel) ? $this->environment->getConfig()->get('default_channel') : $channel); 
     432 
     433    if (is_null($version)) 
     434    { 
     435      $version = $this->getPluginVersion($plugin, $stability); 
     436    } 
     437 
     438    return $rest->getPluginLicense($plugin, $version); 
     439  } 
     440 
     441  /** 
    415442   * Returns true if the plugin is comptatible with the dependency. 
    416443   * 
  • branches/1.1/lib/task/plugin/sfPluginInstallTask.class.php

    r8474 r8813  
    3535      new sfCommandOption('channel', 'c', sfCommandOption::PARAMETER_REQUIRED, 'The PEAR channel name', null), 
    3636      new sfCommandOption('install_deps', 'd', sfCommandOption::PARAMETER_NONE, 'Whether to force installation of required dependencies', null), 
     37      new sfCommandOption('force-license', null, sfCommandOption::PARAMETER_NONE, 'Whether to force installation even if the license is not MIT like'), 
    3738    )); 
    3839 
     
    102103    unset($options['release']); 
    103104 
     105    // license compatible? 
     106    if (!$options['force-license']) 
     107    { 
     108      try 
     109      { 
     110        $license = $this->getPluginManager()->getPluginLicense($arguments['name'], isset($options['channel']) ? $options['channel'] : null); 
     111      } 
     112      catch (Exception $e) 
     113      { 
     114        throw new sfCommandException(sprintf('%s (use --force-license to force installation)', $e->getMessage())); 
     115      } 
     116 
     117      $temp = trim(str_replace('license', '', strtolower($license))); 
     118      if (!is_null($license) && !in_array($temp, array('mit', 'bsd', 'lgpl', 'php', 'apache'))) 
     119      { 
     120        throw new sfCommandException(sprintf('The license of this plugin "%s" is not MIT like (use --force-license to force installation).', $license)); 
     121      } 
     122    } 
     123 
    104124    $this->getPluginManager()->installPlugin($arguments['name'], $options); 
    105125  }