Skip to content

Use tmp folder from Magento installation to prevent path collisions #34272

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

Merged

Conversation

alinalexandru
Copy link
Member

Description (*)

Use tmp folder relative to magento installation, instead of using the system tmp.
SYS_TMP is defined \Magento\Framework\Filesystem\DirectoryList, but \Magento\Framework\App\Filesystem\DirectoryList is used in \Magento\Analytics\Model\ExportDataHandler, so it means we can us TMP constant.
In this way, every magento2 installation will not interfere with each other.

Fixed Issues (if relevant)

  1. Fixes Hardcoded path causes collisions #29373

Manual testing scenarios (*)

I see 2 ways to do manual test, as cron cleans everything during execution

  1. Follow the steps from Hardcoded path causes collisions #29373 (comment)
  2. Comment the finaly block from \Magento\Analytics\Model\ExportDataHandler

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)

@m2-assistant
Copy link

m2-assistant bot commented Oct 7, 2021

Hi @alinalexandru. Thank you for your contribution
Here are 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 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

ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

For more details, please, review the Magento Contributor Guide documentation.

⚠️ According to the Magento Contribution requirements, all Pull Requests must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting.

🕙 You can find the schedule on the Magento Community Calendar page.

📞 The triage of Pull Requests happens in the queue order. If you want to speed up the delivery of your contribution, please join the Community Contributions Triage session to discuss the appropriate ticket.

🎥 You can find the recording of the previous Community Contributions Triage on the Magento Youtube Channel

✏️ Feel free to post questions/proposals/feedback related to the Community Contributions Triage process to the corresponding Slack Channel

@alinalexandru
Copy link
Member Author

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@ihor-sviziev
Copy link
Contributor

@magento run all tests

@ihor-sviziev ihor-sviziev self-assigned this Oct 7, 2021
@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@ihor-sviziev ihor-sviziev added Severity: S1 Affects critical data or functionality and forces users to employ a workaround. Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Award: bug fix Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. and removed Severity: S1 Affects critical data or functionality and forces users to employ a workaround. labels Oct 7, 2021
@ihor-sviziev ihor-sviziev changed the title #29373: Hardcoded path causes collisions Use tmp folder from Magento installation to prevent path collisions Oct 7, 2021
@alinalexandru
Copy link
Member Author

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

Copy link
Contributor

@ihor-sviziev ihor-sviziev left a comment

Choose a reason for hiding this comment

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

Please fix failing static tests

@alinalexandru
Copy link
Member Author

@magento run Static Tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@alinalexandru
Copy link
Member Author

@ihor-sviziev Fixed

@ihor-sviziev
Copy link
Contributor

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

Copy link
Contributor

@Den4ik Den4ik left a comment

Choose a reason for hiding this comment

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

Hi @alinalexandru
Thanks for PR. Please look at my comment

@@ -106,8 +106,10 @@ public function prepareExportData()
$this->cryptographer->encode($tmpDirectory->readFile($this->getArchiveRelativePath()))
);
} finally {
$tmpDirectory->delete($this->getTmpFilesDirRelativePath());
$tmpDirectory->delete($this->getArchiveRelativePath());
if (isset($tmpDirectory) && $tmpDirectory instanceof WriteInterface) {
Copy link
Contributor

Choose a reason for hiding this comment

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

$tmpDirecory always will be WriteInterface and check $tmpDirectory instanceof WriteInterface is unnecessary

@magento-engcom-team
Copy link
Contributor

Hi @ihor-sviziev, thank you for the review.
ENGCOM-9245 has been created to process this Pull Request

Copy link
Contributor

@Den4ik Den4ik left a comment

Choose a reason for hiding this comment

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

✅ Looks good for me. All tests passed

@magento-engcom-team
Copy link
Contributor

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

@sidolov sidolov added the Priority: P3 May be fixed according to the position in the backlog. label Oct 28, 2021
@sidolov
Copy link
Contributor

sidolov commented Nov 3, 2021

@magento convert to patch for 2.4.3

@m2-github-services
Copy link
Collaborator

@sidolov changes has been successfully converted for 2.4.3 version and pushed to the converted-magento-magento2-2.4.3 branch.

You may submit a pull request using the link: 2.4.3-release...magento:converted-magento-magento2-2.4.3

1 similar comment
@m2-github-services
Copy link
Collaborator

@sidolov changes has been successfully converted for 2.4.3 version and pushed to the converted-magento-magento2-2.4.3 branch.

You may submit a pull request using the link: 2.4.3-release...magento:converted-magento-magento2-2.4.3

@slavvka
Copy link
Member

slavvka commented Nov 10, 2021

@magento run all tests

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

1 similar comment
@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@Den4ik
Copy link
Contributor

Den4ik commented Nov 12, 2021

@magento run Functional Tests EE

@magento-automated-testing
Copy link

The requested builds are added to the queue. You should be able to see them here within a few minutes. Please re-request them if they don't show in a reasonable amount of time.

@sidolov sidolov added Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. and removed Priority: P3 May be fixed according to the position in the backlog. labels Apr 21, 2022
@engcom-Alfa engcom-Alfa self-assigned this Apr 27, 2022
@engcom-Lima
Copy link
Contributor

Hi @alinalexandru , @Den4ik , @ihor-sviziev Thanks for your contribution and collaboration .
Tried reproducing the issue in 2.4-develop version before testing the given PR fix code referring PR description/ comments.
Issue is not reproducible and below is the information on this:

Pre Conditions

  1. Installed two magento instances with 2.4-develop version in my local with sample data.
  2. Used PHP 7.4.29 version in my ubuntu system.

Reproducible steps

  1. Followed the given steps in first magento instance issue comment
  2. Repeated same steps in 2nd Magento instance as well.
  3. Commented the finally block from \Magento\Analytics\Model\ExportDataHandler in both the instances.
  4. Cross checked the given path /tmp/analytics/tmp/ in the local system .

Observation - Analytics folder was not found in the given path /tmp/analytics/tmp/

Kindly let me know based on what factors files will get generated in given path, So, that we can proceed further in our testing.

@engcom-Alfa
Copy link
Contributor

engcom-Alfa commented Jun 3, 2022

✔️ QA Passed

Preconditions:

  1. Should use the local system in which we should have all Magento instance relevant installed.
  2. We should have 2 Magento latest versioned instances in the same system to test.

Manual testing scenario:

  1. There are code changes done in 2 of the php files commented here, we should do the same code changes in both the instances of our Magento local code.
  2. Download the n98-magerun2-latest.phar file from here.
  3. Rename the file n98-magerun2-latest.phar to n98-magerun2.phar.
  4. Copy the downloaded file inside both the local Magento instances' root folder.
  5. Run the command php -d upload_tmp_dir=/tmp n98-magerun2.phar sys:cron:run analytics_collect_data from the Magento root folder of both instances one by one.

Before: ✖️ The responded command used to return the folder path from both the instances which is a common local system TEMP folder.
image

After: ✔️ The responded command returns the folder path from both the instances which is a unique <Magento_root>/var/ folder of each Magento instance only.
image

Since it is a specific case where the reporting folder has been changed, and so no additional regression test case are required for this case.
Note: I think, it is good to have the Magento doc to be updated with this information, even I couldn't find any info relevant to it as of now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Tests: Covered All changes in Pull Request is covered by auto-tests Award: bug fix Component: Analytics mmro-contribution-day2021 Priority: P1 Once P0 defects have been fixed, a defect having this priority is the next candidate for fixing. Progress: accept Release Line: 2.4 Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hardcoded path causes collisions