-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Hi @dimaMackert. Thank you for your contribution
For more details, please, review the Magento Contributor Guide documentation. |
* @param Sitemap $subject | ||
* @see \Magento\Sitemap\Model\Sitemap::generateXml | ||
*/ | ||
public function beforeGenerateXml(Sitemap $subject) |
There was a problem hiding this comment.
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();
}
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
c90f66b
to
c56eb37
Compare
$this->appEmulation->stopEnvironmentEmulation(); | ||
} catch (\Exception $e) { | ||
$errors[] = $e->getMessage(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$this->appEmulation->stopEnvironmentEmulation(); | |
} catch (\Exception $e) { | |
$errors[] = $e->getMessage(); | |
} | |
} catch (\Exception $e) { | |
$errors[] = $e->getMessage(); | |
} finally { | |
$this->appEmulation->stopEnvironmentEmulation(); | |
} |
There was a problem hiding this 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( |
There was a problem hiding this comment.
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
@VladimirZaets, could you please check what's going on with tests right now? |
@magento create issue |
@dimaMackert , I am closing this PR now due to inactivity. |
Hi @dimaMackert, thank you for your contribution! |
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 (*)
for example via backend:
for example via cron:
with the appEmulation inside the observer, cron and backend generates the same cache path.
Questions or comments
Contribution checklist (*)
Resolved issues: