Skip to content

Commit

Permalink
Merge pull request #54 from willtp87/8.x.ISLANDORA-2419
Browse files Browse the repository at this point in the history
  • Loading branch information
JojoVes authored May 13, 2019
2 parents 2e22cd2 + ddae37f commit ecc221e
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 11 deletions.
1 change: 1 addition & 0 deletions config/install/islandora_solr.settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ islandora_solr_num_of_results_advanced: []
islandora_solr_explore_config: []
islandora_solr_compound_relationship_field: 'RELS_EXT_isConstituentOf_uri_ms'
islandora_solr_compound_sequence_pattern: 'RELS_EXT_isSequenceNumberOf%PID%_literal_ms'
islandora_solr_technical_difficulties_message: 'We are experiencing technical difficulties at this time and are working to fix the problem. Please try back later.'
2 changes: 2 additions & 0 deletions config/schema/islandora_solr.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ islandora_solr.settings:
type: boolean
islandora_solr_breadcrumbs_parent_fields:
type: string
islandora_solr_technical_difficulties_message:
type: string
islandora_solr_primary_display_table:
type: mapping
mapping:
Expand Down
11 changes: 2 additions & 9 deletions includes/breadcrumbs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* Breadcrumb functions.
*/

use Drupal\Component\Utility\Html;
use Drupal\Core\Link;
use Drupal\Core\Url;

Expand Down Expand Up @@ -107,14 +106,8 @@ function islandora_solr_get_breadcrumb_parent($pid) {
$solr_build->solrParams = islandora_solr_remove_base_filters($solr_build->solrParams);
$solr_build->solrParams = islandora_solr_clean_compound_filters($solr_build->solrParams);

try {
$solr_build->executeQuery(FALSE);
$results = (array) $solr_build->islandoraSolrResult['response']['objects'];
}
catch (Exception $e) {
$results = [];
drupal_set_message(Html::escape(t('Error searching Solr index')) . ' ' . $e->getMessage(), 'error', FALSE);
}
$solr_build->executeQuery(FALSE);
$results = (array) $solr_build->islandoraSolrResult['response']['objects'];

$find_solr_value = function ($o, $field) {
if (isset($o[$field])) {
Expand Down
24 changes: 24 additions & 0 deletions islandora_solr.module
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,27 @@ function islandora_solr_preprocess_islandora_objects_subset(array &$variables) {
$variables['pager'] = \Drupal::service("renderer")->render($variables['pager']);
}
}

/**
* Make nice text for screen and log the exception to watchdog.
*
* @param \Exception $e
* The exception.
*/
function islandora_solr_technical_difficulties(Exception $e) {
// Only report the error once per screen.
$islandora_solr_error_reported = &drupal_static(__FUNCTION__, FALSE);

if ($islandora_solr_error_reported !== TRUE) {
drupal_set_message(t("@message", [
'@message' => \Drupal::config('islandora_solr.settings')->get('islandora_solr_technical_difficulties_message'),
]), 'warning');
\Drupal::logger('islandora_solr')->error(t("Received exception @code: @message\nLine: @line in file: @file", [
'@code' => $e->getCode(),
'@message' => $e->getMessage(),
'@file' => $e->getFile(),
'@line' => $e->getLine(),
]));
$islandora_solr_error_reported = TRUE;
}
}
11 changes: 11 additions & 0 deletions src/Form/AdminIndexSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#description' => $this->t('If checked, deleting objects will also force their removal from the Solr index. <br/><strong>Note:</strong> When active, UI consistency will be increased on any pages using Solr queries for display. This setting is not appropriate for every installation (e.g., on sites with a large volume of Solr commits that hit execution limits, or where the Solr index is not directly writable from Drupal).'),
'#default_value' => $this->config('islandora_solr.settings')->get('islandora_solr_force_update_index_after_object_purge'),
];

$form['solr_ajax_wrapper']['islandora_solr_technical_difficulties_message'] = [
'#type' => 'textfield',
'#title' => $this->t('Solr unavailable message.'),
'#description' => $this->t('When Solr throws an Exception this message is displayed to the users.'),
'#size' => 150,
'#weight' => 10,
'#default_value' => $this->config('islandora_solr.settings')->get('islandora_solr_technical_difficulties_message'),
];

return parent::buildForm($form, $form_state);
}

Expand Down Expand Up @@ -165,6 +175,7 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
$this->config('islandora_solr.settings')
->set('islandora_solr_request_handler', $form_state->getValue('islandora_solr_request_handler'))
->set('islandora_solr_force_update_index_after_object_purge', $form_state->getValue('islandora_solr_force_update_index_after_object_purge'))
->set('islandora_solr_technical_difficulties_message', $form_state->getValue('islandora_solr_technical_difficulties_message'))
->save();
// Force renewal of the cached value, as the request handler might have
// changed.
Expand Down
2 changes: 1 addition & 1 deletion src/IslandoraSolrQueryProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public function executeQuery($alter_results = TRUE, $use_post = FALSE) {
$results = $solr->search($solr_query, $this->solrStart, $this->solrLimit, $this->solrParams, $method);
}
catch (Exception $e) {
drupal_set_message(Html::escape(t('Error searching Solr index')) . ' ' . $e->getMessage(), 'error');
islandora_solr_technical_difficulties($e);
}

$object_results = [];
Expand Down
2 changes: 1 addition & 1 deletion src/SolrPhpClient/Apache/Solr/Apache_Solr_Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ protected function _sendRawGet($url, $timeout = FALSE)


//$http_response_header is set by file_get_contents
$response = new Apache_Solr_Response(@file_get_contents($url, false, $this->_getContext), $http_response_header, $this->_createDocuments, $this->_collapseSingleValueArrays);
$response = new Apache_Solr_Response(@file_get_contents($url, false, $this->_getContext), @$http_response_header, $this->_createDocuments, $this->_collapseSingleValueArrays);

if ($response->getHttpStatus() != 200)
{
Expand Down

0 comments on commit ecc221e

Please sign in to comment.