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

Images in XML sitemap are always linked to base store in multistore on Schedule #19598

Merged
merged 9 commits into from
Feb 13, 2019
25 changes: 22 additions & 3 deletions app/code/Magento/Sitemap/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
namespace Magento\Sitemap\Model;

use Magento\Store\Model\App\Emulation;

/**
Nazar65 marked this conversation as resolved.
Show resolved Hide resolved
* Sitemap module observer
*
Expand Down Expand Up @@ -67,24 +69,33 @@ class Observer
protected $inlineTranslation;

/**
* @var \Magento\Store\Model\App\Emulation $appEmulation
Nazar65 marked this conversation as resolved.
Show resolved Hide resolved
*/
private $appEmulation;

/**
* Observer constructor.
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Magento\Sitemap\Model\ResourceModel\Sitemap\CollectionFactory $collectionFactory
* @param ResourceModel\Sitemap\CollectionFactory $collectionFactory
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder
* @param \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation
* @param Emulation|null $appEmulation
*/
public function __construct(
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Sitemap\Model\ResourceModel\Sitemap\CollectionFactory $collectionFactory,
ResourceModel\Sitemap\CollectionFactory $collectionFactory,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\Mail\Template\TransportBuilder $transportBuilder,
\Magento\Framework\Translate\Inline\StateInterface $inlineTranslation
\Magento\Framework\Translate\Inline\StateInterface $inlineTranslation,
Emulation $appEmulation
Copy link
Member

Choose a reason for hiding this comment

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

This new parameter should be optional

Copy link
Member Author

Choose a reason for hiding this comment

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

Same here if i add optional, as this have been in older commit the codeMess test will fail.
Backward Compatibility Policy is not applied to Plugins, Observers and Setup Scripts.

Copy link
Member Author

Choose a reason for hiding this comment

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

The class Observer has a coupling between objects value of 13.

) {
$this->_scopeConfig = $scopeConfig;
$this->_collectionFactory = $collectionFactory;
$this->_storeManager = $storeManager;
$this->_transportBuilder = $transportBuilder;
$this->inlineTranslation = $inlineTranslation;
$this->appEmulation = $appEmulation;
}

/**
Expand Down Expand Up @@ -112,9 +123,17 @@ public function scheduledGenerateSitemaps()
foreach ($collection as $sitemap) {
/* @var $sitemap \Magento\Sitemap\Model\Sitemap */
try {
$this->appEmulation->startEnvironmentEmulation(
$sitemap->getStoreId(),
'frontend',
Copy link
Member

Choose a reason for hiding this comment

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

Please use the constant

Copy link
Member Author

Choose a reason for hiding this comment

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

This Class have many dependency, so if i will use constant the codeMess test will fail.

Copy link
Member

Choose a reason for hiding this comment

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

In this case it's better to decompose the class in favour to dropping constant usage

true
);

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

Expand Down