Warning Undefined property: stdClass::$pubDate

Created on 15 May 2025, 22 days ago

Problem/Motivation

Warning: Undefined property: stdClass::$pubDate in Drupal\dkan_rss\DkanRssCreator->dateSort() (line 287 of modules/contrib/dkan_rss/src/DkanRssCreator.php).

It looks like $pubDate is not present. It might need a defensive check.

Steps to reproduce

  1. Not sure of the condition of a dataset that might cause it to not have a pubDate. (still investigating)
  2. Login as admin (maybe enable display of warnings/errors)
  3. visit the datasets.rss
  4. Load a Drupal page, See warnings display, one per dataset. (or look in watchdog)

Proposed resolution

Likely this needs a defensive check.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States swirt Florida

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @swirt
  • πŸ‡ΊπŸ‡ΈUnited States swirt Florida

    This does result in a secondary warning
    Deprecated function: DateTime::__construct(): Passing null to parameter #1 ($datetime) of type string is deprecated in Drupal\dkan_rss\DkanRssCreator->dateSort() (line 287 of modules/contrib/dkan_rss/src/DkanRssCreator.php).

    but that is just the result of having no pubDate

  • πŸ‡©πŸ‡ͺGermany stefan.korn Jossgrund

    Thanks for pointing this out.

    Since the pubDate is defined by a property of the dataset (issued by default) and this property is not necessarily required, it is possible that pubDate is empty. pubDate is also not a required property of an RSS feed. So there should be handling there in case pubDate is empty.

    Question is how to handle an empty pubDate while sorting by date. The php DateTime is using "now" as default. So we could go with that as a default as well. But that seems not suitable, because the sort would change dynamically in time.

    So I think, putting a dataset with empty pubDate at the end of the feed, is probably the best option.

    That said, you can also arrange a different sort (or no sort) if you change the schema json. Removing the "_sort" part altogether would apply no sorting. In that case the sorting is probaby introduced by DKANs retrieveAll().

    Or you can change the sort to another property of the feed, like "title", if you put the "_sort" part like this in the schema json:

      "_sort": {
        "title": "baseSortAsc"
      },

    This would sort the datasets by title from A to Z.

  • πŸ‡©πŸ‡ͺGermany stefan.korn Jossgrund
  • πŸ‡©πŸ‡ͺGermany stefan.korn Jossgrund

    warning should be gone and date sorting fixed like mentioned above, also a small fix for the "desc" sort.

  • πŸ‡ΊπŸ‡ΈUnited States swirt Florida

    Thanks for the background and options. I wonder if there is no pubDate we could provide a fallback by grabbing a reasonable date from some other source like 'modified' or entity->updated, because I do like the concept of having the rss sorted by date.

  • πŸ‡©πŸ‡ͺGermany stefan.korn Jossgrund

    Okay, I will be thinking about this a little more.

    Maybe it would be best to allow to provide one's own sorting function via extending in your own module. I will need to implement a hook or plugin solution for this.

    Another approach outside of DKAN RSS would maybe to control this via dataset schema yourself. Maybe one could introduce a property to the dataset schema, that holds the date as a "computed" value that uses for example issued as first option, modified as second and entity->updated as last resort.

Production build 0.71.5 2024