private function SearchApiSolrAcquiaMultiSubsBackend::getExpectedSearchCores in Acquia Search Multiple Indexes 8
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].[databasename] WXYZ-12345.[env].[sitegroup] WXYZ-12345.[env].[sitefolder] WXYZ-12345.[env].default WXYZ-12345_[sitename][env] WXYZ-12345.dev.[databasename] (only if $ah_site_environment isn't 'prod') 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: The name of the site (includes some form of environment info, from $_ENV['AH_SITE_NAME'].
string $ah_site_group: From $_ENV['AH_SITE_GROUP'].
string $sites_foldername: Optional. The current site folder within [docroot]/sites/*. @see conf_path()
Return value
array The eligible core_ids sorted by best match first.
1 call to SearchApiSolrAcquiaMultiSubsBackend::getExpectedSearchCores()
- SearchApiSolrAcquiaMultiSubsBackend::getEnvironmentCore in src/
Plugin/ search_api/ backend/ SearchApiSolrAcquiaMultiSubsBackend.php
File
- src/
Plugin/ search_api/ backend/ SearchApiSolrAcquiaMultiSubsBackend.php, line 399
Class
- SearchApiSolrAcquiaMultiSubsBackend
- Plugin annotation @SearchApiBackend( id = "search_api_solr_acquia_multi_subs", label = @Translation("Acquia Solr Multi Sub"), description = @Translation("Index items using a specific Acquia Apache Solr search server.") )
Namespace
Drupal\acquia_search_multi_subs\Plugin\search_api\backendCode
private function getExpectedSearchCores($acquia_identifier, $ah_site_environment, $ah_site_name, $ah_site_group, $sites_foldername = 'default', $ah_db_name) {
// Build eligible environments array.
$ah_environments = array();
$expected_core_names = 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.[sitegroup] cores.
if ($ah_site_environment != 'prod' && $ah_site_environment != '01live') {
$ah_environments['dev'] = $ah_site_group;
// Build the CORE.env.site_group default.
$expected_core_names[] = $acquia_identifier . '.' . $ah_site_environment . '.' . $ah_site_group;
}
foreach ($ah_environments as $site_environment => $site_name) {
// The possible core name suffixes are [database name], [current site folder name] and 'default'.
$core_suffixes = array_unique(array(
$ah_db_name,
$sites_foldername,
'default',
$ah_site_name,
));
foreach ($core_suffixes as $core_suffix) {
if ($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);
}