Skip to content

Commit

Permalink
MAGETWO-83145: #9151: [Github] Sitemap.xml: lastmod timestamp can con…
Browse files Browse the repository at this point in the history
…tain invalid dates #11902

 - Merge Pull Request #11902 from serhii-balko/magento2:github-9151
 - Merged commits:
   1. 0212c14
   2. 4177336
  • Loading branch information
dmanners committed Nov 2, 2017
2 parents 148da00 + 4177336 commit 827b6b9
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
*/
private $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 827b6b9

Please sign in to comment.