Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Jeli 93][SITE-2457] Reload core during post schema #195

Merged
merged 15 commits into from
Nov 14, 2024
1 change: 1 addition & 0 deletions .envrc.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export PANTHEON_INDEX_PORT=8983
export PANTHEON_INDEX_PATH=/solr
export PANTHEON_INDEX_CORE=${SOLR_CORE}
export PANTHEON_INDEX_SCHEME=http
export PANTHEON_INDEX_RELOAD_PATH=${SOLR_RELOAD_PATH}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@
.idea
.DS_Store
docs/Badge.confluence

.envrc
245 changes: 131 additions & 114 deletions README.md

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ public function testFull(int $drupal_version = 9, string $site_name = NULL) {
// Test creating Solr index.
$this->testSolrIndexCreate($site_name, 'dev');

// Test running the reload
$this->testPantheonSolrReload($site_name, 'dev');
$this->testSolrReload($site_name, 'dev');

// Test select query.
$this->testSolrSelect($site_name, 'dev');

Expand Down Expand Up @@ -573,6 +577,7 @@ public function testModuleEnable(string $site_name, string $env = 'dev') {
'--yes',
'search_api_pantheon',
'search_api_pantheon_admin',
'search_api_solr_admin'
)
->run();
$this->taskExec(static::$TERMINUS_EXE)
Expand Down Expand Up @@ -802,9 +807,41 @@ public function testSolrIndexCreate(string $site_name, string $env = 'dev') {
if (!$result->wasSuccessful()) {
exit(1);
}
}

public function testPantheonSolrReload(string $site_name, string $env = 'dev') {
$result = $this->taskExec( static::$TERMINUS_EXE )
->args(
'drush',
"$site_name.$env",
'--',
'search-api-pantheon:reloadSchema',
)
->run();
if (!$result->wasSuccessful()) {
exit(1);
}
}

public function testSolrReload(string $site_name, string $env = 'dev') {
$result = $this->taskExec( static::$TERMINUS_EXE )
->args(
'drush',
"$site_name.$env",
'--',
'search-api-solr:reload',
'pantheon_solr8'
)
->run();
if (!$result->wasSuccessful()) {
exit(1);
}
}





/**
* Use search-api-pantheon:select command to ensure both Drupal index and the actual Solr index have the same amount of items.
*
Expand Down
5 changes: 5 additions & 0 deletions drush.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ services:
arguments: [ "@logger.factory", "@search_api_pantheon.pantheon_guzzle", "@search_api_pantheon.endpoint", "@search_api_pantheon.solarium_client" ]
tags:
- { name: drush.command }
search_api_pantheon.drush_reload:
class: \Drupal\search_api_pantheon\Commands\Reload
arguments: [ "@logger.factory", "@search_api_pantheon.pantheon_guzzle", "@search_api_pantheon.schema_poster" ]
tags:
- { name: drush.command }
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<server name="PANTHEON_INDEX_PATH" value="${PANTHEON_INDEX_PATH}" />
<server name="PANTHEON_INDEX_CORE" value="${PANTHEON_INDEX_CORE}" />
<server name="PANTHEON_INDEX_SCHEMA" value="${PANTHEON_INDEX_SCHEMA}" />
<server name="PANTHEON_INDEX_RELOAD_PATH" value="${PANTHEON_INDEX_RELOAD_PATH}" />
</php>
<testsuites>
<testsuite name="unit">
Expand Down
13 changes: 13 additions & 0 deletions search_api_pantheon.module
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,16 @@
/**
* @file
*/

function search_api_pantheon_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'solr_reload_core_form') {
$form['#submit'][] = 'search_api_pantheon_form_submit';
}
}

function search_api_pantheon_form_submit($form, &$form_state) {
$rl = \Drupal::service("search_api_pantheon.reload");
$rl->reloadServer() ?
drupal_set_message(t('Core reloaded successfully.')) :
drupal_set_message(t('Core reload failed.'), 'error');
}
3 changes: 3 additions & 0 deletions search_api_pantheon.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ services:
class: Drupal\search_api_pantheon\EventSubscriber\SearchApiPantheonSolrConfigFilesAlter
tags:
- { name: event_subscriber }
search_api_pantheon.reload:
class: Drupal\search_api_pantheon\Services\Reload
arguments: ['@logger.factory', '@search_api_pantheon.pantheon_guzzle']
3 changes: 3 additions & 0 deletions src/Commands/Diagnose.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ public function diagnose() {
$this->logger->notice('Index PATH Value: {var}', [
'var' => $this->endpoint->getPath(),
]);
$this->logger->notice('Index RELOAD_PATH Value: {var}', [
'var' => $this->endpoint->getReloadPath(),
]);
$this->logger->notice('Testing bare Connection...');
$response = $this->pingSolrHost();
$this->logger->notice('Ping Received Response? {var}', [
Expand Down
68 changes: 68 additions & 0 deletions src/Commands/Reload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace Drupal\search_api_pantheon\Commands;

use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\Logger\LoggerChannelTrait;
use Drupal\search_api_pantheon\Services\PantheonGuzzle;
use Drupal\search_api_pantheon\Services\SchemaPoster;
use Drush\Commands\DrushCommands;

/**
* Drush Search Api Pantheon Schema Commands.
*/
class Reload extends DrushCommands {
use LoggerChannelTrait;

/**
* Configured pantheon-solr-specific guzzle client.
*
* @var \Drupal\search_api_pantheon\Services\PantheonGuzzle
*/
private PantheonGuzzle $pantheonGuzzle;

/**
* Configured pantheon-solr-specific schema poster class.
*
* @var \Drupal\search_api_pantheon\Services\SchemaPoster
*/
private SchemaPoster $schemaPoster;

/**
* Class constructor.
*
* @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $loggerChannelFactory
* Injected by container.
* @param \Drupal\search_api_pantheon\Services\PantheonGuzzle $pantheonGuzzle
* Injected by container.
* @param \Drupal\search_api_pantheon\Services\SchemaPoster $schemaPoster
* Injected by Container.
*/
public function __construct(
LoggerChannelFactoryInterface $loggerChannelFactory,
PantheonGuzzle $pantheonGuzzle,
SchemaPoster $schemaPoster
) {
$this->logger = $loggerChannelFactory->get('SearchAPIPantheon Drush');
$this->pantheonGuzzle = $pantheonGuzzle;
$this->schemaPoster = $schemaPoster;
}

/**
* Search_api_pantheon:reloadSchema.
*
* @usage search-api-pantheon:reloadSchema
* Reload the latest schema
*
* @command search-api-pantheon:reloadSchema
*/
public function reloadSchema() {
try {
$this->schemaPoster->reloadServer();
}
catch (\Exception $e) {
$this->logger->error((string) $e);
}
}

}
Loading
Loading