Permalink
Browse files

Add post-install/unistall routines to activate/remove plugins in the …

…local Roundcube config; s/Roundcube/RoundCube/
  • Loading branch information...
thomascube committed Feb 7, 2013
1 parent 50510c2 commit b9d558c191677a0b9ac2a4e16360d3f5205c5227
Showing with 100 additions and 22 deletions.
  1. +14 −4 README.md
  2. +3 −3 composer.json
  3. +83 −15 src/RoundCube/Composer/PluginInstaller.php
View
@@ -1,8 +1,8 @@
# Plugin Installer for RoundCube
# Plugin Installer for Roundcube
This installer ensures that plugins end up in the correct directory:
* `roundcube/plugins/plugin-name`
* `<roundcube-root>/plugins/plugin-name`
## Minimum setup
@@ -12,10 +12,16 @@ This installer ensures that plugins end up in the correct directory:
### sample composer.json for plugins
{
"name": "yourprefix/plugin-name",
"name": "yourvendor/plugin-name",
"license": "the license",
"description": "tell the world what your plugin is good at",
"type": "roundcube-plugin",
"authors": [
{
"name": "<your-name>",
"email": "<your-email>"
}
],
"repositories": [
{
"type": "composer",
@@ -28,9 +34,13 @@ This installer ensures that plugins end up in the correct directory:
"minimum-stability": "dev-master"
}
* Submit your plugin to [plugins.roundcube.net](http://plugins.roundcube.net).
## Installation
* clone RoundCube
* clone Roundcube
* `cp composer.json-dist composer.json`
* add your plugin in `require`
* `composer.phar install`
Read the whole story at [plugins.roundcube.net](http://plugins.roundcube.net/about).
View
@@ -1,6 +1,6 @@
{
"name": "roundcube/plugin-installer",
"description": "A composer-installer for RoundCube plugins.",
"description": "A composer-installer for Roundcube plugins.",
"type": "composer-installer",
"license": "BSD-3-Clause",
"authors": [
@@ -11,11 +11,11 @@
],
"autoload": {
"psr-0": {
"RoundCube\\Composer": "src/"
"Roundcube\\Composer": "src/"
}
},
"extra": {
"class": "RoundCube\\Composer\\PluginInstaller"
"class": "Roundcube\\Composer\\PluginInstaller"
},
"require": {
"php": ">=5.3.0"
@@ -1,5 +1,5 @@
<?php
namespace RoundCube\Composer;
namespace Roundcube\Composer;
use \Composer\Installer\LibraryInstaller;
use \Composer\Package\Version\VersionParser;
@@ -37,20 +37,44 @@ public function getInstallPath(PackageInterface $package)
/**
* {@inheritDoc}
*/
public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
{
$this->rcubeVersionCheck($package);
parent::install($repo, $package);
}
/**
* {@inheritDoc}
*/
public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
{
$this->rcubeVersionCheck($target);
parent::update($repo, $initial, $target);
}
public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
{
$this->rcubeVersionCheck($package);
parent::install($repo, $package);
// post-install: activate plugin in Roundcube config
$config_file = $this->rcubeConfigFile();
if (is_writeable($config_file) && php_sapi_name() == 'cli') {
@list($vendor, $plugin_name) = explode('/', $package->getPrettyName());
echo "Do you want to activate the plugin $plugin_name? [N|y]\n";
$answer = trim(fgets(STDIN));
if (strtolower($answer) == 'y' || strtolower($answer) == 'yes') {
$this->rcubeAlterConfig($plugin_name, true);
}
}
}
/**
* {@inheritDoc}
*/
public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
{
$this->rcubeVersionCheck($target);
parent::update($repo, $initial, $target);
}
/**
* {@inheritDoc}
*/
public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
{
parent::uninstall($repo, $package);
// post-uninstall: deactivate plugin
@list($vendor, $plugin_name) = explode('/', $package->getPrettyName());
$this->rcubeAlterConfig($plugin_name, false);
}
/**
* {@inheritDoc}
@@ -106,4 +130,48 @@ private function rcubeVersionCheck($package)
}
}
}
/**
* Add or remove the given plugin to the list of active plugins in the Roundcube config.
*/
private function rcubeAlterConfig($plugin_name, $add)
{
$config_file = $this->rcubeConfigFile();
@include($config_file);
$success = false;
if (is_array($rcmail_config) && is_writeable($config_file)) {
$config_templ = @file_get_contents($config_file);
$active_plugins = (array)$rcmail_config['plugins'];
if ($add && !in_array($plugin_name, $active_plugins)) {
$active_plugins[] = $plugin_name;
}
else if (!$add && ($i = array_search($plugin_name, $active_plugins)) !== false) {
unset($active_plugins[$i]);
}
if ($active_plugins != $rcmail_config['plugins']) {
$var_export = "array(\n\t'" . join("',\n\t'", $active_plugins) . "',\n);";
$new_config = preg_replace(
'/(\$rcmail_config\[\'plugins\'\])\s+=\s+(.+);/Uimse',
"'\\1 = ' . \$var_export",
$config_templ);
$success = file_put_contents($config_file, $new_config);
}
}
if ($success && php_sapi_name() == 'cli') {
echo "Updated local config at $config_file\n";
}
return $success;
}
/**
* Helper method to get an absolute path to the local Roundcube config file
*/
private function rcubeConfigFile()
{
return realpath(getcwd() . '/config/main.inc.php');
}
}

0 comments on commit b9d558c

Please sign in to comment.