Script for batch editing article publication dates to match issue publication dates in an Open Journal System (OJS) journal
Python script developed for York Digital Journals. Uses the REST API for OJS 3.3.
This script was used to batch edit the publication dates of articles to match the publication dates of the issues in which they are published. It was developed for a born-print journal's archive that was ingested to OJS. The publication dates in OJS matched the ingest dates, not the original publication dates. We wanted to correct the publication dates before registering DOIs for the articles.
At time of publishing, the OJS API does not permit PUT requests to edit issue data. Therefore, we needed to manually edit the issue publication dates via the OJS web interface to input the correct publication dates.
Caution: this script does not account for article versioning. The journal for which this was developed only uses OJS to create and disseminate the digital archive with very little input from the journal editors so no articles have multiple versions. I suspect that versioning will complicate the script when it comes to handling publication IDs.
The API endpoints and tokens are stored in a CSV file with just one row and no columns headers:
- API token
- endpoint URL: GET list of issues
- endpoint URL: GET issue by ID
- endpoint URL: PUT unpublish publication
- endpoint URL: PUT edit publication
- endpoint URL: PUT publish publication
The endpoint URLs include the placeholders {issueId}
, {submissionId}
, and {publicationId}
used in the API reference. The script will contextually replace these with the actual IDs.
The script pulls the token and endpoint URLs by the index position and assigns them to variables.
Get a list of issues in order to extract the issue IDs. Then start a loop that iterates through each issue ID.
Within the loop, get an issue by ID to do two things: get the publication date (and assign it to a variable) and get the submission and publication IDs for all the published articles within that issue. Then start a nested loop that iterates through each article in the issue.
Within the nested loop, unpublish the article using the submission and publication IDs. OJS does not permit editing of a published article.
Still in the nested loop, edit 'datePublished' for the article to match the publication date for the issue.
Still in the nested loop, republish the article.
Print the submission ID, publication ID, unpublish API response code, edit API response code, and published API response code for logging and debugging.
Go to the next article in the issue, or exit the nested loop if none.
Go to the next issue in the list, or exist the loop if none.
The script took 60-90 minutes to run through a 43-issue journal archive (~460 articles).