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

[FIX] dev:di:info duplicates plugin info #16474

Conversation

coderimus
Copy link
Contributor

@coderimus coderimus commented Jul 1, 2018

Description

Hello,

Looks like the execution of dev:di:info duplicates info about plugins by for the or the Preference if the same plugin class and its type were introduced in plugins by class name section.

For example, execute php bin/magento dev:di:info "Magento\Sales\Model\Order" and the output result will be
image

with provided fix it will look like this

image

The problem is seems to be in this method:

    private function addPluginToList($pluginInstance, $pluginMethod, $methodTypes, $typeCode)
    {
        if ($methodTypes & $typeCode) {
            if (!array_key_exists($pluginInstance, $this->pluginList[$this->pluginTypeMapping[$typeCode]])) {
                $this->pluginList[$this->pluginTypeMapping[$typeCode]][$pluginInstance] = [];
            }
            $this->pluginList[$this->pluginTypeMapping[$typeCode]][$pluginInstance][] = $pluginMethod ;
        }
    }

It checks whether value exists in array or not. And if it exists it will be added +1 time. But it may logically to add an item once if it not exists.

Fixed Issues (if relevant)

N/A

Manual testing scenarios

execute dev:di:info command for class and check "Plugins for the Preference:" section. Seems to have duplicated info.

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)

@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Jul 1, 2018

CLA assistant check
All committers have signed the CLA.

@magento-engcom-team magento-engcom-team added Partner: Vaimo Pull Request is created by partner Vaimo partners-contribution Pull Request is created by Magento Partner labels Jul 1, 2018
@magento-engcom-team
Copy link
Contributor

Hi @coderimus. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me {$VERSION} instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

@coderimus coderimus removed the Partner: Vaimo Pull Request is created by partner Vaimo label Jul 1, 2018
@orlangur orlangur self-assigned this Jul 1, 2018
}
$this->pluginList[$this->pluginTypeMapping[$typeCode]][$pluginInstance][] = $pluginMethod ;
Copy link
Contributor

Choose a reason for hiding this comment

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

$this->pluginList[$this->pluginTypeMapping[$typeCode]][$pluginInstance][] = $pluginMethod ; ->

$this->pluginList[$this->pluginTypeMapping[$typeCode]][$pluginInstance][$pluginMethod] = 1

Please avoid duplication by reversing array. Please check if it is possible to remove if while avoiding PHP notice.

@coderimus coderimus removed the partners-contribution Pull Request is created by Magento Partner label Jul 2, 2018
$this->pluginList[$this->pluginTypeMapping[$typeCode]][$pluginInstance] = [];
}

if (!in_array($pluginMethod, $this->pluginList[$this->pluginTypeMapping[$typeCode]][$pluginInstance])) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @orlangur ,
What do you think about this modification? I implemented this second condition just because it looks like a cheapest and still technologically possible solution. Also, this method is totally isolated and used only for this command.

Copy link
Contributor

Choose a reason for hiding this comment

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

Too wordy and not elegant as to me but still good enough :) Asymptotic complexity became poor but should not be noticeable.

Good job with tiniest possible diff 👍

@magento-engcom-team magento-engcom-team added this to the Release: 2.2.6 milestone Jul 3, 2018
@magento-engcom-team magento-engcom-team added Partner: Vaimo Pull Request is created by partner Vaimo partners-contribution Pull Request is created by Magento Partner labels Jul 3, 2018
@magento-engcom-team
Copy link
Contributor

Hi @orlangur, thank you for the review.
ENGCOM-2177 has been created to process this Pull Request

@magento-engcom-team
Copy link
Contributor

Hi @coderimus. Thank you for your contribution.
We will aim to release these changes as part of 2.2.6.
Please check the release notes for final confirmation.

Please, consider to port this solution to 2.3 release line.
You may use Porting tool to port commits automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Component: Developer Partner: Vaimo Pull Request is created by partner Vaimo partners-contribution Pull Request is created by Magento Partner Progress: accept Release Line: 2.2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants