Add plugins reset command

This commit is contained in:
Romain Neutron
2013-08-08 15:35:46 +02:00
parent 72aaa24ce5
commit f07ace58bc
14 changed files with 140 additions and 5 deletions

View File

@@ -100,9 +100,7 @@ try {
$cli->command(new XSendFileConfigurationDumper()); $cli->command(new XSendFileConfigurationDumper());
$cli->command(new XSendFileMappingGenerator()); $cli->command(new XSendFileMappingGenerator());
call_user_func(function ($cli) { $cli->loadPlugins();
require $cli['plugins.directory'] . '/commands.php';
}, $cli);
$result_code = is_int($cli->run()) ? : 1; $result_code = is_int($cli->run()) ? : 1;
} catch (\Exception $e) { } catch (\Exception $e) {

View File

@@ -19,6 +19,7 @@ namespace KonsoleKommander;
use Alchemy\Phrasea\Core\Version; use Alchemy\Phrasea\Core\Version;
use Alchemy\Phrasea\Command\UpgradeDBDatas; use Alchemy\Phrasea\Command\UpgradeDBDatas;
use Alchemy\Phrasea\Command\Setup\Install; use Alchemy\Phrasea\Command\Setup\Install;
use Alchemy\Phrasea\Command\Setup\PluginsReset;
use Alchemy\Phrasea\CLI; use Alchemy\Phrasea\CLI;
use Alchemy\Phrasea\Command\Setup\CheckEnvironment; use Alchemy\Phrasea\Command\Setup\CheckEnvironment;
@@ -60,6 +61,7 @@ try {
$app->command(new UpgradeDBDatas('system:upgrade-datas')); $app->command(new UpgradeDBDatas('system:upgrade-datas'));
} }
$app->command(new PluginsReset());
$app->command(new CheckEnvironment('check:system')); $app->command(new CheckEnvironment('check:system'));
$app->command(new Install('system:install')); $app->command(new Install('system:install'));

View File

@@ -412,9 +412,21 @@ class Application extends SilexApplication
$guesser->register(new VideoMimeTypeGuesser()); $guesser->register(new VideoMimeTypeGuesser());
$app['plugins.directory'] = $app->share(function () { $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) { call_user_func(function ($app) {
require $app['plugins.directory'] . '/services.php'; require $app['plugins.directory'] . '/services.php';
}, $this); }, $this);

View File

@@ -25,6 +25,7 @@ use Symfony\Component\HttpFoundation\Request;
return call_user_func(function($environment = PhraseaApplication::ENV_PROD) { return call_user_func(function($environment = PhraseaApplication::ENV_PROD) {
$app = new PhraseaApplication($environment); $app = new PhraseaApplication($environment);
$app->loadPlugins();
$app['exception_handler'] = $app->share(function ($app) { $app['exception_handler'] = $app->share(function ($app) {
return new ApiExceptionHandlerSubscriber($app); return new ApiExceptionHandlerSubscriber($app);

View File

@@ -23,6 +23,7 @@ use Symfony\Component\HttpFoundation\Request;
return call_user_func(function($environment = PhraseaApplication::ENV_PROD) { return call_user_func(function($environment = PhraseaApplication::ENV_PROD) {
$app = new PhraseaApplication($environment); $app = new PhraseaApplication($environment);
$app->loadPlugins();
$app['exception_handler'] = $app->share(function ($app) { $app['exception_handler'] = $app->share(function ($app) {
return new PhraseaExceptionHandlerSubscriber($app['phraseanet.exception_handler']); return new PhraseaExceptionHandlerSubscriber($app['phraseanet.exception_handler']);

View File

@@ -90,4 +90,16 @@ class CLI extends Application
$command->setContainer($this); $command->setContainer($this);
$this['console']->add($command); $this['console']->add($command);
} }
/**
* {@inheritdoc}
*/
public function loadPlugins()
{
parent::loadPlugins();
call_user_func(function ($cli) {
require $cli['plugins.directory'] . '/commands.php';
}, $this);
}
} }

View File

@@ -0,0 +1,34 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Command\Setup;
use Alchemy\Phrasea\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class PluginsReset extends Command
{
public function __construct()
{
parent::__construct('plugins:reset');
$this->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;
}
}

View File

View File

@@ -0,0 +1,10 @@
<?php
// This file is automatically generated, please do not edit it.
// To update configuration, use bin/console plugins:* commands.
return call_user_func(function () {
$loader = require __DIR__ . '/../vendor/autoload.php';
return $loader;
});

View File

@@ -0,0 +1,11 @@
<?php
// This file is automatically generated, please do not edit it.
// To update configuration, use bin/console plugins:* commands.
use Alchemy\Phrasea\CLI;
return call_user_func(function (CLI $cli) {
return $cli;
}, $cli);

View File

View File

@@ -0,0 +1,11 @@
<?php
// This file is automatically generated, please do not edit it.
// To update configuration, use bin/console plugins:* commands.
use Alchemy\Phrasea\Application;
return call_user_func(function (Application $app) {
return $app;
}, $app);

View File

@@ -0,0 +1,7 @@
<?php
// This file is automatically generated, please do not edit it.
// To update configuration, use bin/console plugins:* commands.
return array(
);

View File

@@ -0,0 +1,36 @@
<?php
namespace Alchemy\Tests\Phrasea\Command\Setup;
use Alchemy\Phrasea\Command\Setup\PluginsReset;
class PluginResetTest extends \PhraseanetPHPUnitAbstract
{
public function testRun()
{
$input = $this->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));
}
}