diff --git a/src/PreferredSearchCoreService.php b/src/PreferredSearchCoreService.php index 2c7fd3b..84f213a 100644 --- a/src/PreferredSearchCoreService.php +++ b/src/PreferredSearchCoreService.php @@ -248,6 +248,9 @@ class PreferredSearchCoreService { $possible_core_ids[] = $this->acquiaIdentifier . '.' . $ah_env . '.' . $sites_foldername; + // Add eligible fallback core names for Acquia Site Factory sites. + $this->addACSFFallbackCores($possible_core_ids, $ah_env, $sites_foldername); + } // For production-only, we allow auto-connecting to the suffix-less core @@ -263,4 +266,29 @@ class PreferredSearchCoreService { } + /** + * Add list of eligible fallback cores when site is within Site Factory. + * + * @param $possible_core_ids + * @param $ah_env + * @param $sites_foldername + * + * For Site Factory sites, these core names are acceptable: + * [id].[env].default + * [id] (only if environment is 01live) + */ + protected function addACSFFallbackCores(&$possible_core_ids, $ah_env, $sites_foldername) { + $realm = !empty($_ENV['AH_REALM']) ? $_ENV['AH_REALM'] : ''; + if ($realm == 'enterprise-g1' || preg_match('/gardens$/', $realm)) { + // No need to add 'default' again if we already set it. + if ($sites_foldername != 'default') { + $possible_core_ids[] = $this->acquiaIdentifier . '.' . $ah_env . '.default'; + } + // For environments that match [num]live (01live, 02live, etc.) + if (preg_match('/^[\d]+live$/', $ah_env)) { + $possible_core_ids[] = $this->acquiaIdentifier; + } + } + } + } diff --git a/tests/modules/acquia_search_test/src/EventSubscriber/AcquiaSearchTestSubscriber.php b/tests/modules/acquia_search_test/src/EventSubscriber/AcquiaSearchTestSubscriber.php index 18d042e..548194c 100644 --- a/tests/modules/acquia_search_test/src/EventSubscriber/AcquiaSearchTestSubscriber.php +++ b/tests/modules/acquia_search_test/src/EventSubscriber/AcquiaSearchTestSubscriber.php @@ -24,6 +24,7 @@ class AcquiaSearchTestSubscriber implements EventSubscriberInterface { 'AH_SITE_NAME', 'AH_SITE_GROUP', 'AH_PRODUCTION', + 'AH_REALM', ]; foreach ($allowed_keys as $key) { $value = $event->getRequest()->query->get($key); diff --git a/tests/src/Functional/AcquiaConnectorSearchOverrideTest.php b/tests/src/Functional/AcquiaConnectorSearchOverrideTest.php index 2547761..d283ae1 100644 --- a/tests/src/Functional/AcquiaConnectorSearchOverrideTest.php +++ b/tests/src/Functional/AcquiaConnectorSearchOverrideTest.php @@ -108,6 +108,8 @@ class AcquiaConnectorSearchOverrideTest extends BrowserTestBase { $this->caseAcquiaHostingEnvironmentDetectedNoAvailableCores(); $this->caseAcquiaHostingProdEnvironmentDetectedWithoutProdFlag(); $this->caseAcquiaHostingProdEnvironmentDetectedWithProdFlag(); + $this->caseACSFProdEnvironmentDetectedWithProdFlag(); + $this->caseACSFEnvironmentDetectedNoAvailableCores(); } @@ -184,6 +186,7 @@ class AcquiaConnectorSearchOverrideTest extends BrowserTestBase { $this->assertText('The following Acquia Search Solr index IDs would have worked for your current environment'); $this->assertText($this->id . '.test.' . $this->getDbName()); $this->assertText($this->id . '.test.' . $this->getSiteFolderName()); + $this->assertNoText($this->id . '.test.default'); //phpcs:disable //$delete_btn = $this->xpath('//input[@value="Delete all indexed data on this server"]'); @@ -218,6 +221,7 @@ class AcquiaConnectorSearchOverrideTest extends BrowserTestBase { $this->assertText('The following Acquia Search Solr index IDs would have worked for your current environment'); $this->assertText($this->id . '.prod.' . $this->getDbName()); $this->assertText($this->id . '.prod.' . $this->getSiteFolderName()); + $this->assertNoText($this->id . '.prod.default'); //phpcs:disable //$delete_btn = $this->xpath('//input[@value="Delete all indexed data on this server"]'); @@ -262,6 +266,40 @@ class AcquiaConnectorSearchOverrideTest extends BrowserTestBase { } + /** + * Acquia ACSF test environment. According to the mock, no cores + * available for the Test environment so it is read only. Also, an eligible + * corename will be [id].[env].default + */ + public function caseACSFEnvironmentDetectedNoAvailableCores() { + + $overrides = [ + 'env-overrides' => 1, + 'AH_SITE_ENVIRONMENT' => '99test', + 'AH_SITE_NAME' => 'testsite199test', + 'AH_SITE_GROUP' => 'testsite1', + 'AH_REALM' => 'enterprise-g1', + ]; + + $this->drupalGet('/admin/config/search/search-api/server/' . $this->server, ['query' => $overrides ]); + + $this->assertText('automatically enforced read-only mode on this connection.'); + + $this->assertText('The following Acquia Search Solr index IDs would have worked for your current environment'); + $this->assertText($this->id . '.99test.' . $this->_getDbName()); + $this->assertText($this->id . '.99test.' . $this->_getSiteFolderName()); + $this->assertText($this->id . '.99test.default'); + + $delete_btn = $this->xpath('//input[@value="Delete all indexed data on this server"]'); + $this->assertEqual((string) $delete_btn[0]['disabled'], 'disabled'); + + $this->drupalGet('/admin/config/search/search-api/index/' . $this->index, ['query' => $overrides ]); + + // On index edit page, check the read-only mode state. + $this->assertText('automatically enforced read-only mode on this connection.'); + + } + /** * Connect to the Acquia Subscription. */