You are here

function elasticsearch_connector_site_hash in Elasticsearch Connector 8

Same name and namespace in other branches
  1. 8.7 elasticsearch_connector.module \elasticsearch_connector_site_hash()
  2. 8.2 elasticsearch_connector.module \elasticsearch_connector_site_hash()
  3. 8.5 elasticsearch_connector.module \elasticsearch_connector_site_hash()
  4. 8.6 elasticsearch_connector.module \elasticsearch_connector_site_hash()

Returns a unique hash for the current site.

This is used to identify Solr documents from different sites within a single Solr server.

Return value

string A unique site hash, containing only alphanumeric characters.

File

./elasticsearch_connector.module, line 537
Provides hook implementations and functions accessible from other modules.

Code

function elasticsearch_connector_site_hash() {

  // Copied from apachesolr_site_hash().
  if (!($hash = \Drupal::config('elasticsearch.settings')
    ->get('site_hash'))) {
    global $base_url;
    $hash = substr(base_convert(sha1(uniqid($base_url, TRUE)), 16, 36), 0, 6);
    \Drupal::config('elasticsearch.settings')
      ->set('site_hash', $hash)
      ->save();
  }
  return $hash;
}