mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-11 03:53:13 +00:00

- Squashed Pull request #1730 - Squashed Pull request #1741 - Squashed Pull request #1742 - Squash merge branch 4.0 - Squashed Pull request #1744 - Squashed Pull request #1746 - Squashed merge branch 4.0 - Squashed merge branch 4.0 - Squashed merge branch 4.0 - Squashed merge branch 4.0 - Squashed Pull request #1758 - Avoid using imagine/imagine alias as it is causing install issues - Squashed merge branch 4.0 - Squashed Pull request #1763 - Squashed merge branch 4.0 - Squash of 6 commits - Squashed merge branch 4.0 - This is a combination of 2 commits. - Squashed Pull request #1775 - Squashed Pull request #1777 - Squashed Pull request #1779 - Squashed Pull request #1780 - Squashed Pull request #1782 - Adds a Pull request template - Squased Pull request #1783 - Squash Pull request #1786 - Squashed Pull request #1796 - Squashed merge branch 4.0 - Squash Pull request #1791 - Squashed merge branch 4.0 - Squashed Pull request #1808 - Squashed Pull request #1811 - Squashed Pull request #1809
91 lines
2.6 KiB
PHP
91 lines
2.6 KiB
PHP
<?php
|
|
/*
|
|
* This file is part of Phraseanet
|
|
*
|
|
* (c) 2005-2016 Alchemy
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Alchemy\Phrasea\Controller\Admin;
|
|
|
|
use Alchemy\Phrasea\Controller\Controller;
|
|
use Alchemy\Phrasea\SearchEngine\Elastic\ElasticsearchSettingsFormType;
|
|
use Alchemy\Phrasea\SearchEngine\Elastic\ElasticsearchOptions;
|
|
use Symfony\Component\Form\FormInterface;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class SearchEngineController extends Controller
|
|
{
|
|
/**
|
|
* @param Request $request
|
|
* @return Response
|
|
*/
|
|
public function formConfigurationPanelAction(Request $request)
|
|
{
|
|
$options = $this->getElasticsearchOptions();
|
|
$form = $this->getConfigurationForm($options);
|
|
|
|
$form->handleRequest($request);
|
|
|
|
if ($form->isValid()) {
|
|
$this->saveElasticSearchOptions($form->getData());
|
|
|
|
return $this->app->redirectPath('admin_searchengine_form');
|
|
}
|
|
|
|
return $this->render('admin/search-engine/elastic-search.html.twig', [
|
|
'form' => $form->createView(),
|
|
'indexer' => $this->app['elasticsearch.indexer']
|
|
]);
|
|
}
|
|
|
|
public function dropIndexAction(Request $request)
|
|
{
|
|
$indexer = $this->app['elasticsearch.indexer'];
|
|
if ($indexer->indexExists()) {
|
|
$indexer->deleteIndex();
|
|
}
|
|
return $this->app->redirectPath('admin_searchengine_form');
|
|
}
|
|
|
|
public function createIndexAction(Request $request)
|
|
{
|
|
$indexer = $this->app['elasticsearch.indexer'];
|
|
if (!$indexer->indexExists()) {
|
|
$indexer->createIndex();
|
|
}
|
|
return $this->app->redirectPath('admin_searchengine_form');
|
|
}
|
|
|
|
/**
|
|
* @return ElasticsearchOptions
|
|
*/
|
|
private function getElasticsearchOptions()
|
|
{
|
|
return $this->app['elasticsearch.options'];
|
|
}
|
|
|
|
/**
|
|
* @param ElasticsearchOptions $configuration
|
|
* @return void
|
|
*/
|
|
private function saveElasticSearchOptions(ElasticsearchOptions $configuration)
|
|
{
|
|
$this->getConf()->set(['main', 'search-engine', 'options'], $configuration->toArray());
|
|
}
|
|
|
|
/**
|
|
* @param ElasticsearchOptions $options
|
|
* @return FormInterface
|
|
*/
|
|
private function getConfigurationForm(ElasticsearchOptions $options)
|
|
{
|
|
return $this->app->form(new ElasticsearchSettingsFormType(), $options, [
|
|
'action' => $this->app->url('admin_searchengine_form'),
|
|
]);
|
|
}
|
|
}
|