-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
231 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ds_opensearch_controller_admin_index_rebuild_mapping: | ||
path: /admin/ds-index-provider-opensearch/index/rebuild-mapping | ||
methods: [ POST ] | ||
defaults: { _controller: DsOpenSearchBundle\Controller\Admin\IndexController::rebuildMappingAction } | ||
options: | ||
expose: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
services: | ||
|
||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
public: true | ||
|
||
DsOpenSearchBundle\Controller\Admin\IndexController: | ||
tags: | ||
- 'controller.service_arguments' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
services: | ||
|
||
_defaults: | ||
autowire: true | ||
autoconfigure: true | ||
public: false | ||
|
||
DsOpenSearchBundle\EventListener\Admin\AssetListener: | ||
tags: | ||
- { name: kernel.event_subscriber } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
class DsIndexProviderOpensearch { | ||
|
||
addLayoutToDsSettings(event) { | ||
|
||
this.dsSettings = event.detail.subject; | ||
this.dsContextFullConfig = pimcore.globalmanager.get('dynamic_search.context.full_configuration') || {}; | ||
|
||
const dsActionsPanel = new Ext.panel.Panel({ | ||
layout: 'hbox', | ||
title: 'DsIndexProviderOpenSearch', | ||
bodyPadding: 10, | ||
items: [ | ||
|
||
] | ||
}); | ||
this.dsSettings.panel.add(dsActionsPanel); | ||
|
||
if (Object.keys(this.dsContextFullConfig).length === 0) { | ||
dsActionsPanel.add({ | ||
xtype: 'displayfield', | ||
value: 'Error: no dynamic search context configured' | ||
}); | ||
return; | ||
} | ||
|
||
dsActionsPanel.add({ | ||
xtype: 'toolbar', | ||
docked: 'top', | ||
items: [ | ||
{ | ||
scale: 'small', | ||
margin: '0 10 0 0', | ||
text: t('ds_index_provider_opensearch.actions.index.rebuild_mapping'), | ||
icon: '/bundles/pimcoreadmin/img/flat-color-icons/data_configuration.svg', | ||
menu: this.buildContextButtonMenu( 'rebuild_mapping'), | ||
} | ||
] | ||
}); | ||
|
||
} | ||
|
||
buildContextButtonMenu(action) { | ||
return Object.keys(this.dsContextFullConfig).map(function(context) { | ||
return { | ||
text: context, | ||
handler: function() { | ||
Ext.Msg.confirm( | ||
t(`ds_index_provider_opensearch.actions.index.${action}`) + ': ' + context, | ||
t(`ds_index_provider_opensearch.actions.index.${action}.confirmation.message`), | ||
function (confirmMsg) { | ||
|
||
if (confirmMsg !== 'yes') { | ||
return; | ||
} | ||
|
||
this.performContextIndexAction(context, action); | ||
|
||
}.bind(this) | ||
); | ||
}.bind(this) | ||
} | ||
}.bind(this)) | ||
} | ||
|
||
performContextIndexAction(context, action) { | ||
let url = ''; | ||
|
||
try { | ||
url = Routing.generate('ds_opensearch_controller_admin_index_' + action); | ||
} catch (e) { | ||
Ext.Msg.alert('Error', e.message); | ||
return; | ||
} | ||
|
||
Ext.Ajax.request({ | ||
url: url, | ||
method: 'POST', | ||
params: { | ||
context: context | ||
}, | ||
success: function(response) { | ||
if (response.status === 200) { | ||
pimcore.helpers.showNotification(t('success'), t(`ds_index_provider_opensearch.actions.index.${action}.success`), 'success'); | ||
} else { | ||
pimcore.helpers.showNotification(t('error'), response.responseText, 'error'); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
|
||
const dsIndexProviderOpensearch = new DsIndexProviderOpensearch(); | ||
|
||
document.addEventListener('dynamic_search.event.settings.postBuildLayout', dsIndexProviderOpensearch.addLayoutToDsSettings.bind(dsIndexProviderOpensearch)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace DsOpenSearchBundle\Controller\Admin; | ||
|
||
use DsOpenSearchBundle\Builder\ClientBuilderInterface; | ||
use DsOpenSearchBundle\Service\IndexPersistenceService; | ||
use DynamicSearchBundle\Builder\ContextDefinitionBuilderInterface; | ||
use DynamicSearchBundle\Context\ContextDefinitionInterface; | ||
use DynamicSearchBundle\Generator\IndexDocumentGeneratorInterface; | ||
use DynamicSearchBundle\Provider\PreConfiguredIndexProviderInterface; | ||
use Pimcore\Bundle\AdminBundle\Controller\AdminAbstractController; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class IndexController extends AdminAbstractController | ||
{ | ||
public function __construct( | ||
protected ContextDefinitionBuilderInterface $contextDefinitionBuilder, | ||
protected IndexDocumentGeneratorInterface $indexDocumentGenerator, | ||
protected ClientBuilderInterface $clientBuilder, | ||
) | ||
{ | ||
} | ||
|
||
public function rebuildMappingAction(Request $request): Response | ||
{ | ||
$contextName = $request->get('context'); | ||
|
||
if (empty($contextName)) { | ||
return new Response('no context given', 400); | ||
} | ||
|
||
try { | ||
$contextDefinition = $this->contextDefinitionBuilder->buildContextDefinition($contextName, ContextDefinitionInterface::CONTEXT_DISPATCH_TYPE_INDEX); | ||
|
||
if (!$contextDefinition instanceof ContextDefinitionInterface) { | ||
throw new \Exception( | ||
sprintf('no context definition with name "%s" found', $contextName) | ||
); | ||
} | ||
|
||
$indexDocument = $this->indexDocumentGenerator->generateWithoutData($contextDefinition, ['preConfiguredIndexProvider' => true]); | ||
|
||
if (!$indexDocument->hasIndexFields()) { | ||
throw new \Exception( | ||
sprintf( | ||
'No Index Document found. The current context index provider requires pre-configured indices. Please make sure your document definition implements the "%s" interface', | ||
PreConfiguredIndexProviderInterface::class | ||
) | ||
); | ||
} | ||
|
||
$options = $contextDefinition->getIndexProviderOptions(); | ||
|
||
$client = $this->clientBuilder->build($options); | ||
$indexService = new IndexPersistenceService($client, $options); | ||
|
||
if ($indexService->indexExists()) { | ||
$indexService->dropIndex(); | ||
} | ||
|
||
$indexService->createIndex($indexDocument); | ||
} catch (\Throwable $e) { | ||
return new Response($e->getMessage(), 500); | ||
} | ||
|
||
return new Response(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace DsOpenSearchBundle\EventListener\Admin; | ||
|
||
use Pimcore\Event\BundleManager\PathsEvent; | ||
use Pimcore\Event\BundleManagerEvents; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
class AssetListener implements EventSubscriberInterface | ||
{ | ||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
BundleManagerEvents::JS_PATHS => 'addJsFiles' | ||
]; | ||
} | ||
|
||
public function addJsFiles(PathsEvent $event): void | ||
{ | ||
$event->addPaths([ | ||
'/bundles/dsopensearch/js/backend/settings.js', | ||
]); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
ds_index_provider_opensearch.actions.index.rebuild_mapping: 'Rebuild index mapping' | ||
ds_index_provider_opensearch.actions.index.rebuild_mapping.confirmation.message: 'This will drop the selected index and all data will be lost! Continue?' | ||
ds_index_provider_opensearch.actions.index.rebuild_mapping.success: 'Index rebuild was successful' |