Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ public function discover(): null|string|bool|array {
return $v;
}

// Try to discover from settings.acquia.php.
// @deprecated Discovery from hardcoded path in settings.acquia.php. The
// new settings.acquia.php uses AH_SITE_GROUP environment variable instead
// of a hardcoded project name. Kept for backward compatibility with older
// installations.
$acquia_settings_file = $this->dstDir . sprintf('/%s/sites/default/includes/providers/settings.acquia.php', $this->webroot);
if (file_exists($acquia_settings_file)) {
$content = file_get_contents($acquia_settings_file);
Expand Down Expand Up @@ -125,6 +128,10 @@ public function process(): void {
$w = $this->webroot;

Env::writeValueDotenv('VORTEX_ACQUIA_APP_NAME', $v, $t . '/.env');
// @deprecated The settings.acquia.php no longer uses hardcoded project
// names - it uses AH_SITE_GROUP environment variable instead. This
// replacement is kept for backward compatibility with older installations
// that may still use the hardcoded path pattern.
File::replaceContentInFile($t . '/' . $w . '/sites/default/includes/providers/settings.acquia.php', 'your_site', $v);

Env::writeValueDotenv('LAGOON_PROJECT', $v, $t . '/.env');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@
$config['acquia_hosting_settings_autoconnect'] = FALSE;

// Include Acquia environment settings.
if (file_exists('/var/www/site-php/star_wars/star_wars-settings.inc')) {
// @codeCoverageIgnoreStart
// @phpstan-ignore-next-line
require '/var/www/site-php/star_wars/star_wars-settings.inc';
// @codeCoverageIgnoreEnd
// The path is built dynamically from the AH_SITE_GROUP environment variable
// provided by Acquia Cloud.
$ah_site_group = getenv('AH_SITE_GROUP');
// @codeCoverageIgnoreStart
if (!empty($ah_site_group)) {
$ah_settings_file = sprintf('/var/www/site-php/%s/%s-settings.inc', $ah_site_group, $ah_site_group);
if (!file_exists($ah_settings_file)) {
throw new \RuntimeException(sprintf('Acquia settings file "%s" not found. Check Acquia Cloud environment configuration.', $ah_settings_file));
}
require $ah_settings_file;
}

// @codeCoverageIgnoreEnd
// Set the config sync directory to a `config_vcs_directory`, but still
// allow overriding it with the DRUPAL_CONFIG_PATH environment variable.
if (!empty($settings['config_vcs_directory'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@
$config['acquia_hosting_settings_autoconnect'] = FALSE;

// Include Acquia environment settings.
if (file_exists('/var/www/site-php/my_custom_acquia-project/my_custom_acquia-project-settings.inc')) {
// @codeCoverageIgnoreStart
// @phpstan-ignore-next-line
require '/var/www/site-php/my_custom_acquia-project/my_custom_acquia-project-settings.inc';
// @codeCoverageIgnoreEnd
// The path is built dynamically from the AH_SITE_GROUP environment variable
// provided by Acquia Cloud.
$ah_site_group = getenv('AH_SITE_GROUP');
// @codeCoverageIgnoreStart
if (!empty($ah_site_group)) {
$ah_settings_file = sprintf('/var/www/site-php/%s/%s-settings.inc', $ah_site_group, $ah_site_group);
if (!file_exists($ah_settings_file)) {
throw new \RuntimeException(sprintf('Acquia settings file "%s" not found. Check Acquia Cloud environment configuration.', $ah_settings_file));
}
require $ah_settings_file;
}

// @codeCoverageIgnoreEnd
// Set the config sync directory to a `config_vcs_directory`, but still
// allow overriding it with the DRUPAL_CONFIG_PATH environment variable.
if (!empty($settings['config_vcs_directory'])) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public static function dataProviderHandlerProcess(): array {
static::cw(function (FunctionalTestCase $test): void {
$test->assertSutContains([
'VORTEX_ACQUIA_APP_NAME=my_custom_acquia-project',
'/site-php\/my_custom_acquia-project\/my_custom_acquia-project-settings\.inc/',
]);
}),
],
Expand Down
17 changes: 11 additions & 6 deletions web/sites/default/includes/providers/settings.acquia.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@
$config['acquia_hosting_settings_autoconnect'] = FALSE;

// Include Acquia environment settings.
if (file_exists('/var/www/site-php/your_site/your_site-settings.inc')) {
// @codeCoverageIgnoreStart
// @phpstan-ignore-next-line
require '/var/www/site-php/your_site/your_site-settings.inc';
// @codeCoverageIgnoreEnd
// The path is built dynamically from the AH_SITE_GROUP environment variable
// provided by Acquia Cloud.
$ah_site_group = getenv('AH_SITE_GROUP');
// @codeCoverageIgnoreStart
if (!empty($ah_site_group)) {
$ah_settings_file = sprintf('/var/www/site-php/%s/%s-settings.inc', $ah_site_group, $ah_site_group);
if (!file_exists($ah_settings_file)) {
throw new \RuntimeException(sprintf('Acquia settings file "%s" not found. Check Acquia Cloud environment configuration.', $ah_settings_file));
}
require $ah_settings_file;
}
Comment on lines 22 to 32
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Fail fast when AH_SITE_GROUP is missing.

When AH_SITE_ENVIRONMENT is set but AH_SITE_GROUP is empty, this silently skips the include and doesn’t signal misconfiguration. The objective calls for a hard failure on misconfigured Acquia env vars—please throw if AH_SITE_GROUP is not set.

✅ Suggested fix
   // `@codeCoverageIgnoreStart`
   $ah_site_group = getenv('AH_SITE_GROUP');
-  if (!empty($ah_site_group)) {
-    $ah_settings_file = sprintf('/var/www/site-php/%s/%s-settings.inc', $ah_site_group, $ah_site_group);
-    if (!file_exists($ah_settings_file)) {
-      throw new \RuntimeException(sprintf('Acquia settings file "%s" not found. Check Acquia Cloud environment configuration.', $ah_settings_file));
-    }
-    // `@phpstan-ignore-next-line`
-    require $ah_settings_file;
-  }
+  if (empty($ah_site_group)) {
+    throw new \RuntimeException('AH_SITE_GROUP is not set. Check Acquia Cloud environment configuration.');
+  }
+  $ah_settings_file = sprintf('/var/www/site-php/%s/%s-settings.inc', $ah_site_group, $ah_site_group);
+  if (!file_exists($ah_settings_file)) {
+    throw new \RuntimeException(sprintf('Acquia settings file "%s" not found. Check Acquia Cloud environment configuration.', $ah_settings_file));
+  }
+  // `@phpstan-ignore-next-line`
+  require $ah_settings_file;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// The path is built dynamically from the AH_SITE_GROUP environment variable
// provided by Acquia Cloud.
// @codeCoverageIgnoreStart
$ah_site_group = getenv('AH_SITE_GROUP');
if (!empty($ah_site_group)) {
$ah_settings_file = sprintf('/var/www/site-php/%s/%s-settings.inc', $ah_site_group, $ah_site_group);
if (!file_exists($ah_settings_file)) {
throw new \RuntimeException(sprintf('Acquia settings file "%s" not found. Check Acquia Cloud environment configuration.', $ah_settings_file));
}
// @phpstan-ignore-next-line
require '/var/www/site-php/your_site/your_site-settings.inc';
// @codeCoverageIgnoreEnd
require $ah_settings_file;
}
// The path is built dynamically from the AH_SITE_GROUP environment variable
// provided by Acquia Cloud.
// `@codeCoverageIgnoreStart`
$ah_site_group = getenv('AH_SITE_GROUP');
if (empty($ah_site_group)) {
throw new \RuntimeException('AH_SITE_GROUP is not set. Check Acquia Cloud environment configuration.');
}
$ah_settings_file = sprintf('/var/www/site-php/%s/%s-settings.inc', $ah_site_group, $ah_site_group);
if (!file_exists($ah_settings_file)) {
throw new \RuntimeException(sprintf('Acquia settings file "%s" not found. Check Acquia Cloud environment configuration.', $ah_settings_file));
}
// `@phpstan-ignore-next-line`
require $ah_settings_file;
🤖 Prompt for AI Agents
In `@web/sites/default/includes/providers/settings.acquia.php` around lines 22 -
33, The code currently reads $ah_site_group from getenv('AH_SITE_GROUP') and
silently skips requiring the Acquia settings file when it's empty; update the
logic so that if getenv('AH_SITE_ENVIRONMENT') is non-empty but $ah_site_group
is empty, you throw a RuntimeException indicating missing AH_SITE_GROUP (before
attempting to build $ah_settings_file or require it). In practice, add a check
referencing getenv('AH_SITE_ENVIRONMENT') and $ah_site_group and throw a
descriptive RuntimeException when AH_SITE_ENVIRONMENT is present but
AH_SITE_GROUP is not, keeping the existing $ah_settings_file/file_exists/require
flow unchanged otherwise.


// @codeCoverageIgnoreEnd
// Set the config sync directory to a `config_vcs_directory`, but still
// allow overriding it with the DRUPAL_CONFIG_PATH environment variable.
if (!empty($settings['config_vcs_directory'])) {
Expand Down