Skip to content

Commit 4ab5194

Browse files
MAGETWO-83145: #9151: [Github] Sitemap.xml: lastmod timestamp can contain invalid dates #11902
2 parents 1df94b3 + 827b6b9 commit 4ab5194

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
@@ -43,6 +43,11 @@ class Sitemap extends \Magento\Framework\Model\AbstractModel implements \Magento
4343

4444
const TYPE_URL = 'url';
4545

46+
/**
47+
* Last mode date min value
48+
*/
49+
const LAST_MOD_MIN_VAL = '0000-01-01 00:00:00';
50+
4651
/**
4752
* Real file path
4853
*
@@ -157,6 +162,13 @@ class Sitemap extends \Magento\Framework\Model\AbstractModel implements \Magento
157162
*/
158163
protected $_cacheTag = true;
159164

165+
/**
166+
* Last mode min timestamp value
167+
*
168+
* @var int
169+
*/
170+
private $lastModMinTsVal;
171+
160172
/**
161173
* Initialize dependencies.
162174
*
@@ -661,7 +673,11 @@ protected function _getMediaUrl($url)
661673
*/
662674
protected function _getFormattedLastmodDate($date)
663675
{
664-
return date('c', strtotime($date));
676+
if ($this->lastModMinTsVal === null) {
677+
$this->lastModMinTsVal = strtotime(self::LAST_MOD_MIN_VAL);
678+
}
679+
$timestamp = max(strtotime($date), $this->lastModMinTsVal);
680+
return date('c', $timestamp);
665681
}
666682

667683
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ protected function _getModelMock($mockBeforeSave = false)
540540
$this->returnValue(
541541
[
542542
new \Magento\Framework\DataObject(
543-
['url' => 'product.html', 'updated_at' => '2012-12-21 00:00:00']
543+
['url' => 'product.html', 'updated_at' => '0000-00-00 00:00:00']
544544
),
545545
new \Magento\Framework\DataObject(
546546
[

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)