From 92d5a655236e6ce0f3ad4986888453bbceba6a46 Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Mon, 2 Jan 2017 18:32:23 +0100 Subject: [PATCH] Added download and sync commands --- Command/DeleteObsoleteCommand.php | 9 +++---- Command/DownloadCommand.php | 42 +++++++++++++++++++++++++++++++ Command/ExtractCommand.php | 30 ++++++++-------------- Command/SyncCommand.php | 42 +++++++++++++++++++++++++++++++ 4 files changed, 97 insertions(+), 26 deletions(-) create mode 100644 Command/DownloadCommand.php create mode 100644 Command/SyncCommand.php diff --git a/Command/DeleteObsoleteCommand.php b/Command/DeleteObsoleteCommand.php index c0d4d373..4ab40129 100644 --- a/Command/DeleteObsoleteCommand.php +++ b/Command/DeleteObsoleteCommand.php @@ -17,15 +17,12 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ConfirmationQuestion; -use Symfony\Component\DependencyInjection\ContainerInterface; +/** + * @author Tobias Nyholm + */ class DeleteObsoleteCommand extends ContainerAwareCommand { - /** - * @var ContainerInterface - */ - private $container; - protected function configure() { $this diff --git a/Command/DownloadCommand.php b/Command/DownloadCommand.php new file mode 100644 index 00000000..3cdfd8aa --- /dev/null +++ b/Command/DownloadCommand.php @@ -0,0 +1,42 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Translation\Bundle\Command; + +use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Translation\Bundle\Model\Configuration; +use Translation\Bundle\Service\StorageService; + +/** + * @author Tobias Nyholm + */ +class DownloadCommand extends ContainerAwareCommand +{ + protected function configure() + { + $this + ->setName('translation:download') + ->setDescription('Replace local messages with messages from remote') + ->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $container = $this->getContainer(); + $configName = $input->getArgument('configuration'); + /** @var StorageService $storage */ + $storage = $container->get('php_translation.storage.'.$configName); + $storage->download(); + } +} diff --git a/Command/ExtractCommand.php b/Command/ExtractCommand.php index 5a32e314..070072ee 100644 --- a/Command/ExtractCommand.php +++ b/Command/ExtractCommand.php @@ -15,17 +15,14 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Finder\Finder; use Translation\Bundle\Model\Configuration; +/** + * @author Tobias Nyholm + */ class ExtractCommand extends ContainerAwareCommand { - /** - * @var ContainerInterface - */ - private $container; - protected function configure() { $this @@ -38,16 +35,18 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { $container = $this->getContainer(); - $configName = $input->getArgument('configuration'); - $config = $container->get('php_translation.configuration_manager')->getConfiguration($configName); $importer = $container->get('php_translation.importer'); + $config = $container->get('php_translation.configuration_manager') + ->getConfiguration($input->getArgument('configuration')); $locales = []; if ($inputLocale = $input->getArgument('locale')) { $locales = [$inputLocale]; } - $catalogues = $container->get('php_translation.catalogue_fetcher')->getCatalogues($config, $locales); + $catalogues = $container->get('php_translation.catalogue_fetcher') + ->getCatalogues($config, $locales); + $finder = $this->getConfiguredFinder($config); $results = $importer->extractToCatalogues($finder, $catalogues, [ 'blacklist_domains' => $config->getBlacklistDomains(), @@ -55,17 +54,8 @@ protected function execute(InputInterface $input, OutputInterface $output) 'project_root' => $config->getProjectRoot(), ]); - $writer = $container->get('translation.writer'); - foreach ($results as $result) { - $writer->writeTranslations( - $result, - $config->getOutputFormat(), - [ - 'path' => $config->getOutputDir(), - 'default_locale' => $container->getParameter('php_translation.default_locale'), - ] - ); - } + $container->get('php_translation.catalogue_writer') + ->writeCatalogues($config, $results); } /** diff --git a/Command/SyncCommand.php b/Command/SyncCommand.php new file mode 100644 index 00000000..a1ac6eb0 --- /dev/null +++ b/Command/SyncCommand.php @@ -0,0 +1,42 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Translation\Bundle\Command; + +use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Translation\Bundle\Model\Configuration; +use Translation\Bundle\Service\StorageService; + +/** + * @author Tobias Nyholm + */ +class SyncCommand extends ContainerAwareCommand +{ + protected function configure() + { + $this + ->setName('translation:sync') + ->setDescription('Sync the translations with the remote storage') + ->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $container = $this->getContainer(); + $configName = $input->getArgument('configuration'); + /** @var StorageService $storage */ + $storage = $container->get('php_translation.storage.'.$configName); + $storage->sync(); + } +}