add populate controller in thesaurus

This commit is contained in:
aynsix
2020-06-23 11:06:51 +03:00
parent 1d13486e88
commit df22b24b19
2 changed files with 32 additions and 0 deletions

View File

@@ -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'];
}
}

View File

@@ -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');