hepdata
hepdata copied to clipboard
records: provide a CLI command to change or remove the INSPIRE ID of a record
Occasional requests are made to change the INSPIRE ID of a record, for example, from a preliminary note (e.g. 1643435) to the corresponding final publication (e.g. 1664330). So far I've dealt with these requests manually by executing a combination of SQL, Python, and CLI commands. This is a cumbersome procedure and it would be better to provide a single CLI command that performs the following steps to replace an old_inspire_id
with a new_inspire_id
for a given publication_recid
.
- Replace
inspire_id
in the HEPSubmission object (or objects if more than one version) with the givenpublication_recid
. - Update
last_updated
in the HEPSubmission object to the current timestamp (e.g.timezone('utc', now())::timestamp(4)
) so that the record will be picked up by the nightly INSPIRE harvesting job. - Replace
publication_inspire_id
in the DataSubmission objects with the samepublication_recid
. - Get a list of
associated_recid
values for all the DataSubmission objects with the samepublication_recid
. - Update the INSPIRE ID and last updated timestamp in the record metadata, i.e. something like:
from hepdata.modules.records.utils.common import get_record_by_id
from hepdata.modules.submission.api import get_latest_hepsubmission
from invenio_db import db
from datetime import datetime
hepsubmission = get_latest_hepsubmission(publication_recid=publication_recid)
last_updated = datetime.strftime(hepsubmission.last_updated, '%Y-%m-%d %H:%M:%S')
for recid in recids:
record = get_record_by_id(recid)
record['inspire_id'] = int(new_inspire_id)
record['last_updated'] = last_updated
record.commit()
db.session.commit()
Here recids
is a list of all publication_recid
values of the HEPSubmission objects and all associated_recid
values of the DataSubmission objects.
- Call
update_record_info
fromhepdata.modules.records.utils.records_update_utils
withnew_inspire_id
as the first argument and an optional second argument to send an email to the original submission participants. - Delete any cached files in the
converted
directory withold_inspire_id
in the filenames.