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
9 changes: 7 additions & 2 deletions .vortex/installer/src/Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected function configure(): void {

$this->addOption(static::OPTION_ROOT, NULL, InputOption::VALUE_REQUIRED, 'Path to the root for file path resolution. If not specified, current directory is used.');
$this->addOption(static::OPTION_NO_INTERACTION, 'n', InputOption::VALUE_NONE, 'Do not ask any interactive question.');
$this->addOption(static::OPTION_CONFIG, 'c', InputOption::VALUE_REQUIRED, 'A JSON string with options.');
$this->addOption(static::OPTION_CONFIG, 'c', InputOption::VALUE_REQUIRED, 'A JSON string with options or a path to a JSON file.');
$this->addOption(static::OPTION_URI, 'l', InputOption::VALUE_REQUIRED, 'Remote or local repository URI with an optional git ref set after @.');
$this->addOption(static::OPTION_NO_CLEANUP, NULL, InputOption::VALUE_NONE, 'Do not remove installer after successful installation.');
}
Expand Down Expand Up @@ -207,7 +207,12 @@ protected function checkRequirements(): void {
* Array of CLI options.
*/
protected function resolveOptions(array $arguments, array $options): void {
$config = isset($options[static::OPTION_CONFIG]) && is_scalar($options[static::OPTION_CONFIG]) ? strval($options[static::OPTION_CONFIG]) : '{}';
$config = '{}';
if (isset($options[static::OPTION_CONFIG]) && is_scalar($options[static::OPTION_CONFIG])) {
$config_candidate = strval($options[static::OPTION_CONFIG]);
$config = is_file($config_candidate) ? (string) file_get_contents($config_candidate) : $config_candidate;
}

Comment on lines +210 to +215

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Harden config file loading and produce actionable errors.

  • If file_get_contents() fails, it returns false and silently becomes an empty string; this leads to a confusing JSON parse error later.
  • Provide a contextual error when the JSON is invalid (whether inline or file-based).

Apply:

-    $config = '{}';
-    if (isset($options[static::OPTION_CONFIG]) && is_scalar($options[static::OPTION_CONFIG])) {
-      $config_candidate = strval($options[static::OPTION_CONFIG]);
-      $config = is_file($config_candidate) ? (string) file_get_contents($config_candidate) : $config_candidate;
-    }
+    $config = '{}';
+    if (isset($options[static::OPTION_CONFIG]) && is_scalar($options[static::OPTION_CONFIG])) {
+      $config_candidate = strval($options[static::OPTION_CONFIG]);
+      if (is_file($config_candidate)) {
+        $contents = file_get_contents($config_candidate);
+        if ($contents === FALSE) {
+          throw new \RuntimeException(sprintf('Unable to read --config file at "%s".', $config_candidate));
+        }
+        $config = $contents;
+      }
+      else {
+        $config = $config_candidate;
+      }
+    }

And wrap parsing to add context:

-    $this->config = Config::fromString($config);
+    try {
+      $this->config = Config::fromString($config);
+    }
+    catch (\Throwable $e) {
+      throw new \RuntimeException('Invalid --config value. Provide a valid JSON string or a path to a readable JSON file.', 0, $e);
+    }
🤖 Prompt for AI Agents
In .vortex/installer/src/Command/InstallCommand.php around lines 210-215 the
config loading silently converts a failed file_get_contents() to an empty string
and later JSON errors lack context; change the logic to first check is_file() &&
is_readable($config_candidate) before reading, capture the result of
file_get_contents() and if it === false throw a clear exception mentioning the
file path and read failure; when treating the candidate as inline JSON or file
contents, run json_decode() and then check json_last_error() and if an error
exists throw an exception that includes whether the source was a file or inline
input, the source identifier (file path or "inline"), and the original content
(or a truncated preview) to make the JSON parsing error actionable.

$this->config = Config::fromString($config);

$this->config->setQuiet($options[static::OPTION_QUIET]);
Expand Down
17 changes: 12 additions & 5 deletions .vortex/installer/src/Prompts/PromptManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,14 +506,21 @@ private function args(string $handler_class, mixed $default_override = NULL, arr

// Find appropriate default value.
$default_from_handler = $handler->default($responses);

$env_var = static::makeEnvName($id);
$env_val = Env::get($env_var);
// Create the env var name.
$var_name = static::makeEnvName($id);
// Get from config.
$config_val = $this->config->get($var_name);
$default_from_config = is_null($config_val) ? NULL : $config_val;
// Get from env.
$env_val = Env::get($var_name);
$default_from_env = is_null($env_val) ? NULL : Env::toValue($env_val);
Comment on lines +512 to 516

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Document typing assumptions and treat empty env as “unset”

  • Add a note that config values originate from parsed JSON and are already typed; Env values require Env::toValue().
  • Consider treating empty-string env ('') as “unset” so it doesn’t shadow discovery/handler defaults with a no-op default.

Apply:

-    // Get from config.
+    // Get from config (already typed from parsed JSON).
     $config_val = $this->config->get($var_name);
     $default_from_config = is_null($config_val) ? NULL : $config_val;
-    // Get from env.
-    $env_val = Env::get($var_name);
-    $default_from_env = is_null($env_val) ? NULL : Env::toValue($env_val);
+    // Get from env (string -> typed). Treat empty string as "unset" to allow fallback.
+    $env_val = Env::get($var_name);
+    $default_from_env = ($env_val === '' || $env_val === NULL) ? NULL : Env::toValue($env_val);

Question: Do we want empty env values to be a deliberate way to clear a default, or should they fall back to discovery/handler? Current behavior would silently pick '' (and then omit args['default']), skipping discovery; the change above opts to fall back. Please confirm the desired semantics.

📝 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
$config_val = $this->config->get($var_name);
$default_from_config = is_null($config_val) ? NULL : $config_val;
// Get from env.
$env_val = Env::get($var_name);
$default_from_env = is_null($env_val) ? NULL : Env::toValue($env_val);
// Get from config (already typed from parsed JSON).
$config_val = $this->config->get($var_name);
$default_from_config = is_null($config_val) ? NULL : $config_val;
// Get from env (string -> typed). Treat empty string as "unset" to allow fallback.
$env_val = Env::get($var_name);
$default_from_env = ($env_val === '' || $env_val === NULL) ? NULL : Env::toValue($env_val);


// Get from discovery.
$default_from_discovery = $this->handlers[$id]->discover();

if (!is_null($default_from_env)) {
if (!is_null($default_from_config)) {
$default = $default_from_config;
}
elseif (!is_null($default_from_env)) {
$default = $default_from_env;
}
elseif (!is_null($default_from_discovery)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@@ -99,11 +99,6 @@
usage: Run Drush commands in the CLI service container.
cmd: ahoy cli "vendor/bin/drush -l \${VORTEX_LOCALDEV_URL} $*"

- flush-valkey:
- aliases: [flush-redis]
- usage: Flush Valkey cache.
- cmd: docker compose exec valkey valkey-cli flushall
-
# ----------------------------------------------------------------------------
# Application commands.
# ----------------------------------------------------------------------------
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@@ -70,10 +70,6 @@
# Shield message.
DRUPAL_SHIELD_PRINT="Restricted access."

-# Enable Redis/Valkey integration.
-# See settings.redis.php for details.
-DRUPAL_REDIS_ENABLED=1
-
# Enable ClamAV integration.
DRUPAL_CLAMAV_ENABLED=1

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@@ -2,12 +2,12 @@

# star wars

-Drupal 11 implementation of star wars for star wars Org
+Drupal 11 implementation of star wars for My custom org

-[![Database, Build, Test and Deploy](https://github.com/star_wars_org/star_wars/actions/workflows/build-test-deploy.yml/badge.svg)](https://github.com/star_wars_org/star_wars/actions/workflows/build-test-deploy.yml)
+[![Database, Build, Test and Deploy](https://github.com/my_custom_org/star_wars/actions/workflows/build-test-deploy.yml/badge.svg)](https://github.com/my_custom_org/star_wars/actions/workflows/build-test-deploy.yml)

![Drupal 11](https://img.shields.io/badge/Drupal-11-blue.svg)
-[![codecov](https://codecov.io/gh/star_wars_org/star_wars/graph/badge.svg)](https://codecov.io/gh/star_wars_org/star_wars)
+[![codecov](https://codecov.io/gh/my_custom_org/star_wars/graph/badge.svg)](https://codecov.io/gh/my_custom_org/star_wars)

![Automated updates](https://img.shields.io/badge/Automated%20updates-RenovateBot-brightgreen.svg)

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@@ -1,6 +1,6 @@
{
- "name": "star_wars_org/star_wars",
- "description": "Drupal 11 implementation of star wars for star wars Org",
+ "name": "my_custom_org/star_wars",
+ "description": "Drupal 11 implementation of star wars for My custom org",
"license": "proprietary",
"type": "project",
"require": {
@@ -17,7 +17,6 @@
"drupal/environment_indicator": "__VERSION__",
"drupal/pathauto": "__VERSION__",
"drupal/redirect": "__VERSION__",
- "drupal/redis": "__VERSION__",
"drupal/robotstxt": "__VERSION__",
"drupal/search_api": "__VERSION__",
"drupal/search_api_solr": "__VERSION__",
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
@@ -52,8 +52,6 @@
# Drupal Shield credentials.
DRUPAL_SHIELD_USER: ${DRUPAL_SHIELD_USER:-}
DRUPAL_SHIELD_PASS: ${DRUPAL_SHIELD_PASS:-}
- # Valkey integration flag.
- DRUPAL_REDIS_ENABLED: ${DRUPAL_REDIS_ENABLED:-}

# The default user under which the containers should run.
x-user: &default-user
@@ -146,9 +144,6 @@
ports:
- '3306' # Database port in a container. Find port on host with `ahoy info` or `docker compose port database 3306`.

- valkey:
- image: uselagoon/valkey-8:__VERSION__
-
solr:
build:
context: .
@@ -196,8 +191,7 @@
- clamav
- cli
- database
- - valkey
- command: database:3306 clamav:3310 valkey:6379
+ command: database:3306 clamav:3310

networks: ### Use external networks locally. Automatically removed in CI.
amazeeio-network: ### Automatically removed in CI.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@@ -1,6 +1,6 @@
{
"name": "star_wars",
- "description": "Drupal 11 implementation of star wars for star wars Org",
+ "description": "Drupal 11 implementation of star wars for My custom org",
"license": "proprietary",
"private": true,
"engines": {
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@@ -42,9 +42,6 @@
task "Installing contrib modules."
drush pm:install admin_toolbar coffee config_split config_update media environment_indicator pathauto redirect robotstxt shield stage_file_proxy

- task "Installing Redis module."
- drush pm:install redis || true
-
task "Installing and configuring ClamAV."
drush pm:install clamav
drush config-set clamav.settings mode_daemon_tcpip.hostname clamav
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
@@ -228,105 +228,6 @@
}

/**
- * Test Valkey settings.
- */
- public function testValkey(): void {
- $this->setEnvVars([
- 'DRUPAL_REDIS_ENABLED' => 1,
- 'VALKEY_HOST' => 'valkey_host',
- 'VALKEY_SERVICE_PORT' => 1234,
- 'VORTEX_REDIS_EXTENSION_LOADED' => 1,
- ]);
-
- $this->requireSettingsFile();
-
- $settings['redis.connection']['interface'] = 'PhpRedis';
- $settings['redis.connection']['host'] = 'valkey_host';
- $settings['redis.connection']['port'] = 1234;
- $settings['cache']['default'] = 'cache.backend.redis';
-
- $this->assertArrayHasKey('bootstrap_container_definition', $this->settings);
- unset($this->settings['bootstrap_container_definition']);
-
- $this->assertSettingsContains($settings);
- }
-
- /**
- * Test Valkey partial settings.
- */
- public function testValkeyPartial(): void {
- $this->setEnvVars([
- 'DRUPAL_REDIS_ENABLED' => 1,
- 'VALKEY_HOST' => 'valkey_host',
- 'VALKEY_SERVICE_PORT' => 1234,
- 'VORTEX_REDIS_EXTENSION_LOADED' => 0,
- ]);
-
- $this->requireSettingsFile();
-
- $settings['redis.connection']['interface'] = 'PhpRedis';
- $settings['redis.connection']['host'] = 'valkey_host';
- $settings['redis.connection']['port'] = 1234;
- $no_settings['cache']['default'] = 'cache.backend.redis';
-
- $this->assertArrayNotHasKey('bootstrap_container_definition', $this->settings);
-
- $this->assertSettingsContains($settings);
- $this->assertSettingsNotContains($no_settings);
- }
-
- /**
- * Test Redis settings with REDIS_* environment variables.
- */
- public function testRedisVariables(): void {
- $this->setEnvVars([
- 'DRUPAL_REDIS_ENABLED' => 1,
- 'REDIS_HOST' => 'redis_host',
- 'REDIS_SERVICE_PORT' => 6380,
- 'VORTEX_REDIS_EXTENSION_LOADED' => 1,
- ]);
-
- $this->requireSettingsFile();
-
- $settings['redis.connection']['interface'] = 'PhpRedis';
- $settings['redis.connection']['host'] = 'redis_host';
- $settings['redis.connection']['port'] = 6380;
- $settings['cache']['default'] = 'cache.backend.redis';
-
- $this->assertArrayHasKey('bootstrap_container_definition', $this->settings);
- unset($this->settings['bootstrap_container_definition']);
-
- $this->assertSettingsContains($settings);
- }
-
- /**
- * Test Redis fallback when both VALKEY_* and REDIS_* variables are set.
- */
- public function testRedisValkeyPrecedence(): void {
- $this->setEnvVars([
- 'DRUPAL_REDIS_ENABLED' => 1,
- 'VALKEY_HOST' => 'valkey_host',
- 'VALKEY_SERVICE_PORT' => 1234,
- 'REDIS_HOST' => 'redis_host',
- 'REDIS_SERVICE_PORT' => 6380,
- 'VORTEX_REDIS_EXTENSION_LOADED' => 1,
- ]);
-
- $this->requireSettingsFile();
-
- // VALKEY_* variables should take precedence over REDIS_* variables.
- $settings['redis.connection']['interface'] = 'PhpRedis';
- $settings['redis.connection']['host'] = 'valkey_host';
- $settings['redis.connection']['port'] = 1234;
- $settings['cache']['default'] = 'cache.backend.redis';
-
- $this->assertArrayHasKey('bootstrap_container_definition', $this->settings);
- unset($this->settings['bootstrap_container_definition']);
-
- $this->assertSettingsContains($settings);
- }
-
- /**
* Test Shield config.
*/
#[DataProvider('dataProviderShield')]
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@@ -74,15 +74,6 @@
# See settings.redis.php for details.
DRUPAL_REDIS_ENABLED=1

-# Enable ClamAV integration.
-DRUPAL_CLAMAV_ENABLED=1
-
-# ClamAV mode.
-#
-# Run ClamAV in either daemon mode by setting it to 0 (or 'daemon') or in
-# executable mode by setting it to 1.
-DRUPAL_CLAMAV_MODE=daemon
-
################################################################################
# PROVISION #
################################################################################
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@@ -2,12 +2,12 @@

# star wars

-Drupal 11 implementation of star wars for star wars Org
+Drupal 11 implementation of star wars for My other custom org

-[![Database, Build, Test and Deploy](https://github.com/star_wars_org/star_wars/actions/workflows/build-test-deploy.yml/badge.svg)](https://github.com/star_wars_org/star_wars/actions/workflows/build-test-deploy.yml)
+[![Database, Build, Test and Deploy](https://github.com/my_other_custom_org/star_wars/actions/workflows/build-test-deploy.yml/badge.svg)](https://github.com/my_other_custom_org/star_wars/actions/workflows/build-test-deploy.yml)

![Drupal 11](https://img.shields.io/badge/Drupal-11-blue.svg)
-[![codecov](https://codecov.io/gh/star_wars_org/star_wars/graph/badge.svg)](https://codecov.io/gh/star_wars_org/star_wars)
+[![codecov](https://codecov.io/gh/my_other_custom_org/star_wars/graph/badge.svg)](https://codecov.io/gh/my_other_custom_org/star_wars)

![Automated updates](https://img.shields.io/badge/Automated%20updates-RenovateBot-brightgreen.svg)

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@@ -1,6 +1,6 @@
{
- "name": "star_wars_org/star_wars",
- "description": "Drupal 11 implementation of star wars for star wars Org",
+ "name": "my_other_custom_org/star_wars",
+ "description": "Drupal 11 implementation of star wars for My other custom org",
"license": "proprietary",
"type": "project",
"require": {
@@ -8,7 +8,6 @@
"composer/installers": "__VERSION__",
"cweagans/composer-patches": "__VERSION__",
"drupal/admin_toolbar": "__VERSION__",
- "drupal/clamav": "__VERSION__",
"drupal/coffee": "__VERSION__",
"drupal/config_split": "__VERSION__",
"drupal/config_update": "__VERSION__",
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
@@ -166,17 +166,6 @@
ports:
- '8983' # Solr port in a container. Find port on host with `ahoy info` or `docker compose port solr 8983`.

- clamav:
- build:
- context: .
- dockerfile: .docker/clamav.dockerfile
- environment:
- <<: *default-environment
- ports:
- - '3310' # Find port on host with `docker compose port clamav 3310`.
- networks:
- - default
-
# Chrome container, used for browser testing.
chrome:
image: selenium/standalone-chromium:__VERSION__
@@ -193,11 +182,10 @@
wait_dependencies:
image: drevops/docker-wait-for-dependencies:__VERSION__
depends_on:
- - clamav
- cli
- database
- valkey
- command: database:3306 clamav:3310 valkey:6379
+ command: database:3306 valkey:6379

networks: ### Use external networks locally. Automatically removed in CI.
amazeeio-network: ### Automatically removed in CI.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@@ -1,6 +1,6 @@
{
"name": "star_wars",
- "description": "Drupal 11 implementation of star wars for star wars Org",
+ "description": "Drupal 11 implementation of star wars for My other custom org",
"license": "proprietary",
"private": true,
"engines": {
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@@ -45,10 +45,6 @@
task "Installing Redis module."
drush pm:install redis || true

- task "Installing and configuring ClamAV."
- drush pm:install clamav
- drush config-set clamav.settings mode_daemon_tcpip.hostname clamav
-
task "Installing Solr search modules."
drush pm:install search_api search_api_solr

Loading