From 127254ce33fd156d586e55c745caf682f7fc4188 Mon Sep 17 00:00:00 2001 From: Kevin Porras Date: Tue, 16 Nov 2021 16:30:52 -0600 Subject: [PATCH 1/3] Set full configuration on form submit and override core from env var as needed. --- .../SolrConnector/PantheonSolrConnector.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Plugin/SolrConnector/PantheonSolrConnector.php b/src/Plugin/SolrConnector/PantheonSolrConnector.php index 416d1bc8..4b6a1270 100644 --- a/src/Plugin/SolrConnector/PantheonSolrConnector.php +++ b/src/Plugin/SolrConnector/PantheonSolrConnector.php @@ -129,6 +129,7 @@ public function defaultConfiguration() { 'core' => getenv('PANTHEON_INDEX_CORE'), 'schema' => getenv('PANTHEON_INDEX_SCHEMA'), 'solr_version' => '8', + 'commit_within' => 1000, ]); } @@ -180,7 +181,9 @@ public function submitConfigurationForm( array &$form, FormStateInterface $form_state ) { - $this->setConfiguration($form_state->getValues()); + $configuration = $form_state->getValues(); + $configuration = array_merge($this->defaultConfiguration(), $configuration); + $this->setConfiguration($configuration); } /** @@ -312,6 +315,14 @@ public function viewSettings() { return $view_settings; } + /** + * {@inheritdoc} + */ + public function getCoreInfo($reset = FALSE) { + $this->useTimeout(); + return $this->getDataFromHandler(getenv('PANTHEON_INDEX_CORE') . '/admin/system', $reset); + } + /** * Override any other endpoints by getting the Pantheon Default endpoint. * @@ -357,7 +368,7 @@ public function getFile($file = NULL) { * {@inheritdoc} */ public function getServerInfo($reset = FALSE) { - return $this->getDataFromHandler($this->configuration['core'] . '/admin/system', $reset); + return $this->getDataFromHandler(getenv('PANTHEON_INDEX_CORE') . '/admin/system', $reset); } /** From c9cac079a8e602acba1fe65410f24658e47eb4da Mon Sep 17 00:00:00 2001 From: Kevin Porras Date: Tue, 16 Nov 2021 16:42:15 -0600 Subject: [PATCH 2/3] Force override core and schema options. --- src/Plugin/SolrConnector/PantheonSolrConnector.php | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/Plugin/SolrConnector/PantheonSolrConnector.php b/src/Plugin/SolrConnector/PantheonSolrConnector.php index 4b6a1270..2504a2e8 100644 --- a/src/Plugin/SolrConnector/PantheonSolrConnector.php +++ b/src/Plugin/SolrConnector/PantheonSolrConnector.php @@ -87,6 +87,8 @@ public function __construct( $this->dateFormatter = $date_formatter; $this->messenger = $messenger; $this->setLogger($logger_factory->get('PantheonSearch')); + $this->configuration['core'] = getenv('PANTHEON_INDEX_CORE'); + $this->configuration['schema'] = getenv('PANTHEON_INDEX_SCHEMA'); $this->connect(); } @@ -315,14 +317,6 @@ public function viewSettings() { return $view_settings; } - /** - * {@inheritdoc} - */ - public function getCoreInfo($reset = FALSE) { - $this->useTimeout(); - return $this->getDataFromHandler(getenv('PANTHEON_INDEX_CORE') . '/admin/system', $reset); - } - /** * Override any other endpoints by getting the Pantheon Default endpoint. * @@ -368,7 +362,7 @@ public function getFile($file = NULL) { * {@inheritdoc} */ public function getServerInfo($reset = FALSE) { - return $this->getDataFromHandler(getenv('PANTHEON_INDEX_CORE') . '/admin/system', $reset); + return $this->getDataFromHandler($this->configuration['core'] . '/admin/system', $reset); } /** From 4fd49c7b59fa904cef4ae0a1e58d9da2b2776f45 Mon Sep 17 00:00:00 2001 From: Kevin Porras Date: Tue, 16 Nov 2021 16:42:32 -0600 Subject: [PATCH 3/3] Merge options on endpoint creation. --- src/Services/Endpoint.php | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/Services/Endpoint.php b/src/Services/Endpoint.php index d01cce77..1cb0c80f 100644 --- a/src/Services/Endpoint.php +++ b/src/Services/Endpoint.php @@ -44,18 +44,17 @@ class Endpoint extends SolariumEndpoint { * they are used by other functions of the endpoint. */ public function __construct(array $options = []) { - if (!$options) { - $options = [ - 'scheme' => getenv('PANTHEON_INDEX_SCHEME'), - 'host' => getenv('PANTHEON_INDEX_HOST'), - 'port' => getenv('PANTHEON_INDEX_PORT'), - 'path' => getenv('PANTHEON_INDEX_PATH'), - 'core' => getenv('PANTHEON_INDEX_CORE'), - 'schema' => getenv('PANTHEON_INDEX_SCHEMA'), - 'collection' => NULL, - 'leader' => FALSE, - ]; - } + // We intentionally want to override this options in case they are set in the parameter. + $options = array_merge($options, [ + 'scheme' => getenv('PANTHEON_INDEX_SCHEME'), + 'host' => getenv('PANTHEON_INDEX_HOST'), + 'port' => getenv('PANTHEON_INDEX_PORT'), + 'path' => getenv('PANTHEON_INDEX_PATH'), + 'core' => getenv('PANTHEON_INDEX_CORE'), + 'schema' => getenv('PANTHEON_INDEX_SCHEMA'), + 'collection' => NULL, + 'leader' => FALSE, + ]); parent::__construct($options); }