Ojs2 - oaipmh and getEarliestDatestamp (OJS 2.4.8)

Hi,
it’s me again with another tough one…

We’re trying to harvest our URNs (in epicur format) vie OAI-PMH. Now it turned out, that the Earliest Datestamp provided by /oai?verb=Identify seems not to be correct - there are a lot of older submissions in the system. I tried to trace this back and found, that the function here which inherits from here creates this value. It generates this query as far I can see

SELECT 
    CASE
        WHEN COALESCE(dot.date_deleted, a.last_modified) > i.last_modified THEN i.last_modified
        ELSE COALESCE(dot.date_deleted, a.last_modified)
    END
FROM
    mutex m
        LEFT JOIN
    published_articles pa ON (m.i = 0)
        LEFT JOIN
    articles a ON (a.article_id = pa.article_id)
        LEFT JOIN
    issues i ON (i.issue_id = pa.issue_id)
        LEFT JOIN
    sections s ON (s.section_id = a.section_id)
        LEFT JOIN
    journals j ON (j.journal_id = a.journal_id)
        LEFT JOIN
    data_object_tombstones dot ON (m.i = 1)
        LEFT JOIN
    data_object_tombstone_oai_set_objects tsoj ON tsoj.assoc_id = NULL
        LEFT JOIN
    data_object_tombstone_oai_set_objects tsos ON tsos.assoc_id = NULL
WHERE
    ((s.section_id IS NOT NULL
        AND i.published = 1
        AND j.enabled = 1
        AND a.status <> 0)
        OR dot.data_object_id IS NOT NULL)

An then takes the first result.. Since there is no order by clause in the query, how is this supposed to be the earlieist timestamp? It looks to me, that this might be a bug, and a simple order by clause could fix it - on the other hand, so many projects around the world use OAIPMH with OJS and don’t have this problem, so maybe the integrity of our database is not okay somehow? But how?

Someone have any thoughts about this? Thank you in advance as always for your help.
Best wishes,
Paf

Hi @paf,

What version of OJS are you using? (Please include this in your posts.)

Regards,
Alec Smecher
Public Knowledge Project Team

Hi Alec, the one my Github links are pointing to - GitHub - pkp/pkp-lib at ojs-stable-2_4_8
But yes, sorry, I should have written that explicitly.
Best Wishes

Hi @paf,

Hmm, yes, this does look like a bug. It’s already been resolved in OJS 3.x as part of issue #2407 – however, we’re not likely to back-port that to OJS 2.x. Are you comfortable opening up a pull request to add the necessary ORDER BY?

Regards,
Alec Smecher
Public Knowledge Project Team

Hi @Alec,
I did a pull request now (pkp/pkp-lib#2693 getEarliestDatestamp gets really earliest now by paflov · Pull Request #2567 · pkp/pkp-lib · GitHub), hope I did it right!
Best,
Paflov

Hi @paf,

Excellent – merged, thanks!

Regards,
Alec Smecher
Public Knowledge Project Team