- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 452
Fix environment loader #4617
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix environment loader #4617
Conversation
| @sreichel Please see this PR. | 
| Quick test. 404 one every page. | 
| Maybe it come from invalid setting .... ?  | 
| For reference my old config: With yours I am getting infinite loop. | 
| The error was caused by the  via 1f6b7ed | 
| Thanks for working on it. Cant make a PR to your repo right now ... how about to filter env vars in getEnv()?     public function getEnv(): array
    {
        if (is_null($this->envStore)) {
            $env = getenv();
            $env = array_filter($env, function ($key) {
                return str_starts_with($key, self::ENV_STARTS_WITH);
            }, ARRAY_FILTER_USE_KEY);
            $this->envStore = $env;
        }
        return $this->envStore;
    }Maybe add an additional check for env  | 
| 
 Yes, on default scope, but not on one website/storeview level. (Scope label should ben changed to "ENV") | 
| Note ... Tests should be updated. | 
1f6b7ed    to
    9072ff8      
    Compare
  
    | 
 In "Default" scope the attribute is locked. For "German" storeview its not. 
 No, not that other "label". :) "[STORE VIEW]" could change to "[ENV]" and the checkbox can be removed. I am busy for the next 2-3 days. I'll test ASAP. | 
| 
 Hm. For me its locked. 
 Gotcha. Good point. | 
| 
 Not sure about it, sorry. Maybe the disabled checkbox was missleading. (?) | 
| Great! ❤️ I can make a PR later, but if you have time for it, please check the red SonarCloud issues. | 
| 
 I've removed one case. I'm not sure how else to get there (without makeing the cache array public?) | 
| To pass the complexity-check it should be enough to move try/catch-parts to a seperate method. Leave it as it is, i'll add a PR later. PS: please  | 
| :/ | 
- fix Mage::getStoreConfig w/o parameter (was empty result) - fix: apply default/website config to child stores - added test for backend (verify value is set and config label is set correctly)
| @pquerner can you please take a look at the failing unit tests? 
 | 
| Thinks its ready to review? | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements environment variable-based configuration overrides for OpenMage, allowing system configuration values to be set via environment variables with the format OPENMAGE_CONFIG__<SCOPE>__<SECTION>__<GROUP>__<FIELD>. This feature must be explicitly enabled by setting OPENMAGE_CONFIG_OVERRIDE_ALLOWED=1.
Key changes:
- Added a feature flag (OPENMAGE_CONFIG_OVERRIDE_ALLOWED) to control environment variable override functionality
- Extended override logic to support default, website, and store scopes with proper inheritance
- Added registry-based caching to prevent multiple overrides during a single request
- Created helper methods hasPath()andgetAsArray()for configuration access
- Updated admin UI to display [ENV]label and disable fields overridden by environment variables
Reviewed Changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description | 
|---|---|
| app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php | Core implementation of environment variable override logic with scope handling and caching | 
| app/code/core/Mage/Core/Helper/EnvironmentConfigLoader/Override.php | New data object class for storing parsed environment variable configuration | 
| app/code/core/Mage/Adminhtml/Block/System/Config/Form.php | Admin UI integration to display ENV scope label and disable fields | 
| app/code/core/Mage/Adminhtml/Model/Config/Data.php | Merges environment config into configuration data retrieval | 
| app/code/core/Mage/Core/Model/Store.php | Triggers environment override when fetching store configuration | 
| app/code/core/Mage/Core/Model/App.php | Clears registry cache when reinitializing stores | 
| tests/unit/Mage/Core/Helper/EnvironmentConfigLoaderTest.php | Comprehensive unit tests for environment override functionality | 
| cypress/e2e/openmage/backend/system/config/general/general.cy.js | End-to-end test verifying ENV overrides in admin UI | 
| cypress/support/openmage/backend/system/config/general/general.js | Test configuration for general system settings | 
| cypress/support/openmage/_utils/validation.js | Conditional CSS validation check | 
| cypress/support/openmage/_utils/test.js | Registers general config test namespace | 
| cypress/support/openmage/_utils/admin.js | Adds helper function for switching config scope | 
| cypress/support/e2e.js | Imports general config test support | 
| cypress/e2e/openmage/frontend/customer/account.cy.js | Updates test expectation to match ENV-overridden value | 
| .github/workflows/cypress.yml | Configures ENV variables for CI testing | 
        
          
                cypress/e2e/openmage/backend/system/config/general/general.cy.js
              
                Outdated
          
            Show resolved
            Hide resolved
        
              
          
                cypress/support/openmage/backend/system/config/general/general.js
              
                Outdated
          
            Show resolved
            Hide resolved
        
      Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
| Website dash (-) can be removed, yes. Tests fail because they iterate through the stores and no stores with german-at or german_ch exists (anymore?). | 
Websites may not have a "-" character so this test is removed Removed website test for "base_ch", as its the same as "base", so superflous. Add testing stores if not existing and remove afterwards.
| 
 | 
| Merged. This feature needs to be enabled via ENV  | 



Description (*)
This PR attempts to fix the incomplete attempt for config values to be overwritten from ENV variables.
Related Pull Requests
Fixed Issues (if relevant)
Manual testing scenarios (*)
Mage::getStoreConfig.Automated tests:
ddev phpunit --group Mage_Core_EnvLoaderQuestions or comments
Please give feedback to this WIP solution.
Maybe in the future we can add a reasoning of "why" the field in the backend is disabled for edits. Such as give a "warning" sign and show that this field is overwritten by a environment variable.
I feel that this is out of scope for now, for I think that the feature should first work the best it can.
Contribution checklist (*)