You are here

public function SearchApiAcquiaApi::getDatabaseRole in Acquia Search for Search API 7.2

Returns the name of the Acquia "DB Role".

Acquia "DB Role" is in use when running inside an Acquia environment.

Parameters

array $databases: List of available databases.

string $ah_db_name: Current database name.

Return value

string Database role.

1 call to SearchApiAcquiaApi::getDatabaseRole()
SearchApiAcquiaApi::getPreferredCoreService in includes/v3/SearchApiAcquiaApi.php
Returns preferred search index service.

File

includes/v3/SearchApiAcquiaApi.php, line 204

Class

SearchApiAcquiaApi
Class SearchApiAcquiaApi.

Code

public function getDatabaseRole(array $databases, string $ah_db_name) {

  // Ignore the "default" connection, because even though it may match the
  // currently-used DB connection, this entry always exists and its key
  // won't match the AH "DB Role".
  $filter = function ($role) {
    return $role !== 'default';
  };
  $databases = array_filter($databases, $filter, ARRAY_FILTER_USE_KEY);

  // Scan all the available Databases and look for the currently-used DB name.
  foreach ($databases as $database_role => $databases_list) {
    if ($databases_list['default']['database'] == $ah_db_name) {
      $database_role = $this
        ->sanitizeDatabaseRoleName($database_role);
      return $database_role;
    }
  }
  return '';
}