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

Extend Observer declaration in events.xml by new attribute ifconfig #38493

Open
wants to merge 13 commits into
base: 2.4-develop
Choose a base branch
from

Conversation

bartekAtconvert
Copy link

@bartekAtconvert bartekAtconvert commented Mar 6, 2024

Description (*)

Extension of Observer declaration in events.xml by new optional attribute ifconfig with appropriate handling of it.
Similar to usage of ifconfig in layout's xml files - it executes (or not) Observer depending on boolean value of given config path. The purpose is to condition Observer's execution on config paths representing module's state - usually <module/general/active> or <module/general/enabled> etc.

Manual testing scenarios (*)

  1. Add ifconfig attribute to Observer A declaration in events.xml file where its value will be config path and dispatch event to trigger Observer.
    a) When config path value equals to true - Observer should execute.
    b) When config path value equals to false - Observer should not execute
    c) When config does not exist (path does not represent any actual value) - Observer should not execute
  2. Add ifconfig attribute to Observer A declaration in events.xml file where its value is empty string "" and dispatch event to trigger Observer. Observer should execute.

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)
  • README.md files for modified modules are updated and included in the pull request if any README.md predefined sections require an update
  • All automated tests passed successfully (all builds are green)

Resolved issues:

  1. resolves [Issue] Extend Observer declaration in events.xml by new attribute ifconfig #38514: Extend Observer declaration in events.xml by new attribute ifconfig

…fig.

Similar to layouts xml files ifconfig is optional conditioner based on which Observer will be executed or not.
Copy link

m2-assistant bot commented Mar 6, 2024

Hi @bartekAtconvert. Thank you for your contribution!
Here are some useful tips on 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 give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names.

Allowed build names are:
  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests
  13. Semantic Version Checker

You can find more information about the builds here
ℹ️ Run only required test builds during development. Run all test builds before sending your pull request for review.


For more details, review the Code Contributions documentation.
Join Magento Community Engineering Slack and ask your questions in #github channel.

Copy link

Failed to run the builds. Please try to re-run them later.

@bartekAtconvert
Copy link
Author

@magento run all tests

@engcom-Hotel engcom-Hotel added Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it Priority: P3 May be fixed according to the position in the backlog. labels Mar 12, 2024
@engcom-Hotel
Copy link
Contributor

@magento create issue

Copy link

Failed to run the builds. Please try to re-run them later.

@bartekAtconvert
Copy link
Author

@magento run WebAPI Tests

Copy link

Failed to run the builds. Please try to re-run them later.

@bartekAtconvert
Copy link
Author

@magento run Unit Tests

@bartekAtconvert
Copy link
Author

@magento run Static Tests

@bartekAtconvert
Copy link
Author

@magento run Unit Tests

@bartekAtconvert
Copy link
Author

@magento run Static Tests

@bartekAtconvert
Copy link
Author

@magento run WebAPI Tests

@bartekAtconvert
Copy link
Author

@magento run Database Compare

@bartekAtconvert
Copy link
Author

@magento run Static Tests

@bartekAtconvert
Copy link
Author

@magento run WebAPI Tests

@peterjaap
Copy link
Contributor

Ha I was just running into this this week! I was wondering whether it existed.

My usecase; I wanted to add an ifconfig here in events.xml that checks for this config value from system.xml so I didn't have to do this in the observer.

@bartekAtconvert
Copy link
Author

@magento run all tests

@bartekAtconvert
Copy link
Author

@magento run all tests

@bartekAtconvert bartekAtconvert marked this pull request as draft April 25, 2024 10:29
@engcom-Hotel
Copy link
Contributor

@magento run all tests

@engcom-Hotel
Copy link
Contributor

@magento run Functional Tests B2B, Functional Tests EE, Functional Tests CE, Integration Tests, WebAPI Tests

Copy link
Contributor

@engcom-Hotel engcom-Hotel left a comment

Choose a reason for hiding this comment

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

For SVC failure we need to create an approval ticket and other failures seem flaky to me. Hence approving the PR.

@engcom-November
Copy link
Contributor

@bartekAtconvert,

Thank you for the contribution and collaboration!

✔️ QA Passed

Steps to reproduce:

  1. Add ifconfig attribute to Observer A declaration in events.xml file where its value will be config path and dispatch event to trigger Observer.
    a) When config path value equals to true - Observer should execute.
    b) When config path value equals to false - Observer should not execute
    c) When config does not exist (path does not represent any actual value) - Observer should not execute
  2. Add ifconfig attribute to Observer A declaration in events.xml file where its value is empty string "" and dispatch event to trigger Observer. Observer should execute.

Before: ✖️
No ability to condtion the execution of observer.

After: ✔️
Able to conditionalize observer execution.

Created a module with observer, and added ifconfig in events.xml, observer is getting trigerred when config path in ifconfig is true.

Please refer the screenshot:

  • Created a system configuration for ifconfig attribute, when this is enabled or the path for ifconfig is empty the observer is trigerred and it will be logged(for testing purpose).
image log output:
[2024-06-11T10:06:03.927013+00:00] main.DEBUG: custom event Triggered [] []
  • If the config is disabled or if the config path passed to ifconfig is incorrect, the observer will not be trigerred and the value will not be logged.
image

Please find the custom module used to test this PR.
P38493V.zip

Thank you.

@engcom-November
Copy link
Contributor

As the linked issue is tagged as feature request, moving this to on hold for PO confirmation.

@engcom-Charlie
Copy link
Contributor

As the linked issue is tagged as feature request, moving this to on hold for PO confirmation.

We have a confirmation from Product Owner on this feature request issue hence moving it back to Extended Testing.

@engcom-Dash engcom-Dash self-assigned this Dec 20, 2024
@engcom-Dash
Copy link
Contributor

@magento run all tests

@engcom-Dash
Copy link
Contributor

@magento run all tests

@engcom-Dash
Copy link
Contributor

Raised internal approval Jira for the SVC failure. Moving this PR to Pending Approval now. We will proceed ahead on this once will get all the required approvals.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: P3 May be fixed according to the position in the backlog. Progress: ready for testing Project: Community Picked PRs upvoted by the community Triage: Dev.Experience Issue related to Developer Experience and needs help with Triage to Confirm or Reject it
Projects
Status: Pending Approval
Development

Successfully merging this pull request may close these issues.

[Issue] Extend Observer declaration in events.xml by new attribute ifconfig
8 participants