Skip to content

Commit 57318bf

Browse files
committed
Forwardport of #11902 to 2.3-develop branch
1 parent 8e77e2f commit 57318bf

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

app/code/Magento/Sitemap/Model/Sitemap.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ class Sitemap extends \Magento\Framework\Model\AbstractModel implements \Magento
4242

4343
const TYPE_URL = 'url';
4444

45+
/**
46+
* Last mode date min value
47+
*/
48+
const LAST_MOD_MIN_VAL = '0000-01-01 00:00:00';
49+
4550
/**
4651
* Real file path
4752
*
@@ -177,6 +182,13 @@ class Sitemap extends \Magento\Framework\Model\AbstractModel implements \Magento
177182
*/
178183
private $sitemapItemFactory;
179184

185+
/**
186+
* Last mode min timestamp value
187+
*
188+
* @var int
189+
*/
190+
private $lastModMinTsVal;
191+
180192
/**
181193
* Initialize dependencies.
182194
*
@@ -694,7 +706,11 @@ protected function _getMediaUrl($url)
694706
*/
695707
protected function _getFormattedLastmodDate($date)
696708
{
697-
return date('c', strtotime($date));
709+
if ($this->lastModMinTsVal === null) {
710+
$this->lastModMinTsVal = strtotime(self::LAST_MOD_MIN_VAL);
711+
}
712+
$timestamp = max(strtotime($date), $this->lastModMinTsVal);
713+
return date('c', $timestamp);
698714
}
699715

700716
/**

app/code/Magento/Sitemap/Test/Unit/Model/SitemapTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ protected function getModelMock($mockBeforeSave = false)
527527
->willReturn([
528528
new SitemapItem('category.html', '1.0', 'daily', '2012-12-21 00:00:00'),
529529
new SitemapItem('/category/sub-category.html', '1.0', 'daily', '2012-12-21 00:00:00'),
530-
new SitemapItem('product.html', '0.5', 'monthly', '2012-12-21 00:00:00'),
530+
new SitemapItem('product.html', '0.5', 'monthly', '0000-00-00 00:00:00'),
531531
new SitemapItem(
532532
'product2.html',
533533
'0.5',

app/code/Magento/Sitemap/Test/Unit/Model/_files/sitemap-1-3.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
1111
<url>
1212
<loc>http://store.com/product.html</loc>
13-
<lastmod>2012-12-21T00:00:00-08:00</lastmod>
13+
<lastmod>0000-01-01T00:00:00-08:00</lastmod>
1414
<changefreq>monthly</changefreq>
1515
<priority>0.5</priority>
1616
</url>

app/code/Magento/Sitemap/Test/Unit/Model/_files/sitemap-single.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
</url>
2323
<url>
2424
<loc>http://store.com/product.html</loc>
25-
<lastmod>2012-12-21T00:00:00-08:00</lastmod>
25+
<lastmod>0000-01-01T00:00:00-08:00</lastmod>
2626
<changefreq>monthly</changefreq>
2727
<priority>0.5</priority>
2828
</url>

0 commit comments

Comments
 (0)