Skip to content

Conversation

@avstudnitz
Copy link
Contributor

Taken over from #12178.

This is similar to the "lock" switch which writes configuration
values to app/etc/env.php. The "lock-config" switch writes it to
app/etc/config.php instead which can be shared between environments.
For consistency, the "lock" switch has been renamed to "lock-env".

Description

In most cases, configuration settings should be shared among all development, staging and live instances of a shop. To achieve this, you can use the same mechanism as with the --lock switch described in http://devdocs.magento.com/guides/v2.2/config-guide/cli/config-cli-subcommands-config-mgmt-set.html.

The only difference is that the configuration values will be stored in app/etc/config.php instead of app/etc/env.php. This file should usually be included in the VCS and thus shared between instances.

To store a config setting in the file via command line, the command would be as follows:

bin/magento config:set --lock-config <path> <value>

i.e.

bin/magento config:set --lock-config general/store_information/name "Sample Store"

Manual testing scenarios

  1. Call bin/magento config:set --lock-config general/store_information/name "Sample Store" from the command line
  2. Verify that the app/etc/config.php file contains a section as follows:
[...]
  'cache_types' => 
  array (
    'config' => 1,
    [...]
  ),
  'install' => 
  array (
    'date' => 'Wed, 08 Nov 2017 11:52:21 +0000',
  ),
  'system' => 
  array (
    'default' => 
    array (
      'general' => 
      array (
        'store_information' => 
        array (
          'name' => 'Sample Store',
        ),
      ),
    ),
  ),
);
  1. Verify that the configuration setting "Store Name" in the section "General", group "Store Information" is filled with "Sample Store" and greyed out:

grafik

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

This is similar to the "lock" switch which writes configuration
values to app/etc/env.php. The "share" switch writes it to
app/etc/config.php instead which can be shared between environments.
…hare option

We are using Virtual Classes now as we have almost the same Processor
twice and we can avoid having duplicate code this way.
The "getOption" method was called more often than before, so
we had to adjust that.
This new method contains the new parameter and will be called from
the old method.
This is similar to the "lock" switch which writes configuration
values to app/etc/env.php. The "share" switch writes it to
app/etc/config.php instead which can be shared between environments.
…hare option

We are using Virtual Classes now as we have almost the same Processor
twice and we can avoid having duplicate code this way.
The "getOption" method was called more often than before, so
we had to adjust that.
This new method contains the new parameter and will be called from
the old method.
…g-set-option-share

# Conflicts:
#	app/code/Magento/Deploy/Model/Mode.php
@davidverholen
Copy link
Member

davidverholen commented Jan 22, 2018

@avstudnitz really great pr, read your article about it a while ago
But isn't it the other way around (from your description)? That the default lock switch currently writes to the config.php and the additional feature would write to env.php. Or am I missing something?

@avstudnitz
Copy link
Contributor Author

@davidverholen I just had that in a training last week, and I can confirm that the original --lock switch writes to env.php. Where did you read it vice versa? I can't find it at the moment...

@davidverholen
Copy link
Member

@avstudnitz Ok, I think I know now what happened.

I was just confused since I used this command to generate the config.php, but did not recognize the values being written to the env.php

Actually, I've set up everything with config:set and then exported the configuration to the config.php with bin/magento app:config:dump.

The app:config:dump command seems to make a difference between env specific and env independent settings. So some settings are considered shared and these are dumped to the config.php. I'm still searching for this Flag, my first guess was in the system.xml.

For example the base_url is configured in my local env.php, but is not exported to the config.php. Even if I explicitly lock the base_url before the config:dump. Most other settings are exported to the config.php.

@avstudnitz
Copy link
Contributor Author

@davidverholen Ah, yes. Some configuration options are marked as "sensitive" and not exported into config.php. See https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Config/etc/di.xml#L313-L324 for how it can be set. config:set doesn't care about that sensitive setting.

@avstudnitz
Copy link
Contributor Author

@fooman @okorshenko Any info when this will be tackled? It was almost finished in old PR #12178.

@magento-engcom-team
Copy link
Contributor

@avstudnitz thank you for contributing. Please accept Community Contributors team invitation here to gain extended permissions for this repository.

@magento magento deleted a comment from magento-engcom-team Feb 14, 2018
@avstudnitz
Copy link
Contributor Author

@magento-engcom-team Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants