From 7b8fe3d68a946c62fd55af525b44f1ef9256ab16 Mon Sep 17 00:00:00 2001 From: Steven de Jong Date: Sat, 2 Jun 2018 16:01:30 +0200 Subject: [PATCH 1/7] #15588 Added the appEmulation to get the correct image Url for the generated sitemaps. Context had incorrect Url data. --- .../Controller/Adminhtml/Sitemap/Generate.php | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php index 67d2ce4f4f148..c46733b7d325d 100644 --- a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php +++ b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php @@ -6,8 +6,29 @@ */ namespace Magento\Sitemap\Controller\Adminhtml\Sitemap; +use Magento\Backend\App\Action; +use Magento\Store\Model\App\Emulation; + class Generate extends \Magento\Sitemap\Controller\Adminhtml\Sitemap { + /** @var \Magento\Store\Model\App\Emulation $appEmulation */ + private $appEmulation; + + /** + * Generate constructor. + * @param Action\Context $context + * @param \Magento\Store\Model\App\Emulation $appEmulation + */ + public function __construct( + Action\Context $context, + Emulation $appEmulation + ) { + $this->appEmulation = $appEmulation; + parent::__construct( + $context + ); + } + /** * Generate sitemap * @@ -23,7 +44,13 @@ public function execute() // if sitemap record exists if ($sitemap->getId()) { try { + //We need to emulate to get the correct frontend URL for the product images + $this->appEmulation->startEnvironmentEmulation($sitemap->getStoreId(), + \Magento\Framework\App\Area::AREA_FRONTEND, + true + ); $sitemap->generateXml(); + $this->appEmulation->stopEnvironmentEmulation(); $this->messageManager->addSuccess( __('The sitemap "%1" has been generated.', $sitemap->getSitemapFilename()) From 498047cb31c5e34955e49aa684a7e910c4e7d941 Mon Sep 17 00:00:00 2001 From: Steven de Jong Date: Sat, 2 Jun 2018 21:51:09 +0200 Subject: [PATCH 2/7] #15588 Refactor for code neatness Travis CI. 48 | ERROR | [x] Opening parenthesis of a multi-line function call must be the last content on the line --- .../Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php index c46733b7d325d..4ef67dbabfc15 100644 --- a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php +++ b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php @@ -45,7 +45,8 @@ public function execute() if ($sitemap->getId()) { try { //We need to emulate to get the correct frontend URL for the product images - $this->appEmulation->startEnvironmentEmulation($sitemap->getStoreId(), + $this->appEmulation->startEnvironmentEmulation( + $sitemap->getStoreId(), \Magento\Framework\App\Area::AREA_FRONTEND, true ); From 63ed86492f2bdf5b2410836a71724106f9d137f0 Mon Sep 17 00:00:00 2001 From: Steven de Jong Date: Sun, 3 Jun 2018 02:50:25 +0200 Subject: [PATCH 3/7] Update for Codacy removed whitespace --- .../Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php index 4ef67dbabfc15..819608ee0235d 100644 --- a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php +++ b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php @@ -29,7 +29,7 @@ public function __construct( ); } - /** + /** * Generate sitemap * * @return void From 83ad777b941eff746883a25ad674f97609b5e9c6 Mon Sep 17 00:00:00 2001 From: Steven de Jong Date: Sun, 3 Jun 2018 19:21:08 +0200 Subject: [PATCH 4/7] #15588 Fixed incorrect image urls sitemap Change for travisCI --- .../Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php index 819608ee0235d..6872122cb1013 100644 --- a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php +++ b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php @@ -28,8 +28,8 @@ public function __construct( $context ); } - - /** + + /** * Generate sitemap * * @return void From 6a490a8af822080cca3f35db15ae9ec9f5365205 Mon Sep 17 00:00:00 2001 From: Steven de Jong Date: Wed, 6 Jun 2018 09:02:57 +0200 Subject: [PATCH 5/7] #15588 Fixed incorrect image urls in multistore xml sitemap placed the stop Emulation in a finally. Now it will always be executed. --- .../Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php index 6872122cb1013..9d578c97b0ed7 100644 --- a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php +++ b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php @@ -43,6 +43,7 @@ public function execute() $sitemap->load($id); // if sitemap record exists if ($sitemap->getId()) { + try { //We need to emulate to get the correct frontend URL for the product images $this->appEmulation->startEnvironmentEmulation( @@ -51,7 +52,6 @@ public function execute() true ); $sitemap->generateXml(); - $this->appEmulation->stopEnvironmentEmulation(); $this->messageManager->addSuccess( __('The sitemap "%1" has been generated.', $sitemap->getSitemapFilename()) @@ -60,6 +60,8 @@ public function execute() $this->messageManager->addError($e->getMessage()); } catch (\Exception $e) { $this->messageManager->addException($e, __('We can\'t generate the sitemap right now.')); + } finally { + $this->appEmulation->stopEnvironmentEmulation(); } } else { $this->messageManager->addError(__('We can\'t find a sitemap to generate.')); From f1dd4e838e7eaa12e5b06c78e1ed465a326b05ed Mon Sep 17 00:00:00 2001 From: David Manners Date: Wed, 6 Jun 2018 10:12:56 +0200 Subject: [PATCH 6/7] magento/magento2#15588: Remove extra line from if --- .../Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php index 9d578c97b0ed7..29df85f791a66 100644 --- a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php +++ b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php @@ -43,7 +43,6 @@ public function execute() $sitemap->load($id); // if sitemap record exists if ($sitemap->getId()) { - try { //We need to emulate to get the correct frontend URL for the product images $this->appEmulation->startEnvironmentEmulation( From b7f8d28c83c82268f56b6ccff3082cc9b54d1310 Mon Sep 17 00:00:00 2001 From: David Manners Date: Wed, 6 Jun 2018 11:55:14 +0200 Subject: [PATCH 7/7] magento/magenot2#15588: add dependency in a backwards compatible way --- .../Controller/Adminhtml/Sitemap/Generate.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php index 29df85f791a66..d19b248c8008f 100644 --- a/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php +++ b/app/code/Magento/Sitemap/Controller/Adminhtml/Sitemap/Generate.php @@ -8,6 +8,7 @@ use Magento\Backend\App\Action; use Magento\Store\Model\App\Emulation; +use Magento\Framework\App\ObjectManager; class Generate extends \Magento\Sitemap\Controller\Adminhtml\Sitemap { @@ -17,16 +18,15 @@ class Generate extends \Magento\Sitemap\Controller\Adminhtml\Sitemap /** * Generate constructor. * @param Action\Context $context - * @param \Magento\Store\Model\App\Emulation $appEmulation + * @param \Magento\Store\Model\App\Emulation|null $appEmulation */ public function __construct( Action\Context $context, - Emulation $appEmulation + Emulation $appEmulation = null ) { - $this->appEmulation = $appEmulation; - parent::__construct( - $context - ); + parent::__construct($context); + $this->appEmulation = $appEmulation ?: ObjectManager::getInstance() + ->get(\Magento\Store\Model\App\Emulation::class); } /**