Skip to content

Commit

Permalink
BUGS-7551: Updates ConfigFilesAlter to use a listener instead of hook.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Wagner committed Mar 4, 2024
1 parent 77fad97 commit 42cca10
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 20 deletions.
20 changes: 0 additions & 20 deletions search_api_pantheon.module
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,3 @@
* @file
*/

/**
* @issue BUGS-4278
*
* Implements hook_search_api_solr_config_files_alter().
*
* Remember to post schema after any changes to the XML files here.
*/
function search_api_pantheon_search_api_solr_config_files_alter(array &$files, string $lucene_match_version, string $server_id = '') {
// Append at the end of the file.
$solrcore_properties = explode(PHP_EOL, $files['solrcore.properties']);
// Remove the solr.install.dir if it exists
foreach ($solrcore_properties as $key => $property) {
if (substr($property, 0, 16) == 'solr.install.dir') {
unset($solrcore_properties[$key]);
}
}
// Remove the solrcore.properties file from the upload
// This file is causing undue issues with core restarts
unset($files['solrcore.properties']);
}
4 changes: 4 additions & 0 deletions search_api_pantheon.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ services:
search_api_pantheon.solarium_client:
class: Drupal\search_api_pantheon\Services\SolariumClient
arguments: ['@search_api_pantheon.pantheon_guzzle', '@search_api_pantheon.endpoint', '@logger.factory', '@event_dispatcher']
search_api_pantheon.event_subscriber:
class: Drupal\search_api_pantheon\EventSubscriber\SearchApiPantheonSolrConfigFilesAlter
tags:
- { name: event_subscriber }
51 changes: 51 additions & 0 deletions src/EventSubscriber/SearchApiPantheonSolrConfigFilesAlter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php declare(strict_types = 1);

namespace Drupal\search_api_pantheon\EventSubscriber;

use Drupal\search_api_solr\Event\PostConfigFilesGenerationEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;

/**
* @issue BUGS-4278
*
* Implements hook_search_api_solr_config_files_alter().
*
* Remember to post schema after any changes to the XML files here.
*/
final class SearchApiPantheonSolrConfigFilesAlter implements EventSubscriberInterface {

/**
* PostConfigFilesGenerationEvent event handler.
*
* @param PostConfigFilesGenerationEvent $event
*/
public function onPostConfigFilesGenerationEvent(PostConfigFilesGenerationEvent $event): void {
$files = $event->getConfigFiles();
// Append at the end of the file.
$solrcore_properties = explode(PHP_EOL, $files['solrcore.properties']);
// Remove the solr.install.dir if it exists
foreach ($solrcore_properties as $key => $property) {
if (substr($property, 0, 16) == 'solr.install.dir') {
unset($solrcore_properties[$key]);
}
}
// Remove the solrcore.properties file from the upload
// This file is causing undue issues with core restarts
unset($files['solrcore.properties']);

$event->setConfigFiles($files);
}

/**
* {@inheritdoc}
*/
public static function getSubscribedEvents(): array {
return [
'Drupal\search_api_solr\Event\PostConfigFilesGenerationEvent' => ['onPostConfigFilesGenerationEvent'],
];
}

}

0 comments on commit 42cca10

Please sign in to comment.