Skip to content

MAGETWO-2745: added appEmulation Plugin for the $sitemap->generateXml() for generating the sitemap via cron and backend #27476

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

Conversation

dimaMackert
Copy link
Contributor

@dimaMackert dimaMackert commented Mar 27, 2020

Description (*)

I found almost the same issue here: #24605, here you generate the sitemap via backend.
In my case i let generate the sitemap with cron schedule. The problem is i get a wrong cache path, because the \Magento\Sitemap\Model\Observer:scheduledGenerateSitemaps() does not implement the appEmulation->stopEnvironmentEmulation(); like it was fixed in the issue #24605

Manual testing scenarios (*)

  1. Just generate a sitemap via backend
  2. Generate a sitemap via cron
  3. You will see, there are two different cache paths

for example via backend:

/media/catalog/product/cache/cb8ca2a9db68e4f593ce69a9ee07e2b0/p/r/test.png

for example via cron:

/media/catalog/product/cache/9b58a33b64c72152de346a8490e93157/p/r/test.png

with the appEmulation inside the observer, cron and backend generates the same cache path.

Questions or comments

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 are green)

Resolved issues:

  1. resolves [Issue] MAGETWO-2745: added appEmulation Plugin for the $sitemap->generateXml() for generating the sitemap via cron and backend #29605: MAGETWO-2745: added appEmulation Plugin for the $sitemap->generateXml() for generating the sitemap via cron and backend

@m2-assistant
Copy link

m2-assistant bot commented Mar 27, 2020

Hi @dimaMackert. 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 give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

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

* @param Sitemap $subject
* @see \Magento\Sitemap\Model\Sitemap::generateXml
*/
public function beforeGenerateXml(Sitemap $subject)
Copy link
Contributor

@kandy kandy Mar 27, 2020

Choose a reason for hiding this comment

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

Better to use around plugin here
and write code in the way like

 $this->appEmulation->startEnvironmentEmulation(
                    $sitemap->getStoreId(),
                    Area::AREA_FRONTEND,
                    true
                );
             try {
                retrun $proceed();
             } finally {
                $this->appEmulation->stopEnvironmentEmulation();
             }

Copy link
Contributor

Choose a reason for hiding this comment

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

And actually why do not put this directly in generateXml method

Copy link
Contributor

Choose a reason for hiding this comment

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

And actually why do not put this directly in generateXml method

@kandy why do you think Sitemap itself should be responsible for modifying the Application state? I'd say it should be done by the observer.

@ghost ghost assigned kandy Mar 27, 2020
@Stepa4man Stepa4man assigned Stepa4man and unassigned Stepa4man Mar 27, 2020
@Stepa4man Stepa4man self-requested a review March 27, 2020 17:29
@dimaMackert dimaMackert force-pushed the MAGETWO-27458-sitemap-generation-via-cron branch from c90f66b to c56eb37 Compare March 27, 2020 17:41
Comment on lines +126 to 129
$this->appEmulation->stopEnvironmentEmulation();
} catch (\Exception $e) {
$errors[] = $e->getMessage();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
$this->appEmulation->stopEnvironmentEmulation();
} catch (\Exception $e) {
$errors[] = $e->getMessage();
}
} catch (\Exception $e) {
$errors[] = $e->getMessage();
} finally {
$this->appEmulation->stopEnvironmentEmulation();
}

@ghost ghost assigned Stepa4man Mar 28, 2020
Copy link
Contributor

@Stepa4man Stepa4man left a comment

Choose a reason for hiding this comment

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

Hi @dimaMackert
Thanks for your contribution

Please sign CLA and consider suggested changes.

@@ -105,7 +117,13 @@ public function scheduledGenerateSitemaps()
foreach ($collection as $sitemap) {
/* @var $sitemap \Magento\Sitemap\Model\Sitemap */
try {
$this->appEmulation->startEnvironmentEmulation(
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest moving area emulation outside of the foreach statement

@Stepa4man
Copy link
Contributor

Stepa4man commented Mar 28, 2020

@VladimirZaets, could you please check what's going on with tests right now?
I can see that failed functional tests don't relate to this PR

@sidolov sidolov added Priority: P3 May be fixed according to the position in the backlog. Severity: S3 Affects non-critical data or functionality and does not force users to employ a workaround. labels Aug 17, 2020
@sidolov
Copy link
Contributor

sidolov commented Aug 17, 2020

@magento create issue

@sidolov
Copy link
Contributor

sidolov commented Aug 19, 2020

@dimaMackert , I am closing this PR now due to inactivity.
Please reopen and update if you wish to continue.
Thank you for the collaboration!

@sidolov sidolov closed this Aug 19, 2020
@m2-assistant
Copy link

m2-assistant bot commented Aug 19, 2020

Hi @dimaMackert, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Sitemap Partner: TechDivision partners-contribution Pull Request is created by Magento Partner Priority: P3 May be fixed according to the position in the backlog. Progress: needs update 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.

[Issue] MAGETWO-2745: added appEmulation Plugin for the $sitemap->generateXml() for generating the sitemap via cron and backend
5 participants