From df22b24b1933dd5e07f507cb4ee29f22b1acb57f Mon Sep 17 00:00:00 2001 From: aynsix Date: Tue, 23 Jun 2020 11:06:51 +0300 Subject: [PATCH] add populate controller in thesaurus --- .../Thesaurus/ThesaurusController.php | 31 +++++++++++++++++++ .../Thesaurus/Thesaurus.php | 1 + 2 files changed, 32 insertions(+) diff --git a/lib/Alchemy/Phrasea/Controller/Thesaurus/ThesaurusController.php b/lib/Alchemy/Phrasea/Controller/Thesaurus/ThesaurusController.php index 1bd06d83b2..b31ad7e8c2 100644 --- a/lib/Alchemy/Phrasea/Controller/Thesaurus/ThesaurusController.php +++ b/lib/Alchemy/Phrasea/Controller/Thesaurus/ThesaurusController.php @@ -13,6 +13,9 @@ use Alchemy\Phrasea\Application\Helper\DispatcherAware; use Alchemy\Phrasea\Controller\Controller; use Alchemy\Phrasea\Core\Event\Thesaurus as ThesaurusEvent; use Alchemy\Phrasea\Core\Event\Thesaurus\ThesaurusEvents; +use Alchemy\Phrasea\SearchEngine\Elastic\ElasticsearchOptions; +use Alchemy\Phrasea\WorkerManager\Event\PopulateIndexEvent; +use Alchemy\Phrasea\WorkerManager\Event\WorkerEvents; use Doctrine\DBAL\Driver\Connection; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -1222,6 +1225,26 @@ class ThesaurusController extends Controller ]); } + /** + * Order to populate databox + * + * @param Request $request + * @return \Symfony\Component\HttpFoundation\JsonResponse + */ + public function populate(Request $request) + { + $options = $this->getElasticsearchOptions(); + + $data['host'] = $options->getHost(); + $data['port'] = $options->getPort(); + $data['indexName'] = $options->getIndexName(); + $data['databoxIds'] = [$request->get('databox_id')]; + + $this->getDispatcher()->dispatch(WorkerEvents::POPULATE_INDEX, new PopulateIndexEvent($data)); + + return $this->app->json($data); + } + /** * @param Request $request * @return Response @@ -3031,4 +3054,12 @@ class ThesaurusController extends Controller { return $this->app['locales.available']; } + + /** + * @return ElasticsearchOptions + */ + private function getElasticsearchOptions() + { + return $this->app['elasticsearch.options']; + } } diff --git a/lib/Alchemy/Phrasea/ControllerProvider/Thesaurus/Thesaurus.php b/lib/Alchemy/Phrasea/ControllerProvider/Thesaurus/Thesaurus.php index 039cb4b96f..d5119eede9 100644 --- a/lib/Alchemy/Phrasea/ControllerProvider/Thesaurus/Thesaurus.php +++ b/lib/Alchemy/Phrasea/ControllerProvider/Thesaurus/Thesaurus.php @@ -60,6 +60,7 @@ class Thesaurus implements ControllerProviderInterface, ServiceProviderInterface $controllers->match('newterm.php', 'controller.thesaurus:newTerm'); $controllers->match('properties.php', 'controller.thesaurus:properties'); $controllers->match('thesaurus.php', 'controller.thesaurus:thesaurus')->bind('thesaurus_thesaurus'); + $controllers->match('populate', 'controller.thesaurus:populate')->bind('thesaurus_populate'); $controllers->match('xmlhttp/accept.x.php', 'controller.thesaurus:acceptXml'); $controllers->match('xmlhttp/acceptcandidates.x.php', 'controller.thesaurus:acceptCandidatesXml');