From 42cca10020a1279597810459f97c32cdba00904d Mon Sep 17 00:00:00 2001 From: Ryan Wagner Date: Mon, 4 Mar 2024 15:31:17 -0500 Subject: [PATCH] BUGS-7551: Updates ConfigFilesAlter to use a listener instead of hook. --- search_api_pantheon.module | 20 -------- search_api_pantheon.services.yml | 4 ++ .../SearchApiPantheonSolrConfigFilesAlter.php | 51 +++++++++++++++++++ 3 files changed, 55 insertions(+), 20 deletions(-) create mode 100644 src/EventSubscriber/SearchApiPantheonSolrConfigFilesAlter.php diff --git a/search_api_pantheon.module b/search_api_pantheon.module index 3ae685eb..26bd8005 100644 --- a/search_api_pantheon.module +++ b/search_api_pantheon.module @@ -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']); -} diff --git a/search_api_pantheon.services.yml b/search_api_pantheon.services.yml index 34776a37..f20aa923 100755 --- a/search_api_pantheon.services.yml +++ b/search_api_pantheon.services.yml @@ -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 } diff --git a/src/EventSubscriber/SearchApiPantheonSolrConfigFilesAlter.php b/src/EventSubscriber/SearchApiPantheonSolrConfigFilesAlter.php new file mode 100644 index 00000000..9d228dd2 --- /dev/null +++ b/src/EventSubscriber/SearchApiPantheonSolrConfigFilesAlter.php @@ -0,0 +1,51 @@ +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'], + ]; + } + +}