Skip to content
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

Feature/env variables override config #3842

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
618d0b3
wip: override config from env vars
Feb 4, 2024
1824a0d
docs and phpcs changes
Feb 4, 2024
1e1d30f
feat: refactor config environment loader
Feb 11, 2024
b6c75ed
add unittest and some changes for mocking and making the logic work
Flyingmana Feb 18, 2024
c6eabc3
tests: finish some more tests w/ website and store data overrides
Feb 18, 2024
63a9c95
Merge branch 'main' into feature/ENV-variables-override-config
fballiano Feb 19, 2024
f6743b3
Merge branch 'main' into feature/ENV-variables-override-config
fballiano Feb 25, 2024
9f85ccd
Changed "unload" to "beforeunload" in extjs to avoid deprecation warn…
andrewcbi Feb 25, 2024
cfac8e0
Bump phpunit/phpunit from 9.6.16 to 9.6.17 (#3854)
dependabot[bot] Feb 26, 2024
9ec1e69
Bump phpseclib/mcrypt_compat from 2.0.4 to 2.0.5 (#3855)
dependabot[bot] Feb 26, 2024
0ea5dd7
Bump friendsofphp/php-cs-fixer from 3.49.0 to 3.50.0 (#3857)
dependabot[bot] Feb 26, 2024
3f6db4d
Removed Mage_Backup and Mage_PageCache from PHPStan configuration (#3…
fballiano Feb 27, 2024
6f441b5
New feature: added support for type "label" to system.xml (#3849)
fballiano Feb 27, 2024
cbf384a
Bump phpstan/phpstan from 1.10.58 to 1.10.59 (#3856)
dependabot[bot] Feb 27, 2024
fef1c08
Fixed column default sorting in customer's orders grid (#3852)
addison74 Feb 27, 2024
63293af
Fixed null parameter warning in DataFlow Profiles (#3827)
addison74 Feb 27, 2024
8d00914
Merge pull request from GHSA-gp6m-fq6h-cjcx
Judx Feb 27, 2024
4176402
Version bump in preparation for next release
fballiano Feb 27, 2024
5b84ee1
PHPCS fix for commit 8d00914fb5238efbb242d8d95b395e35b9a21fe4
fballiano Feb 27, 2024
40dcee7
Fixed zIndex to avoid conflicts between TinyMCE and OpenMage's overla…
fballiano Feb 28, 2024
94f08e1
Fixed default width for input/textarea in OpenMage backend theme (#3850)
fballiano Feb 29, 2024
ac50a6a
Improved fields dependence (show/hide) in backend's config section (#…
luigifab Mar 2, 2024
50bdaf8
wip: override config from env vars
Feb 4, 2024
67b82e7
docs and phpcs changes
Feb 4, 2024
fe15216
feat: refactor config environment loader
Feb 11, 2024
2da4951
add unittest and some changes for mocking and making the logic work
Flyingmana Feb 18, 2024
3eda641
tests: finish some more tests w/ website and store data overrides
Feb 18, 2024
b2abcf0
Merge branch 'feature/ENV-variables-override-config' of https://githu…
Mar 2, 2024
b3da428
fix: PHP8 test error when constructing Mage_Core_Model_Config
Mar 2, 2024
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
4 changes: 2 additions & 2 deletions app/Mage.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public static function getOpenMageVersionInfo(): array
if (self::getOpenMageMajorVersion() === 20) {
return [
'major' => '20',
'minor' => '4',
'minor' => '5',
'patch' => '0',
'stability' => '', // beta,alpha,rc
'number' => '', // 1,2,3,0.3.7,x.7.z.92 @see https://semver.org/#spec-item-9
Expand All @@ -225,7 +225,7 @@ public static function getOpenMageVersionInfo(): array
return [
'major' => '19',
'minor' => '5',
'patch' => '2',
'patch' => '3',
'stability' => '', // beta,alpha,rc
'number' => '', // 1,2,3,0.3.7,x.7.z.92 @see https://semver.org/#spec-item-9
];
Expand Down
18 changes: 9 additions & 9 deletions app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ protected function _prepareColumns()
'index' => 'increment_id',
]);

if (!Mage::app()->isSingleStoreMode()) {
$this->addColumn('store_id', [
'header' => Mage::helper('customer')->__('Bought From'),
'index' => 'store_id',
'type' => 'store',
'store_view' => true
]);
}

$this->addColumn('created_at', [
'header' => Mage::helper('customer')->__('Purchase On'),
'index' => 'created_at',
Expand Down Expand Up @@ -99,15 +108,6 @@ protected function _prepareColumns()
'options' => Mage::getSingleton('sales/order_config')->getStatuses(),
]);

if (!Mage::app()->isSingleStoreMode()) {
$this->addColumn('store_id', [
'header' => Mage::helper('customer')->__('Bought From'),
'index' => 'store_id',
'type' => 'store',
'store_view' => true
]);
}

if (Mage::helper('sales/reorder')->isAllow()) {
$this->addColumn('action', [
'header' => ' ',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ protected function _prepareLayout()
'after_html' => '</div>'
]);
$this->setChild('top_button', $button);
}

if ($this->getCustomerId()) {
$button = clone $button;
$button->unsId();
$this->setChild('bottom_button', $button);
}

return parent::_prepareLayout();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function _getDeleteCheckbox()
$html = '';
if ((string)$this->getValue()) {
$label = Mage::helper('adminhtml')->__('Delete File');
$html .= '<div>' . $this->getValue() . ' ';
$html .= '<div>' . Mage::helper('adminhtml')->escapeHtml($this->getValue()) . ' ';
$html .= '<input type="checkbox" name="' . parent::getName() . '[delete]" value="1" class="checkbox" id="' . $this->getHtmlId() . '_delete"' . ($this->getDisabled() ? ' disabled="disabled"' : '') . '/>';
$html .= '<label for="' . $this->getHtmlId() . '_delete"' . ($this->getDisabled() ? ' class="disabled"' : '') . '> ' . $label . '</label>';
$html .= '<input type="hidden" name="' . parent::getName() . '[value]" value="' . $this->getValue() . '" />';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class Mage_Adminhtml_Block_System_Config_Form_Field_Heading extends Mage_Adminht
*/
public function render(Varien_Data_Form_Element_Abstract $element)
{
$useContainerId = $element->getData('use_container_id');
return sprintf(
'<tr class="system-fieldset-sub-head" id="row_%s"><td colspan="5"><h4 id="%s">%s</h4></td></tr>',
$element->getHtmlId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function getValue($key, $default = '', $defaultNew = null)
}

$value = $this->getData($key);
return $this->escapeHtml(strlen($value) > 0 ? $value : $default);
return $this->escapeHtml($value !== null && strlen($value) > 0 ? $value : $default);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Catalog/Block/Product/List.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Mage_Catalog_Block_Product_List extends Mage_Catalog_Block_Product_Abstrac
/**
* Product Collection
*
* @var Mage_Eav_Model_Entity_Collection_Abstract|null
* @var Mage_Catalog_Model_Resource_Product_Collection|null
*/
protected $_productCollection;

Expand Down
132 changes: 132 additions & 0 deletions app/code/core/Mage/Core/Helper/EnvironmentConfigLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?php
/**
* OpenMage
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available at https://opensource.org/license/osl-3-0-php
*
* @category Mage
* @package Mage_Core
* @copyright Copyright (c) 2006-2020 Magento, Inc. (https://www.magento.com)
* @copyright Copyright (c) 2016-present The OpenMage Contributors (https://www.openmage.org)
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

/**
* Core Environment helper
*
* @category Mage
* @package Mage_Core
*/
class Mage_Core_Helper_EnvironmentConfigLoader extends Mage_Core_Helper_Abstract
{
protected $_moduleName = 'Mage_Core';
protected const ENV_STARTS_WITH = 'OPENMAGE_CONFIG';
protected const ENV_KEY_SEPARATOR = '__';
protected const CONFIG_KEY_DEFAULT = 'DEFAULT';
protected const CONFIG_KEY_WEBSITES = 'WEBSITES';
protected const CONFIG_KEY_STORES = 'STORES';

protected array $envStore = [];

/**
* Load configuration values from ENV variables into xml config object
*
* Environment variables work on this schema:
*
* self::ENV_STARTS_WITH . self::ENV_KEY_SEPARATOR (OPENMAGE_CONFIG__)
* ^ Prefix (required)
* <SCOPE>__
* ^ Where scope is DEFAULT, WEBSITES__<WEBSITE_CODE> or STORES__<STORE_CODE>
* <SYSTEM_VARIABLE_NAME>
* ^ Where GROUP, SECTION and FIELD are separated by self::ENV_KEY_SEPARATOR
*
* Each example will override the 'general/store_information/name' value.
* Override from the default configuration:
* @example OPENMAGE_CONFIG__DEFAULT__GENERAL__STORE_INFORMATION__NAME=default
* Override the website 'base' configuration:
* @example OPENMAGE_CONFIG__WEBSITES__BASE__GENERAL__STORE_INFORMATION__NAME=website
* Override the store 'german' configuration:
* @example OPENMAGE_CONFIG__STORES__GERMAN__GENERAL__STORE_INFORMATION__NAME=store_german
*
* @param Varien_Simplexml_Config $xmlConfig
* @return void
*/
public function overrideEnvironment(Varien_Simplexml_Config $xmlConfig)
{
$env = $this->getEnv();

foreach ($env as $configKey => $value) {
if (!str_starts_with($configKey, static::ENV_STARTS_WITH)) {
continue;
}

$configKeyParts = array_filter(
explode(
static::ENV_KEY_SEPARATOR,
$configKey
),
'trim'
);
list($_, $scope) = $configKeyParts;

switch ($scope) {
case static::CONFIG_KEY_DEFAULT:
list($_, $_, $section, $group, $field) = $configKeyParts;
$path = $this->buildPath($section, $group, $field);
$xmlConfig->setNode($this->buildNodePath($scope, $path), $value);
break;

case static::CONFIG_KEY_WEBSITES:
case static::CONFIG_KEY_STORES:
list($_, $_, $code, $section, $group, $field) = $configKeyParts;
$path = $this->buildPath($section, $group, $field);
$nodePath = sprintf('%s/%s/%s', strtolower($scope), strtolower($code), $path);
$xmlConfig->setNode($nodePath, $value);
break;
}
}
}

/**
* @internal method mostly for mocking
*/
public function setEnvStore(array $envStorage): void
{
$this->envStore = $envStorage;
}

public function getEnv(): array
{
if (empty($this->envStore)) {
$this->envStore = getenv();
}
return $this->envStore;
}

/**
* Build configuration path.
*
* @param string $section
* @param string $group
* @param string $field
* @return string
*/
public function buildPath($section, $group, $field): string
{
return strtolower(implode('/', [$section, $group, $field]));
}

/**
* Build configuration node path.
*
* @param string $scope
* @param string $path
* @return string
*/
public function buildNodePath($scope, $path): string
{
return strtolower($scope) . '/' . $path;
}
}
1 change: 1 addition & 0 deletions app/code/core/Mage/Core/Model/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ protected function _initModules()
Varien_Profiler::stop('mage::app::init::apply_db_schema_updates');
}
$this->_config->loadDb();
$this->_config->loadEnv();
$this->_config->saveCache();
}
} finally {
Expand Down
18 changes: 18 additions & 0 deletions app/code/core/Mage/Core/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ public function init($options = [])
$this->_useCache = false;
$this->loadModules();
$this->loadDb();
$this->loadEnv();
$this->saveCache();
}
} finally {
Expand Down Expand Up @@ -422,6 +423,23 @@ public function loadDb()
return $this;
}

/**
* Load environment variables and override config
*
* @return self
*/
public function loadEnv(): Mage_Core_Model_Config
{
if ($this->_isLocalConfigLoaded && Mage::isInstalled()) {
Varien_Profiler::start('config/load-env');
/** @var Mage_Core_Helper_EnvironmentConfigLoader $environmentConfigLoaderHelper */
$environmentConfigLoaderHelper = Mage::helper('core/environmentConfigLoader');
$environmentConfigLoaderHelper->overrideEnvironment($this);
Varien_Profiler::stop('config/load-env');
}
return $this;
}

/**
* Reinitialize configuration
*
Expand Down
3 changes: 2 additions & 1 deletion app/code/core/Mage/Dataflow/Model/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ protected function _beforeSave()
{
parent::_beforeSave();
$actionsXML = $this->getData('actions_xml');
if (strlen($actionsXML) < 0 &&
// @phpstan-ignore-next-line because of https://github.com/phpstan/phpstan/issues/10570
if ($actionsXML !== null && strlen($actionsXML) < 0 &&
@simplexml_load_string('<data>' . $actionsXML . '</data>', null, LIBXML_NOERROR) === false
) {
Mage::throwException(Mage::helper('dataflow')->__("Actions XML is not valid."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ public function getRowUrl($row)
* Prepare collection by setting page number, sorting etc..
*
* @param Mage_Eav_Model_Resource_Entity_Attribute_Collection $collection
* @return Mage_Eav_Model_Resource_Entity_Attribute_Collection
* @return Mage_Core_Model_Resource_Db_Collection_Abstract|null
*/
public function prepareCollection(Mage_Eav_Model_Resource_Entity_Attribute_Collection $collection)
{
Expand Down
3 changes: 1 addition & 2 deletions app/code/core/Mage/Sales/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,7 @@ public function prepareProductEditFormRecurringProfile($observer)
$dependencies = $block
->addFieldMap('is_recurring', 'product[is_recurring]')
->addFieldMap($profileElement->getHtmlId(), $profileElement->getName())
->addFieldDependence($profileElement->getName(), 'product[is_recurring]', '1')
->addConfigOptions(['levels_up' => 2]);
->addFieldDependence($profileElement->getName(), 'product[is_recurring]', '1');
$observer->getEvent()->getResult()->output .= $dependencies->toHtml();
}

Expand Down
Loading
Loading