Skip to content

Commit

Permalink
Merge forwardport of #11902 to 2.3-develop branch
Browse files Browse the repository at this point in the history
Applied pull request patch https://github.com/magento/magento2/pull/11902.patch (created by @serhii-balko) based on commit(s):
  1. 0212c14
  2. 4177336

Fixed GitHub Issues in 2.3-develop branch:
  - #9151: Sitemap.xml: lastmod timestamp can contain invalid dates (reported by @hostep)
  • Loading branch information
magento-engcom-team authored Feb 5, 2018
2 parents 15d1a96 + 57318bf commit 63b9e90
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
18 changes: 17 additions & 1 deletion app/code/Magento/Sitemap/Model/Sitemap.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class Sitemap extends \Magento\Framework\Model\AbstractModel implements \Magento

const TYPE_URL = 'url';

/**
* Last mode date min value
*/
const LAST_MOD_MIN_VAL = '0000-01-01 00:00:00';

/**
* Real file path
*
Expand Down Expand Up @@ -177,6 +182,13 @@ class Sitemap extends \Magento\Framework\Model\AbstractModel implements \Magento
*/
private $sitemapItemFactory;

/**
* Last mode min timestamp value
*
* @var int
*/
private $lastModMinTsVal;

/**
* Initialize dependencies.
*
Expand Down Expand Up @@ -694,7 +706,11 @@ protected function _getMediaUrl($url)
*/
protected function _getFormattedLastmodDate($date)
{
return date('c', strtotime($date));
if ($this->lastModMinTsVal === null) {
$this->lastModMinTsVal = strtotime(self::LAST_MOD_MIN_VAL);
}
$timestamp = max(strtotime($date), $this->lastModMinTsVal);
return date('c', $timestamp);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Sitemap/Test/Unit/Model/SitemapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ protected function getModelMock($mockBeforeSave = false)
->willReturn([
new SitemapItem('category.html', '1.0', 'daily', '2012-12-21 00:00:00'),
new SitemapItem('/category/sub-category.html', '1.0', 'daily', '2012-12-21 00:00:00'),
new SitemapItem('product.html', '0.5', 'monthly', '2012-12-21 00:00:00'),
new SitemapItem('product.html', '0.5', 'monthly', '0000-00-00 00:00:00'),
new SitemapItem(
'product2.html',
'0.5',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
<url>
<loc>http://store.com/product.html</loc>
<lastmod>2012-12-21T00:00:00-08:00</lastmod>
<lastmod>0000-01-01T00:00:00-08:00</lastmod>
<changefreq>monthly</changefreq>
<priority>0.5</priority>
</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</url>
<url>
<loc>http://store.com/product.html</loc>
<lastmod>2012-12-21T00:00:00-08:00</lastmod>
<lastmod>0000-01-01T00:00:00-08:00</lastmod>
<changefreq>monthly</changefreq>
<priority>0.5</priority>
</url>
Expand Down

0 comments on commit 63b9e90

Please sign in to comment.