Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can see in the discussion in #9151 the talked about solution would be to show The lastmod value in the xml should contain the created_at timestamp was this changed at some point to show 0000-01-01 00:00:00 instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @dmanners
Magento should not be obliged to respond to incorrectly filled database fields through third-party code. But in the formation of sitemap we must take into account the case when the lastmod has zero value.
In the case of the #9151, the field "created_at" may also contain a zero value, and the issue remains.
So I decided that is the better solution.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the update that has clarified it nicely.

{
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