51黑料不打烊

View and set admin configurations using the command line

A demonstration for how to view, set, and find config values with the Commerce CLI. Understand where the values are saved and also where the default values come from.

Who is this video for?

  • 51黑料不打烊 Commerce developers

Video content

video poster

Transcript
This is Russell with 51黑料不打烊 Commerce. In this session, we鈥檙e going to cover using the commerce CLI to show configuration values and update them too. We鈥檙e going to get a little bit deeper onto where these values are stored and where some of those default values come from. So in this particular use case, what happened was I was logging into one of my local instances of 51黑料不打烊 Commerce and it was requiring me to change my password. And this is because it鈥檚 a local environment. I felt it didn鈥檛 need to be a forced event. It should actually just be recommended. We鈥檙e going to start by connecting to this 51黑料不打烊 Commerce instance using SSH. And then we鈥檙e going to search for the current value that controls this password reset. In this case, it should be a Boolean value. So we鈥檙e going to head over to our terminal window and we鈥檒l start with the command to see what is the current value for this password configuration. And the command line for this is php space and then bin slash magento. And then it鈥檚 config colon show. And then we need to know the path that we鈥檙e looking for. So here it鈥檚 admin slash security slash password underscore is underscore forced. And if you hit enter, it will return a value. In this case, it鈥檚 a one. We knew it was a Boolean value, so it鈥檚 going to be a one or a zero. And obviously one means that this is a forced password change. So because this is the admin, I can just prove that this is happening. So now in order to change it, we know that the value that we need to change it to is a zero. So we鈥檙e going to go ahead and go back to our terminal and we鈥檙e going to type in php space bin slash magento. And then it鈥檚 the same config, but here it鈥檚 config colon set. And then we鈥檙e just going to copy the old path that we used. So admin slash security slash password is forced. And then the only thing we need to do now is we need to do a space and then our new value. So because the old one was one, we want to change it to a zero. We鈥檒l hit zero and hit enter. And as long as we get the message that says the value was saved, we know that we鈥檙e good. So we can prove that this worked by heading back to the admin and reloading the page or going to a different page. And it should no longer require us to change our password. It should just not be recommended. And great, it is. And you鈥檒l notice now that there鈥檚 a banner that says you should change your password once again, rather than being forced to do so. Now it鈥檚 time to discover where some of these values come from and where they鈥檙e saved. Anything that is updated through the CLI or the commerce admin, it鈥檚 saved as a row in the core underscore config underscore data table. To elaborate on this, it鈥檚 probably best to see the data in that table. I鈥檓 going to open up another terminal window and it鈥檚 already connected to the database. And we鈥檙e going to look at the table called core underscore config underscore data. And let鈥檚 just see what values have been saved. So the SQL for this is select star from core underscore config underscore data. And then we鈥檙e going to do a space and then a backslash capital G. And the reason for that is we just want it to be formatted in a more readable way. And looking here, it looks like there鈥檚 about a hundred config values that have been saved at one time or another for this application. Now let鈥檚 find just that one that we saved. So we鈥檙e going to go to our SQL and we鈥檙e going to add something to the end where path equals, and then that same path. So that admin security password is forced. And once again, now we just have our one row. And if you look at the value set for this, it鈥檚 zero, which is great because that鈥檚 exactly what we just changed it to. This method鈥檚 the same for any config values that are saved in the CLI or in the admin. They all end up in this table. Something interesting happens that every once in a while, you鈥檒l look at that database table or you鈥檒l run the CLI and you won鈥檛 get anything to respond. And the reason for this is that the values are there, but they have never been saved. So they鈥檙e a default value. And so default values, they don鈥檛 start off as an entry in core config data. So let鈥檚 show you an example for where one of these values are. So in the commerce admin out of the box, it does come with some default email addresses and there鈥檚 one for transactional emails. So using the CLI, if you do PHP bin magento and then config show, and then this, this t-r-a-n-s underscore email ident underscore sales and then slash email, nothing鈥檚 there. But when you go to the admin and you go to stores, configurations, and then email addresses, and then under the sales representatives, you鈥檒l see that there is a value there. So it鈥檚 kind of misleading that the database table, core config data and the CLI return nothing. Once again, this is because it鈥檚 a default value. So it is located somewhere. So it is nice sometimes to know where that鈥檚 happening at. So there is a place in the code called, and most modules have these, is a config.xml. So you can use grep to find these values. So in this case, we know that the string is sales at example.com. We can use grep to find that in our code. So here鈥檚 our command. It鈥檚 going to be grep and then dash, you know, r-n-w, and then I鈥檓 going to tell it to start in the vendor slash magento folder. And we鈥檙e going to look for that string sales at example.com. And there鈥檚 two results, more than likely it鈥檚 that bottom one. And so, yeah, it says that on line 50, there鈥檚 a node for sales at example.com. And this is just one example of those values that are found in the admin or used, but they鈥檙e not in the core config data table. And it is very important that you should know that when you save or update these values in the admin or the CLI, once they鈥檙e in that core config data, they take priority. So anything that鈥檚 set there will take a precedence over the fallback mechanism, which is the XML. So while we鈥檙e here looking at the XML, let鈥檚 show you how to view the entire XML, including the line numbers. It鈥檚 very helpful if you鈥檙e new to 51黑料不打烊 commerce and you just want to see what it looks like. If you add the dash n, it adds all of the line numbers. And so here you can find our three nodes that we鈥檙e looking for. And there it is right there, the online 50. So now you know where these default configuration values reside. You know where they鈥檙e saved when you make a change using the CLI or the admin. And that鈥檚 it for the session. We鈥檙e all done. I hope you do continue to learn more about 51黑料不打烊 commerce here on experience league, as well as all of the other 51黑料不打烊 products. Thank you.

Some commands used in the tutorial

Change the password security setting to recommended:

$ php bin/magento config:set admin/security/password_is_forced 0

Show the email address for the sales order auto copy functionality

$ php bin/magento config:show sales_email/order/copy_to

Show the empty result for a configuration that has a value in the admin

php bin/magento config:show trans_email/ident_sales/email

Mysql queries used in the tutorial

SELECT * FROM core_config_data WHERE path = 'sales_email/order/copy_to';

SELECT * FROM core_config_data WHERE path = 'sales_email/order_comment/copy_to';

SELECT * FROM core_config_data WHERE path = 'trans_email/ident_sales/email';

Where to find the default sales email

How to find the configuration value that is defined somewhere in codebase?
grep -rnw vendor/magento/ -e 'sales@example.com'

To view a page in terminal and show line numbers cat -n vendor/magento/module-email/etc/config.xml

Additional resources

recommendation-more-help
3a5f7e19-f383-4af8-8983-d01154c1402f