diff --git a/web/modules/custom/joinup_search/joinup_search.install b/web/modules/custom/joinup_search/joinup_search.install new file mode 100644 index 0000000000..9be6bc178e --- /dev/null +++ b/web/modules/custom/joinup_search/joinup_search.install @@ -0,0 +1,65 @@ +get('backend_config.connector_config'); + $uri = (string) (new Uri()) + ->withScheme($endpoint['scheme']) + ->withHost($endpoint['host']) + ->withPort($endpoint['port']) + ->withPath(rtrim($endpoint['path'], '/') . "/{$endpoint['core']}/select") + ->withQuery(http_build_query([ + 'fq' => "-hash:{$site_hash}", + 'q' => '*:*', + 'wt' => 'json', + ])); + + try { + $response = $http_client->get($uri); + } + catch (\Throwable $exception) { + // Ignore error, it's already covered by search_api_solr module. + // @see search_api_solr_requirements() + continue; + } + + $num_found = Json::decode($response->getBody()->getContents())['response']['numFound']; + if ($num_found) { + $requirements["solr_data:{$index_id}"] = [ + 'severity' => REQUIREMENT_ERROR, + 'title' => t('Solr index: %index', ['%index' => $index_id]), + 'value' => t('Found @count entries with invalid site hash', [ + '@count' => $num_found, + ]), + 'description' => t('The valid site hash is %hash. Retrieve the invalid entries with this query.', [ + '%hash' => $site_hash, + ':uri' => $uri, + ]), + ]; + } + } + + return $requirements; +}