hepdata icon indicating copy to clipboard operation
hepdata copied to clipboard

records: provide a CLI command to change or remove the INSPIRE ID of a record

Open GraemeWatt opened this issue 3 years ago • 4 comments

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.

  1. Replace inspire_id in the HEPSubmission object (or objects if more than one version) with the given publication_recid.
  2. 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.
  3. Replace publication_inspire_id in the DataSubmission objects with the same publication_recid.
  4. Get a list of associated_recid values for all the DataSubmission objects with the same publication_recid.
  5. 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.

  1. Call update_record_info from hepdata.modules.records.utils.records_update_utils with new_inspire_id as the first argument and an optional second argument to send an email to the original submission participants.
  2. Delete any cached files in the converted directory with old_inspire_id in the filenames.

GraemeWatt avatar Jan 07 '21 21:01 GraemeWatt