Skip to content

Commit

Permalink
Used logger object from constructure instead of its parent class.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sumit Madan committed Sep 4, 2024
1 parent 2531fa2 commit 4eb4feb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
42 changes: 21 additions & 21 deletions src/Commands/Diagnose.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ?? '',
]);

Expand All @@ -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' => [
Expand All @@ -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) {
Expand All @@ -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!"
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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);
}

}
20 changes: 10 additions & 10 deletions src/Commands/TestIndexAndQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,18 @@ 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) {
throw new \Exception('Cannot contact solr server.');
}

// 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');

Expand All @@ -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(),
]);
Expand All @@ -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(),
Expand All @@ -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'],
]);
}
Expand All @@ -154,15 +154,15 @@ 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(),
]);

$this->deleteSingleItem('1-' . $index->id());
$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!"
);
}
Expand Down

0 comments on commit 4eb4feb

Please sign in to comment.