Skip to content

Commit

Permalink
Forwardport of #11902 to 2.3-develop branch
Browse files Browse the repository at this point in the history
  • Loading branch information
serhii-balko committed Jan 24, 2018
1 parent 8e77e2f commit 57318bf
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 57318bf

Please sign in to comment.