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

Conversation

Nazar65
Copy link
Member

@Nazar65 Nazar65 commented Dec 6, 2018

Description (*)

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

Fixed Issues (if relevant)

  1. Images in XML sitemap are always linked to base store in multistore on Schedule  #19596: Images in XML sitemap are always linked to base store in multistore on Schedule
  2. ...

Manual testing scenarios (*)

Website URL 1: https://my_website.com
Website URL 2: https://my_website.co.uk

Got to Stores->Configuration->Catalog->XML Sitemap->General Settings:
2.Set to Enable, Start Time, Frequency Daily etc...
TIP: I've set to a few minutes before checking!

Website 1 should have images url referencing Website 1 domain = https://my_website.com

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 on Travis CI are green)

@magento-engcom-team
Copy link
Contributor

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

For more details, please, review the Magento Contributor Assistant documentation

Copy link
Member

@sivaschenko sivaschenko left a comment

Choose a reason for hiding this comment

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

@Nazar65 thanks for the contribution. Please see the code review notes.

@@ -67,13 +69,21 @@ class Observer
protected $inlineTranslation;

/**
* @var \Magento\Store\Model\App\Emulation $appEmulation
*/
protected $appEmulation;
Copy link
Member

Choose a reason for hiding this comment

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

please change the access level to private

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

