From 2531fa2ae54729bb713b191942a60ba909ffa6b5 Mon Sep 17 00:00:00 2001 From: Sumit Madan <40235-sumitmadan@users.noreply.drupalcode.org> Date: Sun, 1 Sep 2024 16:48:30 +0530 Subject: [PATCH 1/4] Added query parameter to fetch json formatted response from solr. --- .../src/Form/PantheonSolrAdminForm.php | 7 ++++++- src/Commands/Diagnose.php | 2 ++ src/Commands/TestIndexAndQuery.php | 1 + src/Plugin/SolrConnector/PantheonSolrConnector.php | 1 + 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/search_api_pantheon_admin/src/Form/PantheonSolrAdminForm.php b/modules/search_api_pantheon_admin/src/Form/PantheonSolrAdminForm.php index 368f2197..6773cbdc 100644 --- a/modules/search_api_pantheon_admin/src/Form/PantheonSolrAdminForm.php +++ b/modules/search_api_pantheon_admin/src/Form/PantheonSolrAdminForm.php @@ -55,7 +55,12 @@ public function buildForm( ServerInterface $search_api_server = NULL ): array { $file_list = $this->pantheonGuzzle - ->getQueryResult('admin/file', ['query' => ['action' => 'VIEW']]); + ->getQueryResult('admin/file', [ + 'query' => [ + 'action' => 'VIEW', + 'wt' => 'json', + ], + ]); $form['status'] = [ '#type' => 'vertical_tabs', '#title' => $this->t('Pantheon Search Files'), diff --git a/src/Commands/Diagnose.php b/src/Commands/Diagnose.php index bafac818..2e9430df 100644 --- a/src/Commands/Diagnose.php +++ b/src/Commands/Diagnose.php @@ -160,6 +160,7 @@ public function diagnose() { $indexedStats = $this->pantheonGuzzle->getQueryResult('admin/luke', [ 'query' => [ 'stats' => 'true', + 'wt' => 'json', ], ]); if ($this->output()->isVerbose()) { @@ -173,6 +174,7 @@ public function diagnose() { $beans = $this->pantheonGuzzle->getQueryResult('admin/mbeans', [ 'query' => [ 'stats' => 'true', + 'wt' => 'json', ], ]); if ($this->output()->isVerbose()) { diff --git a/src/Commands/TestIndexAndQuery.php b/src/Commands/TestIndexAndQuery.php index e954fdf0..8cf11ef6 100644 --- a/src/Commands/TestIndexAndQuery.php +++ b/src/Commands/TestIndexAndQuery.php @@ -130,6 +130,7 @@ public function testIndexAndQuery() { 'query' => [ 'q' => 'index_id:' . $index->id(), 'fields' => ['id', 'index_id', 'name'], + 'wt' => 'json', ], ]); if ($result['response']['numFound'] === 1) { diff --git a/src/Plugin/SolrConnector/PantheonSolrConnector.php b/src/Plugin/SolrConnector/PantheonSolrConnector.php index e5cd3147..c2ce5ea2 100644 --- a/src/Plugin/SolrConnector/PantheonSolrConnector.php +++ b/src/Plugin/SolrConnector/PantheonSolrConnector.php @@ -423,6 +423,7 @@ public function getFile($file = NULL) { } return $this->pantheonGuzzle->get('admin/file', [ 'query' => $query, + 'wt' => 'json', ]); } From 4eb4feb0ee5f291bf2fa21f39dbc953f70c21415 Mon Sep 17 00:00:00 2001 From: Sumit Madan <40235-sumitmadan@users.noreply.drupalcode.org> Date: Tue, 3 Sep 2024 11:26:30 +0530 Subject: [PATCH 2/4] Used logger object from constructure instead of its parent class. --- src/Commands/Diagnose.php | 42 +++++++++++++++--------------- src/Commands/Schema.php | 4 +-- src/Commands/TestIndexAndQuery.php | 20 +++++++------- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/Commands/Diagnose.php b/src/Commands/Diagnose.php index 2e9430df..066f24fa 100644 --- a/src/Commands/Diagnose.php +++ b/src/Commands/Diagnose.php @@ -102,58 +102,58 @@ public function diagnose() { if ($pantheon_yml['search']['version'] != '8') { throw new \Exception('Unsupported search.version in pantheon.yml or pantheon.upstream.yml'); } - $this->logger()->notice('Pantheon.yml file looks ok ✅'); + $this->logger->notice('Pantheon.yml file looks ok ✅'); - $this->logger()->notice('Index SCHEME Value: {var}', [ + $this->logger->notice('Index SCHEME Value: {var}', [ 'var' => $this->endpoint->getScheme(), ]); - $this->logger()->notice('Index HOST Value: {var}', [ + $this->logger->notice('Index HOST Value: {var}', [ 'var' => $this->endpoint->getHost(), ]); - $this->logger()->notice('Index PORT Value: {var}', [ + $this->logger->notice('Index PORT Value: {var}', [ 'var' => $this->endpoint->getPort(), ]); - $this->logger()->notice('Index CORE Value: {var}', [ + $this->logger->notice('Index CORE Value: {var}', [ 'var' => $this->endpoint->getCore(), ]); - $this->logger()->notice('Index PATH Value: {var}', [ + $this->logger->notice('Index PATH Value: {var}', [ 'var' => $this->endpoint->getPath(), ]); - $this->logger()->notice('Testing bare Connection...'); + $this->logger->notice('Testing bare Connection...'); $response = $this->pingSolrHost(); - $this->logger()->notice('Ping Received Response? {var}', [ + $this->logger->notice('Ping Received Response? {var}', [ 'var' => $response instanceof ResultInterface ? '✅' : '❌', ]); - $this->logger()->notice('Response http status == 200? {var}', [ + $this->logger->notice('Response http status == 200? {var}', [ 'var' => $response->getResponse()->getStatusCode() === 200 ? '✅' : '❌', ]); if ($response->getResponse()->getStatusCode() !== 200) { throw new \Exception('Cannot contact solr server.'); } - $this->logger()->notice('Drupal Integration...'); + $this->logger->notice('Drupal Integration...'); // @codingStandardsIgnoreLine $manager = \Drupal::getContainer()->get( 'plugin.manager.search_api_solr.connector' ); $connectors = array_keys($manager->getDefinitions() ?? []); - $this->logger()->notice('Pantheon Connector Plugin Exists? {var}', [ + $this->logger->notice('Pantheon Connector Plugin Exists? {var}', [ 'var' => in_array('pantheon', $connectors) ? '✅' : '❌', ]); $connectorPlugin = $manager->createInstance('pantheon'); - $this->logger()->notice('Connector Plugin Instance created {var}', [ + $this->logger->notice('Connector Plugin Instance created {var}', [ 'var' => $connectorPlugin instanceof SolrConnectorInterface ? '✅' : '❌', ]); if (!$connectorPlugin instanceof SolrConnectorInterface) { throw new \Exception('Cannot instantiate solr connector.'); } - $this->logger()->notice('Adding Logger to connector...'); + $this->logger->notice('Adding Logger to connector...'); $connectorPlugin->setLogger($this->logger); - $this->logger()->notice('Using connector plugin to get server Info...'); + $this->logger->notice('Using connector plugin to get server Info...'); $info = $connectorPlugin->getServerInfo(); if ($this->output()->isVerbose()) { - $this->logger()->notice(print_r($info, TRUE)); + $this->logger->notice(print_r($info, TRUE)); } - $this->logger()->notice('Solr Server Version {var}', [ + $this->logger->notice('Solr Server Version {var}', [ 'var' => $info['lucene']['solr-spec-version'] ?? '❌', ]); @@ -164,12 +164,12 @@ public function diagnose() { ], ]); if ($this->output()->isVerbose()) { - $this->logger()->notice('Solr Index Stats: {stats}', [ + $this->logger->notice('Solr Index Stats: {stats}', [ 'stats' => print_r($indexedStats['index'], TRUE), ]); } else { - $this->logger()->notice('We got Solr stats ✅'); + $this->logger->notice('We got Solr stats ✅'); } $beans = $this->pantheonGuzzle->getQueryResult('admin/mbeans', [ 'query' => [ @@ -178,12 +178,12 @@ public function diagnose() { ], ]); if ($this->output()->isVerbose()) { - $this->logger()->notice('Mbeans Stats: {stats}', [ + $this->logger->notice('Mbeans Stats: {stats}', [ 'stats' => print_r($beans['solr-mbeans'], TRUE), ]); } else { - $this->logger()->notice('We got Mbeans stats ✅'); + $this->logger->notice('We got Mbeans stats ✅'); } } catch (\Exception $e) { @@ -196,7 +196,7 @@ public function diagnose() { $this->logger->emergency("There's a problem somewhere..."); exit(1); } - $this->logger()->notice( + $this->logger->notice( "If there's an issue with the connection, it would have shown up here. You should be good to go!" ); } diff --git a/src/Commands/Schema.php b/src/Commands/Schema.php index 77c4ae8f..c43b37dc 100644 --- a/src/Commands/Schema.php +++ b/src/Commands/Schema.php @@ -92,7 +92,7 @@ public function postSchema(?string $server_id = NULL, ?string $path = NULL) { $this->schemaPoster->postSchema($server_id, $files); } catch (\Exception $e) { - $this->logger()->error((string) $e); + $this->logger->error((string) $e); } } @@ -112,7 +112,7 @@ public function postSchema(?string $server_id = NULL, ?string $path = NULL) { */ public function viewSchema(string $filename = 'schema.xml') { $currentSchema = $this->schemaPoster->viewSchema($filename); - $this->logger()->notice($currentSchema); + $this->logger->notice($currentSchema); } } diff --git a/src/Commands/TestIndexAndQuery.php b/src/Commands/TestIndexAndQuery.php index 8cf11ef6..e0c23140 100644 --- a/src/Commands/TestIndexAndQuery.php +++ b/src/Commands/TestIndexAndQuery.php @@ -75,10 +75,10 @@ public function testIndexAndQuery() { $drupal_root = \DRUPAL_ROOT; $response = $this->pingSolrHost(); - $this->logger()->notice('Ping Received Response? {var}', [ + $this->logger->notice('Ping Received Response? {var}', [ 'var' => $response instanceof ResultInterface ? '✅' : '❌', ]); - $this->logger()->notice('Response http status == 200? {var}', [ + $this->logger->notice('Response http status == 200? {var}', [ 'var' => $response->getResponse()->getStatusCode() === 200 ? '✅' : '❌', ]); if ($response->getResponse()->getStatusCode() !== 200) { @@ -86,7 +86,7 @@ public function testIndexAndQuery() { } // Create a new random index. - $this->logger()->notice("Creating temporary index..."); + $this->logger->notice("Creating temporary index..."); $module_root = \Drupal::service('extension.list.module')->getPath('search_api_pantheon'); $value = Yaml::parseFile($module_root . '/.ci/config/search_api.index.solr_index.yml'); @@ -113,10 +113,10 @@ public function testIndexAndQuery() { \Drupal::service('config.installer')->installOptionalConfig($config_source); $index = Index::load($index_id); $index->save(); - $this->logger()->notice("Temporary index created."); + $this->logger->notice("Temporary index created."); $indexSingleItemQuery = $this->indexSingleItem($index->id()); - $this->logger()->notice('Solr Update index with one document Response: {code} {reason}', [ + $this->logger->notice('Solr Update index with one document Response: {code} {reason}', [ 'code' => $indexSingleItemQuery->getResponse()->getStatusCode(), 'reason' => $indexSingleItemQuery->getResponse()->getStatusMessage(), ]); @@ -125,7 +125,7 @@ public function testIndexAndQuery() { throw new \Exception('Cannot unable to index simple item. Have you created an index for the server?'); } - $this->logger()->notice("Querying Solr for the indexed item..."); + $this->logger->notice("Querying Solr for the indexed item..."); $result = $this->pantheonGuzzle->getQueryResult('select', [ 'query' => [ 'q' => 'index_id:' . $index->id(), @@ -134,10 +134,10 @@ public function testIndexAndQuery() { ], ]); if ($result['response']['numFound'] === 1) { - $this->logger()->notice('We got exactly 1 result ✅'); + $this->logger->notice('We got exactly 1 result ✅'); } else { - $this->logger()->notice('We did not get exactly 1 result ❌ (numFound = {numFound})', [ + $this->logger->notice('We did not get exactly 1 result ❌ (numFound = {numFound})', [ 'numFound' => $result['response']['numFound'], ]); } @@ -154,7 +154,7 @@ public function testIndexAndQuery() { } finally { if ($index) { - $this->logger()->notice('Removing content and index {index_id}', [ + $this->logger->notice('Removing content and index {index_id}', [ 'index_id' => $index->id(), ]); @@ -162,7 +162,7 @@ public function testIndexAndQuery() { $index->delete(); } } - $this->logger()->notice( + $this->logger->notice( "If there's an issue with Solr, it would have shown up here. You should be good to go!" ); } From c34a5d1468972b246c5cddf43d79dbbd54f48ead Mon Sep 17 00:00:00 2001 From: Sumit Madan <40235-sumitmadan@users.noreply.drupalcode.org> Date: Wed, 4 Sep 2024 10:00:48 +0530 Subject: [PATCH 3/4] Fixed the linting errors. --- search_api_pantheon.module | 1 - .../SearchApiPantheonSolrConfigFilesAlter.php | 9 ++++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/search_api_pantheon.module b/search_api_pantheon.module index 26bd8005..fca6766c 100644 --- a/search_api_pantheon.module +++ b/search_api_pantheon.module @@ -3,4 +3,3 @@ /** * @file */ - diff --git a/src/EventSubscriber/SearchApiPantheonSolrConfigFilesAlter.php b/src/EventSubscriber/SearchApiPantheonSolrConfigFilesAlter.php index 56d83ca6..167380bf 100644 --- a/src/EventSubscriber/SearchApiPantheonSolrConfigFilesAlter.php +++ b/src/EventSubscriber/SearchApiPantheonSolrConfigFilesAlter.php @@ -1,12 +1,11 @@ -getConfigFiles(); From b3c0cdbc58c6e393e26522b08062053f70d6e801 Mon Sep 17 00:00:00 2001 From: Sumit Madan <40235-sumitmadan@users.noreply.drupalcode.org> Date: Wed, 4 Sep 2024 21:50:08 +0530 Subject: [PATCH 4/4] Disabled the test for drupal 9. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1564b090..dfe4a723 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,7 +49,7 @@ jobs: build_test: strategy: matrix: - drupal-version: [ 9, 10 ] + drupal-version: [ 10 ] fail-fast: false runs-on: ubuntu-latest container: