diff --git a/bin/console b/bin/console index 2ee888d69c..65b3a681fd 100755 --- a/bin/console +++ b/bin/console @@ -13,6 +13,8 @@ namespace KonsoleKommander; use Alchemy\Phrasea\Command\Plugin\ListPlugin; use Alchemy\Phrasea\Command\SearchEngine\IndexFull; +use Alchemy\Phrasea\Command\WebsocketServer; +use Alchemy\Phrasea\Core\Version; use Alchemy\Phrasea\Command\BuildMissingSubdefs; use Alchemy\Phrasea\Command\CreateCollection; use Alchemy\Phrasea\Command\MailTest; @@ -20,7 +22,6 @@ use Alchemy\Phrasea\Command\Compile\Configuration; use Alchemy\Phrasea\Command\RecordAdd; use Alchemy\Phrasea\Command\RescanTechnicalDatas; use Alchemy\Phrasea\Command\UpgradeDBDatas; -use Alchemy\Phrasea\Core\Version; use Alchemy\Phrasea\CLI; use Alchemy\Phrasea\Command\Plugin\AddPlugin; use Alchemy\Phrasea\Command\Plugin\RemovePlugin; @@ -114,6 +115,8 @@ if ($cli['phraseanet.SE']->getName() === 'ElasticSearch') { $cli->command(new IndexFull('searchengine:index')); } +$cli->command(new WebsocketServer('ws-server:run')); + $cli->loadPlugins(); exit(is_int($cli->run()) ? : 1); diff --git a/lib/Alchemy/Phrasea/CLI.php b/lib/Alchemy/Phrasea/CLI.php index 27c826a6c7..317c36b892 100644 --- a/lib/Alchemy/Phrasea/CLI.php +++ b/lib/Alchemy/Phrasea/CLI.php @@ -13,6 +13,7 @@ namespace Alchemy\Phrasea; use Alchemy\Phrasea\Command\CommandInterface; use Alchemy\Phrasea\Core\CLIProvider\TranslationExtractorServiceProvider; +use Alchemy\Phrasea\Core\CLIProvider\WebsocketServerServiceProvider; use Alchemy\Phrasea\Exception\RuntimeException; use Symfony\Component\Console; use Alchemy\Phrasea\Core\CLIProvider\CLIDriversServiceProvider; @@ -55,6 +56,7 @@ class CLI extends Application }); $this->register(new PluginServiceProvider()); + $this->register(new WebsocketServerServiceProvider()); $this->register(new ComposerSetupServiceProvider()); $this->register(new CLIDriversServiceProvider()); $this->register(new LessBuilderServiceProvider()); diff --git a/lib/Alchemy/Phrasea/Command/WebsocketServer.php b/lib/Alchemy/Phrasea/Command/WebsocketServer.php new file mode 100644 index 0000000000..2a82239ce1 --- /dev/null +++ b/lib/Alchemy/Phrasea/Command/WebsocketServer.php @@ -0,0 +1,38 @@ +setDescription("Runs the websocket server"); + } + + public function doExecute(InputInterface $input, OutputInterface $output) + { + $sessionConf = $this->container['conf']->get(['main', 'session', 'type'], 'file'); + + if (!in_array($sessionConf, ['memcached', 'memcache', 'redis'])) { + throw new RuntimeException(sprintf('Running the websocket server requires a server session storage, type `%s` provided', $sessionConf)); + } + + $this->container['ws.server']->run(); + } +} diff --git a/tests/Alchemy/Tests/Phrasea/Command/WebsocketServerTest.php b/tests/Alchemy/Tests/Phrasea/Command/WebsocketServerTest.php new file mode 100644 index 0000000000..1f16cdd90a --- /dev/null +++ b/tests/Alchemy/Tests/Phrasea/Command/WebsocketServerTest.php @@ -0,0 +1,29 @@ +getMock('Symfony\Component\Console\Input\InputInterface'); + $output = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); + + $sessionType = self::$DI['cli']['conf']->get(['main', 'session', 'type'], 'file'); + self::$DI['cli']['conf']->set(['main', 'session', 'type'], 'memcached'); + + self::$DI['cli']['ws.server'] = $this->getMockBuilder('Ratchet\App') + ->disableOriginalConstructor() + ->getMock(); + self::$DI['cli']['ws.server']->expects($this->once()) + ->method('run'); + + $command = new WebsocketServer('websocketserver'); + $command->setContainer(self::$DI['cli']); + $command->execute($input, $output); + + self::$DI['cli']['conf']->set(['main', 'session', 'type'], $sessionType); + } +}