pkp / pkp-lib

The library used by PKP's applications OJS, OMP and OPS, open source software for scholarly publishing.
https://pkp.sfu.ca
GNU General Public License v3.0
297 stars 443 forks source link

Author sequence in returned API JSON incorrect #7844

Open jnugent opened 2 years ago

jnugent commented 2 years ago

Describe the bug The returned JSON when fetching a publication with an API call of the type:

https://journal.org/index.php/path/api/v1/submissions/xxxxx/publications/xxxxx

Includes the wrong sequence for authors. It sets the seq attribute of all of the authors to the sequence the publication has in the issue. Here is a relevant database record showing the sequence of the publication:

Screenshot at 2022-04-08 11-23-45

And here is the JSON for some of the authors. The author sequence is circled:

authors

I've dumped variables and it seems that this is set this way already, here:

https://github.com/pkp/pkp-lib/blob/3ffbbe19241323fd173cc1d38a847d02a7d91e97/classes/services/PKPPublicationService.inc.php#L171

Sequence is correctly set in the authors table for the record, and the author string is also correct.

Seen in 3.3.0.8

jnugent commented 2 years ago

I've done some more digging in this and I suspect the reason for this is that the QueryBuillder for authors selects * here:

https://github.com/pkp/pkp-lib/blob/3ffbbe19241323fd173cc1d38a847d02a7d91e97/classes/services/queryBuilders/PKPAuthorQueryBuilder.inc.php#L123

And joins on the publications table. Doesn't this potentially create two seq columns in the result? I think it does, and the JSON is including the publication one, rather than the author one.

This query is also used when fetching authors for other purposes like when building the author string but the sort clause is table specific:

https://github.com/pkp/pkp-lib/blob/3ffbbe19241323fd173cc1d38a847d02a7d91e97/classes/services/queryBuilders/PKPAuthorQueryBuilder.inc.php#L169

which is why sorting for authors is fine. It's just when you look at the JSON that there's a problem.