prestaconcept/PrestaSitemapBundle

Urlset->add() doesn't use Url->lastmod() for the Urlset lastmod

Closed this issue · 3 comments

PHP version(s) affected: 8.2.13

Package version(s) affected: 3.3.1

Description

$set = new Urlset('/sitemap-set.xml');
$set->add(new UrlConcrete('http://example.com', new \DateTimeImmutable('2021-12-31 00:00:00'));
$set->add(new UrlConcrete('http://example.com', new \DateTimeImmutable('2022-12-31 00:00:00'));
$set->add(new UrlConcrete('http://example.com', new \DateTimeImmutable('2023-12-08 00:00:00'));

var_dump($set->getLastmod()); // should use the latest timestamp, but uses "now"

How to reproduce

See above.

Possible Solution

Set the lastmod on each added URL if higher than current.

Additional Context

This allows reproducible builds for sitemaps, for example in functional tests.

Hello, thanks for the report
Seems that you are using the code by yourself, and Urlset as a constructor arg to acquire the lastmod
The "now" value is a fallback when you provide nothing

On the other hand, the bundle tries to provide a value from children when dumping it
Have you also the issue while using the bundle and not the API?

@yann-eugone I'm not using the bundle fully, I'm using the Urlset as I'm streaming through my dataset. Since the Urlset is a collection of Url, it stands to reason it itself doesn't have a last modified, the URLs it contains do, and its last modified is the most recent last modified of any URL it contains, no?

I understand your point, but because it is not a bug in the bundle itself, and because I'm unsure of the potential side effects of adding such change in the Urlset at runtime, I will close this issue.

I suggest you find a workaround on your side to recreate the Urlset after you get the date you want.