From f07ace58bc29c032e3cf19552775067d748ac71e Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Thu, 8 Aug 2013 15:35:46 +0200 Subject: [PATCH] Add plugins reset command --- bin/console | 4 +-- bin/setup | 2 ++ lib/Alchemy/Phrasea/Application.php | 16 +++++++-- lib/Alchemy/Phrasea/Application/Api.php | 1 + lib/Alchemy/Phrasea/Application/Root.php | 1 + lib/Alchemy/Phrasea/CLI.php | 12 +++++++ .../Phrasea/Command/Setup/PluginsReset.php | 34 ++++++++++++++++++ lib/conf.d/plugins/account.less | 0 lib/conf.d/plugins/autoload.php | 10 ++++++ lib/conf.d/plugins/commands.php | 11 ++++++ lib/conf.d/plugins/login.less | 0 lib/conf.d/plugins/services.php | 11 ++++++ lib/conf.d/plugins/twig-paths.php | 7 ++++ .../Phrasea/Command/Setup/PluginResetTest.php | 36 +++++++++++++++++++ 14 files changed, 140 insertions(+), 5 deletions(-) create mode 100644 lib/Alchemy/Phrasea/Command/Setup/PluginsReset.php create mode 100644 lib/conf.d/plugins/account.less create mode 100644 lib/conf.d/plugins/autoload.php create mode 100644 lib/conf.d/plugins/commands.php create mode 100644 lib/conf.d/plugins/login.less create mode 100644 lib/conf.d/plugins/services.php create mode 100644 lib/conf.d/plugins/twig-paths.php create mode 100644 tests/Alchemy/Tests/Phrasea/Command/Setup/PluginResetTest.php diff --git a/bin/console b/bin/console index de7d3c7f6d..c9f2c76fdb 100755 --- a/bin/console +++ b/bin/console @@ -100,9 +100,7 @@ try { $cli->command(new XSendFileConfigurationDumper()); $cli->command(new XSendFileMappingGenerator()); - call_user_func(function ($cli) { - require $cli['plugins.directory'] . '/commands.php'; - }, $cli); + $cli->loadPlugins(); $result_code = is_int($cli->run()) ? : 1; } catch (\Exception $e) { diff --git a/bin/setup b/bin/setup index 0bb44c9508..1a0dfc3440 100755 --- a/bin/setup +++ b/bin/setup @@ -19,6 +19,7 @@ namespace KonsoleKommander; use Alchemy\Phrasea\Core\Version; use Alchemy\Phrasea\Command\UpgradeDBDatas; use Alchemy\Phrasea\Command\Setup\Install; +use Alchemy\Phrasea\Command\Setup\PluginsReset; use Alchemy\Phrasea\CLI; use Alchemy\Phrasea\Command\Setup\CheckEnvironment; @@ -60,6 +61,7 @@ try { $app->command(new UpgradeDBDatas('system:upgrade-datas')); } + $app->command(new PluginsReset()); $app->command(new CheckEnvironment('check:system')); $app->command(new Install('system:install')); diff --git a/lib/Alchemy/Phrasea/Application.php b/lib/Alchemy/Phrasea/Application.php index 17675f4a74..1bbde577a9 100644 --- a/lib/Alchemy/Phrasea/Application.php +++ b/lib/Alchemy/Phrasea/Application.php @@ -412,9 +412,21 @@ class Application extends SilexApplication $guesser->register(new VideoMimeTypeGuesser()); $app['plugins.directory'] = $app->share(function () { - return realpath(__DIR__ . '/../../../plugins'); - }); + $dir = __DIR__ . '/../../../plugins'; + if (is_dir($dir)) { + return realpath($dir); + } else { + return $dir; + } + }); + } + + /** + * Loads Phraseanet plugins + */ + public function loadPlugins() + { call_user_func(function ($app) { require $app['plugins.directory'] . '/services.php'; }, $this); diff --git a/lib/Alchemy/Phrasea/Application/Api.php b/lib/Alchemy/Phrasea/Application/Api.php index 7150961f73..81d73a1389 100644 --- a/lib/Alchemy/Phrasea/Application/Api.php +++ b/lib/Alchemy/Phrasea/Application/Api.php @@ -25,6 +25,7 @@ use Symfony\Component\HttpFoundation\Request; return call_user_func(function($environment = PhraseaApplication::ENV_PROD) { $app = new PhraseaApplication($environment); + $app->loadPlugins(); $app['exception_handler'] = $app->share(function ($app) { return new ApiExceptionHandlerSubscriber($app); diff --git a/lib/Alchemy/Phrasea/Application/Root.php b/lib/Alchemy/Phrasea/Application/Root.php index 43c58c54f1..9d240a5045 100644 --- a/lib/Alchemy/Phrasea/Application/Root.php +++ b/lib/Alchemy/Phrasea/Application/Root.php @@ -23,6 +23,7 @@ use Symfony\Component\HttpFoundation\Request; return call_user_func(function($environment = PhraseaApplication::ENV_PROD) { $app = new PhraseaApplication($environment); + $app->loadPlugins(); $app['exception_handler'] = $app->share(function ($app) { return new PhraseaExceptionHandlerSubscriber($app['phraseanet.exception_handler']); diff --git a/lib/Alchemy/Phrasea/CLI.php b/lib/Alchemy/Phrasea/CLI.php index e779b8d808..40a0c7de84 100644 --- a/lib/Alchemy/Phrasea/CLI.php +++ b/lib/Alchemy/Phrasea/CLI.php @@ -90,4 +90,16 @@ class CLI extends Application $command->setContainer($this); $this['console']->add($command); } + + /** + * {@inheritdoc} + */ + public function loadPlugins() + { + parent::loadPlugins(); + + call_user_func(function ($cli) { + require $cli['plugins.directory'] . '/commands.php'; + }, $this); + } } diff --git a/lib/Alchemy/Phrasea/Command/Setup/PluginsReset.php b/lib/Alchemy/Phrasea/Command/Setup/PluginsReset.php new file mode 100644 index 0000000000..dc079c2f18 --- /dev/null +++ b/lib/Alchemy/Phrasea/Command/Setup/PluginsReset.php @@ -0,0 +1,34 @@ +setDescription('Reset plugins in case a failure occured'); + } + + protected function doExecute(InputInterface $input, OutputInterface $output) + { + $this->container['filesystem']->remove($this->container['plugins.directory']); + $this->container['filesystem']->mirror(__DIR__ . '/../../../../conf.d/plugins', $this->container['plugins.directory']); + + return 0; + } +} diff --git a/lib/conf.d/plugins/account.less b/lib/conf.d/plugins/account.less new file mode 100644 index 0000000000..e69de29bb2 diff --git a/lib/conf.d/plugins/autoload.php b/lib/conf.d/plugins/autoload.php new file mode 100644 index 0000000000..7c242765f2 --- /dev/null +++ b/lib/conf.d/plugins/autoload.php @@ -0,0 +1,10 @@ +getMock('Symfony\Component\Console\Input\InputInterface'); + $output = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); + + $command = new PluginsReset(); + $command->setContainer(self::$DI['cli']); + + $capturedSource = null; + + self::$DI['cli']['filesystem'] = $this->getMockBuilder('Symfony\Component\Filesystem\Filesystem') + ->disableOriginalConstructor() + ->getMock(); + self::$DI['cli']['filesystem']->expects($this->once()) + ->method('remove') + ->with(self::$DI['cli']['plugins.directory']); + self::$DI['cli']['filesystem']->expects($this->once()) + ->method('mirror') + ->with($this->isType('string'), self::$DI['cli']['plugins.directory']) + ->will($this->returnCallback(function ($source, $target) use (&$capturedSource) { + $capturedSource = $source; + })); + + $this->assertEquals(0, $command->execute($input, $output)); + $this->assertNotNull($capturedSource); + $this->assertEquals(realpath(__DIR__ . '/../../../../../../lib/conf.d/plugins'), realpath($capturedSource)); + } +}