app/code/Magento/Sitemap/Model/Observer.php Outdated Show resolved Hide resolved
app/code/Magento/Sitemap/Model/Observer.php Show resolved Hide resolved
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\Mail\Template\TransportBuilder $transportBuilder
* @param \Magento\Framework\Translate\Inline\StateInterface $inlineTranslation
*/
public function __construct(
Emulation $appEmulation = null,
Copy link
Member

Choose a reason for hiding this comment

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

Please add move the new parameter to the last position in the parameters list

Copy link
Member Author

Choose a reason for hiding this comment

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

ok.

@sivaschenko sivaschenko self-assigned this Dec 7, 2018
@Nazar65
Copy link
Member Author

Nazar65 commented Dec 7, 2018

@sivaschenko all done.

Copy link
Member

@sivaschenko sivaschenko left a comment

Choose a reason for hiding this comment

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

@Nazar65 thanks for your updates, please see remaining review notes

app/code/Magento/Sitemap/Model/Observer.php Outdated Show resolved Hide resolved
\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.

@@ -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

@Nazar65
Copy link
Member Author

Nazar65 commented Dec 7, 2018

@sivaschenko please look at comments.

@sivaschenko
Copy link
Member

Hi @Nazar65 , I think the best way to resolve the problems with static tests and keep the good code style and backward compatibility - is extracting all the business logic to a model from the observer. Actually, this observer is a very good candidate for refactoring. Could you extract it?

@Nazar65
Copy link
Member Author

Nazar65 commented Dec 7, 2018

@sivaschenko yes i agree with you. I'm will work on this :)

@Nazar65
Copy link
Member Author

Nazar65 commented Dec 11, 2018

Hi @sivaschenko can you please look at newly commit ?

Copy link
Member

@sivaschenko sivaschenko left a comment

Choose a reason for hiding this comment

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

Hi @Nazar65 , thanks for your refactoring! It looks great, however, I have some imporvement suggestions. Please see my code review notes.

@@ -24,21 +31,6 @@ class Observer
*/
const XML_PATH_CRON_EXPR = 'crontab/default/jobs/generate_sitemaps/schedule/cron_expr';

/**
Copy link
Member

Choose a reason for hiding this comment

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

Please keep all existing constants in the Observer as they could be already used by third-party extensions.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok.

*/
protected $_transportBuilder;
protected $_storeManager;
Copy link
Member

Choose a reason for hiding this comment

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

I'd change all properties to private and remove the "_" prefix (for consistency and to be compatible with PSR)

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

$transport->sendMessage();

$this->inlineTranslation->resume();
$this->sitemapEmail->sendErrorEmail($errors);
Copy link
Member

Choose a reason for hiding this comment

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

Please call this method after the foreach (as all the errors have to be accumulated in $errors first)

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

self::XML_PATH_ERROR_RECIPIENT,
ScopeInterface::SCOPE_STORE
);
if ($errors && $recipient) {
Copy link
Member

Choose a reason for hiding this comment

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

I'd move this condition to the observer or to a separate method, to keep this method solid

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

*
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
private $_scopeConfig;
Copy link
Member

Choose a reason for hiding this comment

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

Property should not be prefixed with a single underscore, see https://www.php-fig.org/psr/psr-2/#42-properties

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

@@ -0,0 +1,109 @@
<?php
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 strict mode in for all new PHP files

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

\Magento\Framework\Translate\Inline\StateInterface $inlineTranslation
ScopeConfigInterface $scopeConfig,
CollectionFactory $collectionFactory,
StoreManagerInterface $storeManager,
Copy link
Member

Choose a reason for hiding this comment

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

Neither of two classes appears to be using store manager, so I think this dependency can be removed from both of them

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

if ($errors && $recipient) {
$this->inlineTranslation->suspend();

$this->_transportBuilder->setTemplateIdentifier(
Copy link
Member

Choose a reason for hiding this comment

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

I think it may be beneficial to wrap the email send operation in a try-catch block to gracefully handle situations when a mail server is not responsive.

There is an example here

$this->inlineTranslation->suspend();
try {
$transport = $this->transportBuilder
->setTemplateIdentifier($this->contactsConfig->emailTemplate())
->setTemplateOptions(
[
'area' => Area::AREA_FRONTEND,
'store' => $this->storeManager->getStore()->getId()
]
)
->setTemplateVars($variables)
->setFrom($this->contactsConfig->emailSender())
->addTo($this->contactsConfig->emailRecipient())
->setReplyTo($replyTo, $replyToName)
->getTransport();
$transport->sendMessage();
} finally {
$this->inlineTranslation->resume();
}

However, I would improve the approach by catching an exception and writing it to an exception log

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

/**
* Sends emails for the scheduled generation of the sitemap file
*/
class SitemapSendEmail
Copy link
Member

Choose a reason for hiding this comment

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

I'd rename the class to the something like EmailNotification or Mail and the method to send or sendErrors to avoid duplicate wording in full method reference. Currently it's Magento\Sitemap\Model\SitemapSendEmail::sendErrorEmail

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

@Nazar65
Copy link
Member Author

Nazar65 commented Dec 12, 2018

Hi @sivaschenko all done. :)

Copy link
Member

@sivaschenko sivaschenko left a comment

Choose a reason for hiding this comment

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

Hi @Nazar65 thanks for the refactoring! I've added some code suggestions. You can simply add all my suggestions to batch and commit them.

@Nazar65
Copy link
Member Author

Nazar65 commented Dec 12, 2018

@sivaschenko all done, thank you for the review :)

@sivaschenko
Copy link
Member

Thank you @Nazar65 finally there are currently 14 commits, would you like to squash them into a single one?

@Nazar65
Copy link
Member Author

Nazar65 commented Dec 12, 2018

@sivaschenko sorry for that, now i "squash" to one commit.

@magento-engcom-team magento-engcom-team added this to the Release: 2.3.1 milestone Dec 12, 2018
@magento-engcom-team
Copy link
Contributor

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

@Nazar65
Copy link
Member Author

Nazar65 commented Jan 17, 2019

@sivaschenko @sidolov so do I change the variables again?

@magento-engcom-team
Copy link
Contributor

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

@Nazar65
Copy link
Member Author

Nazar65 commented Feb 7, 2019

HI @sivaschenko @sidolov any updates ?

@sivaschenko
Copy link
Member

Hi @Nazar65 the pull request is in queue for delivery to mainline

@ghost
Copy link

ghost commented Feb 13, 2019

Hi @Nazar65, 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants