mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-08 10:34:34 +00:00
Force plugin configuration in configuration
This commit is contained in:
@@ -58,6 +58,10 @@ class AddPlugin extends AbstractPluginCommand
|
|||||||
$this->container['filesystem']->remove($temporaryDir);
|
$this->container['filesystem']->remove($temporaryDir);
|
||||||
$output->writeln(" <comment>OK</comment>");
|
$output->writeln(" <comment>OK</comment>");
|
||||||
|
|
||||||
|
$output->write("Activating plugin...");
|
||||||
|
$this->container['conf']->set(['plugins', $manifest->getName(), 'enabled'], true);
|
||||||
|
$output->writeln(" <comment>OK</comment>");
|
||||||
|
|
||||||
$this->updateConfigFiles($input, $output);
|
$this->updateConfigFiles($input, $output);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@@ -24,8 +24,7 @@ class RemovePlugin extends AbstractPluginCommand
|
|||||||
|
|
||||||
$this
|
$this
|
||||||
->setDescription('Removes a plugin given its name')
|
->setDescription('Removes a plugin given its name')
|
||||||
->addArgument('name', InputArgument::REQUIRED, 'The name of the plugin')
|
->addArgument('name', InputArgument::REQUIRED, 'The name of the plugin');
|
||||||
->addOption('keep-config', 'k', InputOption::VALUE_NONE, 'Use this flag to keep configuration');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function doExecutePluginAction(InputInterface $input, OutputInterface $output)
|
protected function doExecutePluginAction(InputInterface $input, OutputInterface $output)
|
||||||
@@ -50,11 +49,7 @@ class RemovePlugin extends AbstractPluginCommand
|
|||||||
|
|
||||||
$this->updateConfigFiles($input, $output);
|
$this->updateConfigFiles($input, $output);
|
||||||
|
|
||||||
if (!$input->getOption('keep-config')) {
|
$this->container['conf']->remove(['plugins', $name]);
|
||||||
$conf = $this->container['phraseanet.configuration']->getConfig();
|
|
||||||
unset($conf['plugins'][$name]);
|
|
||||||
$this->container['phraseanet.configuration']->setConfig($conf);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -30,24 +30,6 @@ class PluginServiceProvider implements ServiceProviderInterface
|
|||||||
{
|
{
|
||||||
public function register(Application $app)
|
public function register(Application $app)
|
||||||
{
|
{
|
||||||
$app['plugins.schema'] = realpath(__DIR__ . '/../../../../conf.d/plugin-schema.json');
|
|
||||||
|
|
||||||
$app['plugins.manager'] = $app->share(function (Application $app) {
|
|
||||||
return new PluginManager($app['plugins.directory'], $app['plugins.plugins-validator']);
|
|
||||||
});
|
|
||||||
|
|
||||||
$app['plugins.json-validator'] = $app->share(function (Application $app) {
|
|
||||||
return new JsonValidator();
|
|
||||||
});
|
|
||||||
|
|
||||||
$app['plugins.manifest-validator'] = $app->share(function (Application $app) {
|
|
||||||
return ManifestValidator::create($app);
|
|
||||||
});
|
|
||||||
|
|
||||||
$app['plugins.plugins-validator'] = $app->share(function (Application $app) {
|
|
||||||
return new PluginValidator($app['plugins.manifest-validator']);
|
|
||||||
});
|
|
||||||
|
|
||||||
$app['plugins.import-strategy'] = $app->share(function (Application $app) {
|
$app['plugins.import-strategy'] = $app->share(function (Application $app) {
|
||||||
return new ImportStrategy();
|
return new ImportStrategy();
|
||||||
});
|
});
|
||||||
|
@@ -11,6 +11,10 @@
|
|||||||
|
|
||||||
namespace Alchemy\Phrasea\Core\Provider;
|
namespace Alchemy\Phrasea\Core\Provider;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Plugin\PluginManager;
|
||||||
|
use Alchemy\Phrasea\Plugin\Schema\ManifestValidator;
|
||||||
|
use Alchemy\Phrasea\Plugin\Schema\PluginValidator;
|
||||||
|
use JsonSchema\Validator as JsonValidator;
|
||||||
use Silex\Application;
|
use Silex\Application;
|
||||||
use Silex\ServiceProviderInterface;
|
use Silex\ServiceProviderInterface;
|
||||||
|
|
||||||
@@ -18,6 +22,23 @@ class PluginServiceProvider implements ServiceProviderInterface
|
|||||||
{
|
{
|
||||||
public function register(Application $app)
|
public function register(Application $app)
|
||||||
{
|
{
|
||||||
|
$app['plugins.schema'] = realpath(__DIR__ . '/../../../../conf.d/plugin-schema.json');
|
||||||
|
|
||||||
|
$app['plugins.json-validator'] = $app->share(function (Application $app) {
|
||||||
|
return new JsonValidator();
|
||||||
|
});
|
||||||
|
|
||||||
|
$app['plugins.manifest-validator'] = $app->share(function (Application $app) {
|
||||||
|
return ManifestValidator::create($app);
|
||||||
|
});
|
||||||
|
|
||||||
|
$app['plugins.plugins-validator'] = $app->share(function (Application $app) {
|
||||||
|
return new PluginValidator($app['plugins.manifest-validator']);
|
||||||
|
});
|
||||||
|
|
||||||
|
$app['plugins.manager'] = $app->share(function (Application $app) {
|
||||||
|
return new PluginManager($app['plugins.directory'], $app['plugins.plugins-validator'], $app['conf']);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function boot(Application $app)
|
public function boot(Application $app)
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace Alchemy\Phrasea\Plugin;
|
namespace Alchemy\Phrasea\Plugin;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Core\Configuration\PropertyAccess;
|
||||||
use Alchemy\Phrasea\Plugin\Schema\PluginValidator;
|
use Alchemy\Phrasea\Plugin\Schema\PluginValidator;
|
||||||
use Alchemy\Phrasea\Plugin\Exception\PluginValidationException;
|
use Alchemy\Phrasea\Plugin\Exception\PluginValidationException;
|
||||||
use Symfony\Component\Finder\Finder;
|
use Symfony\Component\Finder\Finder;
|
||||||
@@ -19,11 +20,13 @@ class PluginManager
|
|||||||
{
|
{
|
||||||
private $pluginDir;
|
private $pluginDir;
|
||||||
private $validator;
|
private $validator;
|
||||||
|
private $conf;
|
||||||
|
|
||||||
public function __construct($pluginDir, PluginValidator $validator)
|
public function __construct($pluginDir, PluginValidator $validator, PropertyAccess $conf)
|
||||||
{
|
{
|
||||||
$this->pluginDir = $pluginDir;
|
$this->pluginDir = $pluginDir;
|
||||||
$this->validator = $validator;
|
$this->validator = $validator;
|
||||||
|
$this->conf = $conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,20 +34,13 @@ class PluginManager
|
|||||||
*/
|
*/
|
||||||
public function listPlugins()
|
public function listPlugins()
|
||||||
{
|
{
|
||||||
$finder = new Finder();
|
|
||||||
$finder
|
|
||||||
->depth(0)
|
|
||||||
->in($this->pluginDir)
|
|
||||||
->directories();
|
|
||||||
|
|
||||||
$plugins = [];
|
$plugins = [];
|
||||||
|
|
||||||
foreach ($finder as $pluginDir) {
|
foreach ($this->conf->get('plugins') as $name => $config) {
|
||||||
$manifest = $error = null;
|
$manifest = $error = null;
|
||||||
$name = $pluginDir->getBasename();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$manifest = $this->validator->validatePlugin((string) $pluginDir);
|
$manifest = $this->validator->validatePlugin($this->pluginDir.'/'.$name);
|
||||||
} catch (PluginValidationException $e) {
|
} catch (PluginValidationException $e) {
|
||||||
$error = $e;
|
$error = $e;
|
||||||
}
|
}
|
||||||
@@ -57,8 +53,29 @@ class PluginManager
|
|||||||
|
|
||||||
public function hasPlugin($name)
|
public function hasPlugin($name)
|
||||||
{
|
{
|
||||||
$plugins = $this->listPlugins();
|
return array_key_exists($name, $this->conf->get('plugins'));
|
||||||
|
}
|
||||||
|
|
||||||
return isset($plugins[$name]);
|
public function enable($name)
|
||||||
|
{
|
||||||
|
$this->conf->set(['plugins', $name, 'enabled'], true);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function disable($name)
|
||||||
|
{
|
||||||
|
$this->conf->set(['plugins', $name, 'enabled'], false);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isEnabled($name)
|
||||||
|
{
|
||||||
|
if (!$this->hasPlugin($name)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->conf->get(['plugins', $name, 'enabled'], false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
92
lib/classes/patch/390alpha12a.php
Normal file
92
lib/classes/patch/390alpha12a.php
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of Phraseanet
|
||||||
|
*
|
||||||
|
* (c) 2005-2014 Alchemy
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Application;
|
||||||
|
use Alchemy\Phrasea\Plugin\Plugin;
|
||||||
|
use Alchemy\Phrasea\Plugin\Exception\PluginValidationException;
|
||||||
|
use Symfony\Component\Finder\Finder;
|
||||||
|
|
||||||
|
class patch_390alpha12a implements patchInterface
|
||||||
|
{
|
||||||
|
/** @var string */
|
||||||
|
private $release = '3.9.0-alpha.12';
|
||||||
|
|
||||||
|
/** @var array */
|
||||||
|
private $concern = [base::APPLICATION_BOX];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function get_release()
|
||||||
|
{
|
||||||
|
return $this->release;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function require_all_upgrades()
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function concern()
|
||||||
|
{
|
||||||
|
return $this->concern;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getDoctrineMigrations()
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function apply(base $appbox, Application $app)
|
||||||
|
{
|
||||||
|
foreach ($this->listPlugins($app) as $name => $plugin) {
|
||||||
|
$app['conf']->set(['plugins', $name, 'enabled'], true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function listPlugins(Application $app)
|
||||||
|
{
|
||||||
|
$finder = new Finder();
|
||||||
|
$finder
|
||||||
|
->depth(0)
|
||||||
|
->in($app['plugins.directory'])
|
||||||
|
->directories();
|
||||||
|
|
||||||
|
$plugins = [];
|
||||||
|
|
||||||
|
foreach ($finder as $pluginDir) {
|
||||||
|
$manifest = $error = null;
|
||||||
|
$name = $pluginDir->getBasename();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$manifest = $app['plugins.plugins-validator']->validatePlugin((string) $pluginDir);
|
||||||
|
} catch (PluginValidationException $e) {
|
||||||
|
$error = $e;
|
||||||
|
}
|
||||||
|
|
||||||
|
$plugins[$name] = new Plugin($name, $manifest, $error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $plugins;
|
||||||
|
}
|
||||||
|
}
|
@@ -9,27 +9,41 @@ class PluginManagerTest extends PluginTestCase
|
|||||||
{
|
{
|
||||||
public function testListGoodPlugins()
|
public function testListGoodPlugins()
|
||||||
{
|
{
|
||||||
$manager = new PluginManager(__DIR__ . '/Fixtures/PluginDirInstalled', self::$DI['cli']['plugins.plugins-validator']);
|
$prevPlugins = self::$DI['cli']['conf']->get('plugins');
|
||||||
|
self::$DI['cli']['conf']->set('plugins', []);
|
||||||
|
self::$DI['cli']['conf']->set(['plugins', 'test-plugin', 'enabled'], true);
|
||||||
|
|
||||||
|
$manager = new PluginManager(__DIR__ . '/Fixtures/PluginDirInstalled', self::$DI['cli']['plugins.plugins-validator'], self::$DI['cli']['conf']);
|
||||||
$plugins = $manager->listPlugins();
|
$plugins = $manager->listPlugins();
|
||||||
$this->assertCount(1, $plugins);
|
$this->assertCount(1, $plugins);
|
||||||
$plugin = array_pop($plugins);
|
$plugin = array_pop($plugins);
|
||||||
|
|
||||||
$this->assertFalse($plugin->isErroneous());
|
$this->assertFalse($plugin->isErroneous());
|
||||||
|
|
||||||
|
self::$DI['cli']['conf']->set('plugins', $prevPlugins);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testListWrongPlugins()
|
public function testListWrongPlugins()
|
||||||
{
|
{
|
||||||
$manager = new PluginManager(__DIR__ . '/Fixtures/WrongPlugins', self::$DI['cli']['plugins.plugins-validator']);
|
$prevPlugins = self::$DI['cli']['conf']->get('plugins');
|
||||||
|
self::$DI['cli']['conf']->set('plugins', []);
|
||||||
|
self::$DI['cli']['conf']->set(['plugins', 'plugin-test', 'enabled'], true);
|
||||||
|
self::$DI['cli']['conf']->set(['plugins', 'plugin-test2', 'enabled'], true);
|
||||||
|
self::$DI['cli']['conf']->set(['plugins', 'plugin-test3', 'enabled'], true);
|
||||||
|
|
||||||
|
$manager = new PluginManager(__DIR__ . '/Fixtures/WrongPlugins', self::$DI['cli']['plugins.plugins-validator'], self::$DI['cli']['conf']);
|
||||||
$plugins = $manager->listPlugins();
|
$plugins = $manager->listPlugins();
|
||||||
$this->assertCount(8, $plugins);
|
$this->assertCount(3, $plugins);
|
||||||
$plugin = array_pop($plugins);
|
$plugin = array_pop($plugins);
|
||||||
|
|
||||||
$this->assertTrue($plugin->isErroneous());
|
$this->assertTrue($plugin->isErroneous());
|
||||||
|
|
||||||
|
self::$DI['cli']['conf']->set('plugins', $prevPlugins);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHasPlugin()
|
public function testHasPlugin()
|
||||||
{
|
{
|
||||||
$manager = new PluginManager(__DIR__ . '/Fixtures/PluginDirInstalled', self::$DI['cli']['plugins.plugins-validator']);
|
$manager = new PluginManager(__DIR__ . '/Fixtures/PluginDirInstalled', self::$DI['cli']['plugins.plugins-validator'], self::$DI['cli']['conf']);
|
||||||
$this->assertTrue($manager->hasPlugin('test-plugin'));
|
$this->assertTrue($manager->hasPlugin('test-plugin'));
|
||||||
$this->assertFalse($manager->hasPlugin('test-plugin2'));
|
$this->assertFalse($manager->hasPlugin('test-plugin2'));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user