From 704d398076c6802e501b6f3ffaf1fe6201497c0a Mon Sep 17 00:00:00 2001 From: Mantas Date: Wed, 16 Mar 2016 15:36:49 +0200 Subject: [PATCH 1/2] added support for symfony 3.0 and EB 1.0 --- Command/ImportCommand.php | 2 +- Controller/ListController.php | 2 +- Document/Translation.php | 2 +- Resources/config/routing.yml | 16 ++++++++-------- Tests/Functional/Command/ImportCommandTest.php | 2 +- .../Functional/Controller/ApiControllerTest.php | 8 ++++---- Translation/Export/YmlExport.php | 1 - Translation/HistoryManager.php | 8 ++++---- 8 files changed, 20 insertions(+), 21 deletions(-) diff --git a/Command/ImportCommand.php b/Command/ImportCommand.php index 5931c33..cbbc13a 100644 --- a/Command/ImportCommand.php +++ b/Command/ImportCommand.php @@ -91,7 +91,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } else { if ($bundleName) { $this->output->writeln("*** Importing {$bundleName} translation files ***"); - $bundle = $this->getApplication()->getKernel()->getBundle($bundleName); + $bundle = $this->getContainer()->get('kernel')->getBundle($bundleName); $import->importBundlesTranslationFiles([$bundle], true); } else { $this->output->writeln('*** Importing application translation files ***'); diff --git a/Controller/ListController.php b/Controller/ListController.php index 7140ae1..e998790 100644 --- a/Controller/ListController.php +++ b/Controller/ListController.php @@ -79,7 +79,7 @@ private function buildLocalesList($filter) $result = $this->repository->execute($search, Result::RESULTS_RAW); $list = []; - foreach ($result['aggregations']['agg_locale_agg']['buckets'] as $value) { + foreach ($result['aggregations']['locale_agg']['buckets'] as $value) { $list[$value['key']] = true; } ksort($list); diff --git a/Document/Translation.php b/Document/Translation.php index a60fd43..802e51e 100644 --- a/Document/Translation.php +++ b/Document/Translation.php @@ -12,7 +12,7 @@ namespace ONGR\TranslationsBundle\Document; use ONGR\ElasticsearchBundle\Annotation as ES; -use ONGR\ElasticsearchBundle\Collection; +use ONGR\ElasticsearchBundle\Collection\Collection; /** * Holds translations for certain domain. diff --git a/Resources/config/routing.yml b/Resources/config/routing.yml index e795ef3..637775f 100644 --- a/Resources/config/routing.yml +++ b/Resources/config/routing.yml @@ -1,11 +1,11 @@ ongr_translations_list_page: - pattern: /list + path: /list methods: [GET] defaults: _controller: ongr_translations.controller.list:listAction ongr_translations_api_edit: - pattern: /_api/edit + path: /_api/edit methods: [POST] defaults: _controller: ONGRTranslationsBundle:Api:edit @@ -13,7 +13,7 @@ ongr_translations_api_edit: expose: true ongr_translations_api_delete: - pattern: /_api/delete + path: /_api/delete methods: [POST] defaults: _controller: ONGRTranslationsBundle:Api:delete @@ -21,7 +21,7 @@ ongr_translations_api_delete: expose: true ongr_translations_api_add: - pattern: /_api/add + path: /_api/add methods: [POST] defaults: _controller: ONGRTranslationsBundle:Api:add @@ -29,7 +29,7 @@ ongr_translations_api_add: expose: true ongr_translations_api_get: - pattern: /_api/get + path: /_api/get methods: [POST] defaults: _controller: ONGRTranslationsBundle:Api:get @@ -37,7 +37,7 @@ ongr_translations_api_get: expose: true ongr_translations_api_check: - pattern: /_api/check + path: /_api/check methods: [POST] defaults: _controller: ONGRTranslationsBundle:Api:check @@ -45,7 +45,7 @@ ongr_translations_api_check: expose: true ongr_translations_api_export: - pattern: /_api/export + path: /_api/export methods: [POST] defaults: _controller: ONGRTranslationsBundle:Api:export @@ -53,7 +53,7 @@ ongr_translations_api_export: expose: true ongr_translations_api_history: - pattern: /_api/history + path: /_api/history methods: [POST] defaults: _controller: ONGRTranslationsBundle:Api:history diff --git a/Tests/Functional/Command/ImportCommandTest.php b/Tests/Functional/Command/ImportCommandTest.php index 44d1e59..6ff1b64 100644 --- a/Tests/Functional/Command/ImportCommandTest.php +++ b/Tests/Functional/Command/ImportCommandTest.php @@ -13,7 +13,7 @@ use ONGR\ElasticsearchBundle\Test\AbstractElasticsearchTestCase; use ONGR\TranslationsBundle\Command\ImportCommand; -use Symfony\Bundle\FrameworkBundle\Console\Application; +use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; /** diff --git a/Tests/Functional/Controller/ApiControllerTest.php b/Tests/Functional/Controller/ApiControllerTest.php index 1837775..563700f 100644 --- a/Tests/Functional/Controller/ApiControllerTest.php +++ b/Tests/Functional/Controller/ApiControllerTest.php @@ -13,7 +13,7 @@ use ONGR\ElasticsearchBundle\Result\Result; use ONGR\ElasticsearchDSL\Query\BoolQuery; -use ONGR\ElasticsearchDSL\Filter\TermFilter; +use ONGR\ElasticsearchDSL\Query\TermQuery; use ONGR\ElasticsearchBundle\Test\AbstractElasticsearchTestCase; use ONGR\TranslationsBundle\Document\History; use ONGR\TranslationsBundle\Document\Message; @@ -371,9 +371,9 @@ public function testHistoryAction() $manager = $this->getManager(); $repository = $manager->getRepository('ONGRTranslationsBundle:History'); $boolFilter = new BoolQuery(); - $boolFilter->add(new TermFilter('key', 'foo')); - $boolFilter->add(new TermFilter('domain', 'barbar')); - $boolFilter->add(new TermFilter('locale', 'en')); + $boolFilter->add(new TermQuery('key', 'foo')); + $boolFilter->add(new TermQuery('domain', 'barbar')); + $boolFilter->add(new TermQuery('locale', 'en')); $search = $repository->createSearch()->addFilter($boolFilter); $results = $repository->execute($search, Result::RESULTS_ARRAY); diff --git a/Translation/Export/YmlExport.php b/Translation/Export/YmlExport.php index d96eeee..350309a 100644 --- a/Translation/Export/YmlExport.php +++ b/Translation/Export/YmlExport.php @@ -32,7 +32,6 @@ public function export($file, $translations) if (pathinfo($file, PATHINFO_EXTENSION) === 'yml') { $ymlDumper = new Dumper(); - $ymlDumper->setIndentation(0); $ymlContent = ''; $ymlContent .= $ymlDumper->dump($translations, 10); $bytes = file_put_contents($file, $ymlContent); diff --git a/Translation/HistoryManager.php b/Translation/HistoryManager.php index a8b654f..b7188a5 100644 --- a/Translation/HistoryManager.php +++ b/Translation/HistoryManager.php @@ -12,7 +12,7 @@ namespace ONGR\TranslationsBundle\Translation; use ONGR\ElasticsearchBundle\Result\Result; -use ONGR\ElasticsearchDSL\Filter\TermFilter; +use ONGR\ElasticsearchDSL\Query\TermQuery; use ONGR\ElasticsearchDSL\Sort\FieldSort; use ONGR\ElasticsearchBundle\Service\Repository; use Symfony\Component\HttpFoundation\Request; @@ -43,9 +43,9 @@ public function history(Request $request) $content = $this->parseJsonContent($request); $search = $this->repository->createSearch(); - $search->addFilter(new TermFilter('key', $content['key'])); - $search->addFilter(new TermFilter('domain', $content['domain'])); - $search->addFilter(new TermFilter('locale', $content['locale'])); + $search->addFilter(new TermQuery('key', $content['key'])); + $search->addFilter(new TermQuery('domain', $content['domain'])); + $search->addFilter(new TermQuery('locale', $content['locale'])); $search->addSort(new FieldSort('created_at', FieldSort::DESC)); return $this->repository->execute($search, Result::RESULTS_ARRAY); From 7b700df8814c7cc98b3c3a91a05aeebb424d3997 Mon Sep 17 00:00:00 2001 From: Mantas Date: Wed, 16 Mar 2016 16:09:06 +0200 Subject: [PATCH 2/2] made list of locales to be formed from config --- Controller/ListController.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/Controller/ListController.php b/Controller/ListController.php index e998790..569dbf0 100644 --- a/Controller/ListController.php +++ b/Controller/ListController.php @@ -71,19 +71,12 @@ public function listAction(Request $request) */ private function buildLocalesList($filter) { - $search = $this->repository->createSearch(); - - $localeAgg = new TermsAggregation('locale_agg'); - $localeAgg->setField('messages.locale'); - $search->addAggregation($localeAgg); - $result = $this->repository->execute($search, Result::RESULTS_RAW); + $locales = $this->container->getParameter('ongr_translations.managed_locales'); $list = []; - - foreach ($result['aggregations']['locale_agg']['buckets'] as $value) { - $list[$value['key']] = true; + foreach ($locales as $locale) { + $list[$locale] = true; } ksort($list); - $activeLocales = []; if ($filter->getState()->isActive()) {