Skip to content

Commit

Permalink
magento#9151: [Github] Sitemap.xml: lastmod timestamp can contain inv…
Browse files Browse the repository at this point in the history
…alid dates
  • Loading branch information
serhii-balko committed Oct 31, 2017
1 parent 4d26093 commit 0212c14
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 @@ -43,6 +43,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 @@ -157,6 +162,13 @@ class Sitemap extends \Magento\Framework\Model\AbstractModel implements \Magento
*/
protected $_cacheTag = true;

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

/**
* Initialize dependencies.
*
Expand Down Expand Up @@ -661,7 +673,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 @@ -540,7 +540,7 @@ protected function _getModelMock($mockBeforeSave = false)
$this->returnValue(
[
new \Magento\Framework\DataObject(
['url' => 'product.html', 'updated_at' => '2012-12-21 00:00:00']
['url' => 'product.html', 'updated_at' => '0000-00-00 00:00:00']
),
new \Magento\Framework\DataObject(
[
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 0212c14

Please sign in to comment.