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] 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!" ); }