Skip to content

bin/magento config:set expects config path to match display path #27678

Closed
@navarr

Description

@navarr

Summary

We're updating our configuration to be more user friendly and this involves creating new categories to move configuration around. While doing this, we want to maintain backwards compatibility and so have set config_paths for most of our settings.

An example would be tax/vertex_settings/trustedId is now in system.xml as tax/vertex/connection/trusted_id - but has config_path set to tax/vertex_settings/trustedId. This field has a backend model to encrypt the data in it.

The problem being experienced is that the data is being entered into the database unencrypted - leading it to be considered encrypted and then the code receiving junk data.

This is occurring because the config:set command pulls apart the path and sends it as if that were the path being sent by the form.

So when we enter Magento\Config\Model\Config our $groupPath is tax/vertex_settings and our $groupData is ['fields' => ['trustedId' => ['value' => '<value>']]].

It SHOULD be:

  • groupPath = tax/vertex/connection
  • groupData = ['fields' => ['trusted_id' => ['value' => '<value>']]]

One might then try to run config:set tax/vertex/connection/trusted_id <value> however this returns that the config does not exist

Manual testing scenarios (*)

  1. Create sample module with system.xml like this
    <system>
        <section id="sales">
            <group id="general">
                <field id="keyid" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Key Id</label>
                </field>
            </group>
        </section>
    </system>
  1. Set some value via CLI
    bin/magento config:set sales/general/keyid 1
    We can see Value was saved. as expected.
  2. Add some config_path to system.xml like this
    <system>
        <section id="sales">
            <group id="general">
                <field id="keyid" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="0">
                    <label>Key Id</label>
                    <config_path>custom_path/keyid</config_path>
                </field>
            </group>
        </section>
    </system>
  1. Clear cache config
  2. Try to set some value via CLI again
    bin/magento config:set sales/general/keyid 777

Actual Result:

The "sales/general/keyid" path doesn't exist. Verify and try again.

Expected Result:

Value was saved.

Proposed Solution

Update Magento\Config\Model\Config\PathValidator to check if an element exists by the path presented to it, and if it has a config path, use that instead for validation.

Inserting into the top of the validate command:

        $element = $this->structure->getElementByConfigPath($path);
        if ($element->getConfigPath()) {
            $path = $element->getConfigPath();
        }

This is my proposed solution over trying to determine the display path via the config path, as more than one display path can have the same config path. This change would then allow config:set tax/vertex/connection/trusted_id (and other "display paths")

Metadata

Metadata

Assignees

Labels

Issue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: ready for confirmationPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: doneReproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchSeverity: S2Major restrictions or short-term circumventions are required until a fix is available.Triage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions