Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UHF-10719 #715

Merged
merged 9 commits into from
Nov 8, 2024
21 changes: 0 additions & 21 deletions conf/cmi/elasticsearch_connector.cluster.kasko.yml

This file was deleted.

7 changes: 6 additions & 1 deletion conf/cmi/search_api.index.schools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ uuid: 66be132d-2184-4b74-8f13-a79d758b964f
langcode: en
status: true
dependencies:
config:
- field.storage.tpr_unit.field_ontologyword_details
- search_api.server.elastic_kasko
module:
- helfi_tpr
- search_api
- helfi_kasko_content
- helfi_react_search
enforced:
config:
- field.storage.tpr_unit.field_ontologyword_details
Expand Down Expand Up @@ -32,7 +37,7 @@ field_settings:
coordinates:
label: Coordinates
property_path: coordinates
type: object
type: location
id:
label: ID
datasource_id: 'entity:tpr_unit'
Expand Down
11 changes: 8 additions & 3 deletions conf/cmi/search_api.server.elastic_kasko.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ name: 'Elastic kasko'
description: ''
backend: elasticsearch
backend_config:
cluster_settings:
cluster: kasko
fuzziness: auto
connector: standard
connector_config:
url: 'http://elastic:9200'
enable_debug_logging: false
advanced:
prefix: ''
suffix: ''
fuzziness: auto
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Drupal\helfi_kasko_content\EventSubscriber;

use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\elasticsearch_connector\Event\BuildIndexParamsEvent;
use Drupal\elasticsearch_connector\Event\IndexParamsEvent;
use Drupal\helfi_kasko_content\SchoolUtility;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

Expand All @@ -20,31 +20,32 @@
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
*/
public function __construct(private readonly EntityTypeManagerInterface $entityTypeManager) {
public function __construct(
private readonly EntityTypeManagerInterface $entityTypeManager,
) {
}

/**
* {@inheritdoc}
*/
public static function getSubscribedEvents(): array {
return [
BuildIndexParamsEvent::BUILD_PARAMS => 'modifyOntologywordDetailsFields',
IndexParamsEvent::class => 'modifyOntologywordDetailsFields',

Check failure on line 33 in public/modules/custom/helfi_kasko_content/src/EventSubscriber/KaskoElasticIndexSubscriber.php

View workflow job for this annotation

GitHub Actions / tests

Class Drupal\elasticsearch_connector\Event\IndexParamsEvent not found.
];
}

/**
* Index only current schoolyear Ontologyword ids and clarifications.
*
* @param \Drupal\elasticsearch_connector\Event\BuildIndexParamsEvent $event
* @param \Drupal\elasticsearch_connector\Event\IndexParamsEvent $event
* Event emitted by elasticsearch_connector.
*/
public function modifyOntologywordDetailsFields(BuildIndexParamsEvent $event): void {
public function modifyOntologywordDetailsFields(IndexParamsEvent $event): void {

Check failure on line 43 in public/modules/custom/helfi_kasko_content/src/EventSubscriber/KaskoElasticIndexSubscriber.php

View workflow job for this annotation

GitHub Actions / tests

Parameter $event of method Drupal\helfi_kasko_content\EventSubscriber\KaskoElasticIndexSubscriber::modifyOntologywordDetailsFields() has invalid type Drupal\elasticsearch_connector\Event\IndexParamsEvent.

Check failure on line 43 in public/modules/custom/helfi_kasko_content/src/EventSubscriber/KaskoElasticIndexSubscriber.php

View workflow job for this annotation

GitHub Actions / tests

Parameter $event of method Drupal\helfi_kasko_content\EventSubscriber\KaskoElasticIndexSubscriber::modifyOntologywordDetailsFields() has invalid type Drupal\elasticsearch_connector\Event\IndexParamsEvent.
if ($event->getIndexName() !== 'schools') {

Check failure on line 44 in public/modules/custom/helfi_kasko_content/src/EventSubscriber/KaskoElasticIndexSubscriber.php

View workflow job for this annotation

GitHub Actions / tests

Call to method getIndexName() on an unknown class Drupal\elasticsearch_connector\Event\IndexParamsEvent.
return;
}

/** @var array $params */
$params = $event->getElasticIndexParams();
$params = $event->getParams();

Check failure on line 48 in public/modules/custom/helfi_kasko_content/src/EventSubscriber/KaskoElasticIndexSubscriber.php

View workflow job for this annotation

GitHub Actions / tests

Call to method getParams() on an unknown class Drupal\elasticsearch_connector\Event\IndexParamsEvent.
$schoolYear = SchoolUtility::getCurrentComprehensiveSchoolYear();

foreach ($params['body'] as $key => $body) {
Expand All @@ -53,9 +54,14 @@

if (isset($body['ontologyword_details_clarifications'])) {
foreach ($body['ontologyword_details_clarifications'] as $ontologywordDetailId) {
[$language] = $body['search_api_language'];

/** @var \Drupal\helfi_tpr\Entity\OntologyWordDetails $ontologywordDetail */
$ontologywordDetail = $this->entityTypeManager->getStorage('tpr_ontology_word_details')->load($ontologywordDetailId);
$ontologywordDetail = $ontologywordDetail->hasTranslation($body['_language']) ? $ontologywordDetail->getTranslation($body['_language']) : $ontologywordDetail;
$ontologywordDetail = $this->entityTypeManager
->getStorage('tpr_ontology_word_details')
->load($ontologywordDetailId);

$ontologywordDetail = $ontologywordDetail->hasTranslation($language) ? $ontologywordDetail->getTranslation($language) : $ontologywordDetail;
$ontologywordId = $ontologywordDetail->get('ontologyword_id')->getString();
$detailItems = $ontologywordDetail->get('detail_items');

Expand All @@ -80,7 +86,7 @@
}
}

$event->setElasticIndexParams($params);
$event->setParams($params);

Check failure on line 89 in public/modules/custom/helfi_kasko_content/src/EventSubscriber/KaskoElasticIndexSubscriber.php

View workflow job for this annotation

GitHub Actions / tests

Call to method setParams() on an unknown class Drupal\elasticsearch_connector\Event\IndexParamsEvent.
}

}
9 changes: 4 additions & 5 deletions public/sites/default/all.settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@

// Elasticsearch settings.
if (getenv('ELASTICSEARCH_URL')) {
$config['elasticsearch_connector.cluster.kasko']['url'] = getenv('ELASTICSEARCH_URL');
$config['search_api.server.elastic_kasko']['backend_config']['connector_config']['url'] = getenv('ELASTICSEARCH_URL');

if (getenv('ELASTIC_USER') && getenv('ELASTIC_PASSWORD')) {
$config['elasticsearch_connector.cluster.kasko']['options']['use_authentication'] = '1';
$config['elasticsearch_connector.cluster.kasko']['options']['authentication_type'] = 'Basic';
$config['elasticsearch_connector.cluster.kasko']['options']['username'] = getenv('ELASTIC_USER');
$config['elasticsearch_connector.cluster.kasko']['options']['password'] = getenv('ELASTIC_PASSWORD');
$config['search_api.server.elastic_kasko']['backend_config']['connector'] = 'basicauth';
$config['search_api.server.elastic_kasko']['backend_config']['connector_config']['username'] = getenv('ELASTIC_USER');
$config['search_api.server.elastic_kasko']['backend_config']['connector_config']['password'] = getenv('ELASTIC_PASSWORD');
}
}

Expand Down
Loading