diff --git a/search_api.theme.inc b/search_api.theme.inc index 6924b00..1bc2378 100644 --- a/search_api.theme.inc +++ b/search_api.theme.inc @@ -137,6 +137,15 @@ function theme_search_api_server($variables) { $rows[] = Utility::deepCopy($row); $class = ''; + // Add backend availability information. + $info = $server->isAvailable() ? t('Server is available.') : t('Server is not available.'); + $class = $server->isAvailable() ? 'ok' : 'error'; + + // Append the row and reset variables. + $label = t('Backend availability'); + $rows[] = Utility::deepCopy($row); + $class = ''; + // Build the indexes links container. $indexes = array( '#theme' => 'links', diff --git a/src/Backend/BackendPluginBase.php b/src/Backend/BackendPluginBase.php index ecb1662..fab8ed8 100644 --- a/src/Backend/BackendPluginBase.php +++ b/src/Backend/BackendPluginBase.php @@ -94,6 +94,13 @@ abstract class BackendPluginBase extends ConfigurablePluginBase implements Backe /** * {@inheritdoc} */ + public function isAvailable() { + return TRUE; + } + + /** + * {@inheritdoc} + */ public function supportsFeature($feature) { return FALSE; } diff --git a/src/Backend/BackendSpecificInterface.php b/src/Backend/BackendSpecificInterface.php index 394ebfd..a77cef6 100644 --- a/src/Backend/BackendSpecificInterface.php +++ b/src/Backend/BackendSpecificInterface.php @@ -37,6 +37,20 @@ interface BackendSpecificInterface { public function viewSettings(); /** + * Returns a boolean with the availability of the backend. + * + * This can implement a specific call to test if the backend is available for + * reading. For SOLR or elasticsearch this would be a "ping" to the server to + * test if it's online. If this is a db-backend that is running on a seperate + * server, this can also be a ping. When it's a db-backend that runs in the + * same database as the drupal installation; just returning TRUE is enough. + * + * @return bool + * The availability of the backend. + */ + public function isAvailable(); + + /** * Determines whether the backend supports a given feature. * * Features are optional extensions to Search API functionality and usually diff --git a/src/Entity/Server.php b/src/Entity/Server.php index fac5f8f..66cfaa7 100644 --- a/src/Entity/Server.php +++ b/src/Entity/Server.php @@ -174,6 +174,13 @@ class Server extends ConfigEntityBase implements ServerInterface { /** * {@inheritdoc} */ + public function isAvailable() { + return $this->hasValidBackend() ? $this->getBackend()->isAvailable() : FALSE; + } + + /** + * {@inheritdoc} + */ public function supportsFeature($feature) { return $this->hasValidBackend() ? $this->getBackend()->supportsFeature($feature) : FALSE; } diff --git a/src/Tests/IntegrationTest.php b/src/Tests/IntegrationTest.php index dc46b93..5afcd42 100644 --- a/src/Tests/IntegrationTest.php +++ b/src/Tests/IntegrationTest.php @@ -128,6 +128,11 @@ class IntegrationTest extends WebTestBase { $this->assertText($this->t('The server was successfully saved.')); $this->assertUrl('admin/config/search/search-api/server/' . $this->serverId, array(), 'Correct redirect to server page.'); + + // Test that the server view page has a list of useful server information. + $this->assertText($this->t('Backend class')); + $this->assertText($this->t('Backend availability')); + $this->assertText($this->t('Server is available.')); } /**