function acquia_search_multi_subs_get_expected_search_cores in Acquia Search Multiple Indexes 7
Same name and namespace in other branches
- 8 acquia_search_multi_subs.common.inc \acquia_search_multi_subs_get_expected_search_cores()
Calculates eligible search core names based on environment information, in order of most likely (or preferred!) core names first.
The generated list of expected core names is done according to Acquia Search conventions, prioritized in this order: WXYZ-12345.[env].[acquia_db_name] WXYZ-12345.[env].[sitefolder] WXYZ-12345.[env].default WXYZ-12345_[sitename][env] WXYZ-12345.dev.[sitefolder] (only if $ah_site_environment isn't 'prod') WXYZ-12345_[sitename]dev (only if $ah_site_environment isn't 'prod') WXYZ-12345 (only if $ah_site_environment is 'prod')
NOTE that [sitefolder] is a stripped-down version of the sites/* folder, such that it is only alphanumeric and max. 16 chars in length. E.g. for sites/www.example.com, the expected corename for a dev environment could be WXYZ-12345.dev.wwwexamplecom
Parameters
string $acquia_identifier: Subscription ID. E.g. WXYZ-12345
string $ah_site_environment: String with the environment, from $_ENV[AH_SITE_ENVIRONMENT]. E.g. 'dev', 'test', 'prod'.
string $ah_site_name: From $_ENV[AH_SITE_NAME]
string $sites_foldername: Optional. The current site folder within [docroot]/sites/*.
string $ah_db_name: The Acquia Hosting current DB name.
Return value
array The eligible core_ids sorted by best match first.
See also
2 calls to acquia_search_multi_subs_get_expected_search_cores()
- acquia_search_multi_subs_apachesolr_init in lib/
Drupal/ Apachesolr/ acquia_search_multi_subs.apachesolr.inc - Initializes this module's Apache Solr Search Integration module support.
- acquia_search_multi_subs_searchapi_init in lib/
Drupal/ SearchApiSolr/ acquia_search_multi_subs.searchapisolr.inc - Initializes this module's Apache Solr Search Integration module support.
File
- ./
acquia_search_multi_subs.common.inc, line 42 - Helper functions used for the integration with either Solr module.
Code
function acquia_search_multi_subs_get_expected_search_cores($acquia_identifier, $ah_site_environment, $ah_site_name, $sites_foldername = 'default', $ah_db_name) {
// Build eligible environments array.
$ah_environments = array();
// If we have the proper environment, add it as the first option.
if ($ah_site_environment) {
$ah_environments[$ah_site_environment] = $ah_site_name;
}
// Add fallback options. For sites that lack the AH_* variables or are non-prod
// we will try to match .dev.[sitefolder] cores.
if ($ah_site_environment != 'prod') {
$ah_environments['dev'] = $ah_site_name;
}
$core_suffixes = array();
if (!empty($ah_db_name)) {
$core_suffixes[] = $ah_db_name;
}
// The possible core name suffixes are [current site folder name] and 'default'.
$core_suffixes = array_merge($core_suffixes, array_unique(array(
$sites_foldername,
'default',
)));
$expected_core_names = array();
foreach ($ah_environments as $site_environment => $site_name) {
foreach ($core_suffixes as $core_suffix) {
// Fix the $core_suffix: alphanumeric only
$core_suffix = preg_replace('@[^a-zA-Z0-9]+@', '', $core_suffix);
// We first add a 60-char-length indexname, which is the Solr index name limit.
$expected_core_names[] = substr($acquia_identifier . '.' . $site_environment . '.' . $core_suffix, 0, 60);
// Before 17-nov-2015 (see BZ-2778) the suffix limit was 16 chars; add this as well for backwards compatibility.
$expected_core_names[] = $acquia_identifier . '.' . $site_environment . '.' . substr($core_suffix, 0, 16);
// Add WXYZ-12345_[sitename][env] option.
if (!empty($site_name) && $sites_foldername == 'default') {
// Replace any weird characters that might appear in the sitegroup name or
// identifier.
$site_name = preg_replace('@[^a-zA-Z0-9_-]+@', '_', $site_name);
$expected_core_names[] = $acquia_identifier . '_' . $site_name;
}
}
// Add our failover options
$expected_core_names[] = $acquia_identifier . '.' . $site_environment . '.failover';
}
// Add suffix-less core if we're on prod now. If the sitename is empty,
// it means we are not on Acquia Hosting or something is wrong. Do not
// allow the prod index to be one of the available cores.
if ($ah_site_environment == 'prod' && $ah_site_name != '') {
$expected_core_names[] = $acquia_identifier;
}
return array_unique($expected_core_names);
}