Skip to content

Add option "lock-config" for shell command "config:set" #12178

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

Closed
wants to merge 1,265 commits into from

Conversation

avstudnitz
Copy link
Contributor

@avstudnitz avstudnitz commented Nov 10, 2017

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)

@avstudnitz
Copy link
Contributor Author

I am not totally happy with the naming of the option. Instead of --share I could think of --lock-shared. I think both are okay, but not perfect. I am open for suggestions.

@fooman
Copy link
Contributor

fooman commented Nov 14, 2017

Thanks @avstudnitz - read your blog post on this and an addition like this totally makes sense. Agree that naming this is tricky.

I would suggest the following:
--lock-env (which is just an alias for --lock as to not break anything)
--lock-config

@avstudnitz
Copy link
Contributor Author

You can find the blog post about this functionality which was mentioned by @fooman at https://www.integer-net.com/magento-2-2-configuration-via-code/.

@jalogut
Copy link
Contributor

jalogut commented Nov 22, 2017

Just referencing another PR with improvements in same area:

@avstudnitz
Copy link
Contributor Author

I adjusted the PR accordingly (now using Virtual Classes to avoid code duplication) and updated the description. Thanks for the suggestion @fooman.

@avstudnitz avstudnitz changed the title Add option "share" for shell command "config:set" Add option "lock-config" for shell command "config:set" Nov 24, 2017
@fooman
Copy link
Contributor

fooman commented Nov 25, 2017

@avstudnitz would you mind taking a look at this failure as well https://travis-ci.org/magento/magento2/jobs/306722542#L1031 which seems related.

@avstudnitz
Copy link
Contributor Author

@fooman Done.

* @since 100.2.0
*/
public function process($path, $value, $scope, $scopeCode, $lock)
public function process($path, $value, $scope, $scopeCode, $lock, $lockTarget = ConfigFilePool::APP_ENV)
Copy link
Contributor

Choose a reason for hiding this comment

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

Unfortunately this backward incompatible change. Please follow the instruction here http://devdocs.magento.com/guides/v2.0/contributor-guide/backward-compatible-development/#adding-parameters-in-public-methods

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@okorshenko Can you explain to me why adding an optional parameter at the end should be backwards incompatible? I'd like to understand that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @avstudnitz this class has annotation @api. Adding new parameter to the method will break SPI clients of this class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed. If you have a better name than processWithLockTarget for the new method please tell me.

gwharton and others added 8 commits December 13, 2017 10:44
Old code "I" was not removed in initial commit for some reason.
…dia magento#1007

 - Merge Pull Request magento-engcom/magento2ce#1007 from p-bystritsky/magento2:ISSUE-12378
 - Merged commits:
   1. 5c36f98
   2. c27a56a
Added product codes to i18n
These codes have been renamed, so entries removed from i18n
 - Merge Pull Request magento#12633 from miguelbalparda/magento2:image-fix
 - Merged commits:
   1. ef1ffd5
   2. cef5991
Added quotes around strings in i18n
…false</var> for mobile device don't work in product view page gallery magento#1006
Accepted Public Pull Requests:
 - magento#12736: Issues/12374 (by @virtual97)


Fixed GitHub Issues:
 - magento#12374: Model hasDataChanges always true (reported by @Detzler) has been fixed in magento#12736 by @virtual97 in 2.2-develop branch
   Related commits:
     1. a847d89
     2. ae62931
@fooman fooman dismissed okorshenko’s stale review December 30, 2017 05:18

concerns addressed in last commit

@fooman
Copy link
Contributor

fooman commented Dec 30, 2017

@avstudnitz Thanks for addressing @okorshenko's feedback. Would you mind taking a look at the mentioned merge conflict as well.

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
@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Jan 2, 2018

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
8 out of 11 committers have signed the CLA.

✅ gwharton
✅ ishakhsuvarov
✅ p-bystritsky
✅ serhii-balko
✅ okorshenko
✅ sidolov
✅ nmalevanec
✅ RomaKis
❌ AzVo
❌ andimov
❌ duhon

@avstudnitz
Copy link
Contributor Author

@fooman I resolved the merge conflict and rebased the branch. Seems that has some side effects, tell me if I should create a new clean pull request.

@okorshenko okorshenko modified the milestones: December 2017, January 2018 Jan 8, 2018
@okorshenko
Copy link
Contributor

Hi @avstudnitz
Something goes wrong with your branch. Could you please extract your changes and apply them to new branches based on magento/magento2 : 2.2-develop
Please create new PR once ready.
Unfortunately, we can con merge this PR as is

@avstudnitz
Copy link
Contributor Author

Continued in #13280.

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.