def do_upgrade(): """ Implement your upgrades here """ from invenio.modules.workflows.models import BibWorkflowObject from invenio.modules.workflows.engine import ObjectVersion, WorkflowStatus from lw_daap.modules.invenio_deposit.models import Deposition for o in BibWorkflowObject.query.filter( BibWorkflowObject.id_user != 0).all(): d = Deposition(o) if is_error(d): warn(o, 'ERROR', "run workflow") sip = d.get_latest_sip(sealed=False) for k in ['first_author', 'additional_authors']: if k in sip.metadata: sip.metadata['_%s' % k] = sip.metadata[k] del sip.metadata[k] d.run_workflow(headless=True) elif is_done(d): if (o.version != ObjectVersion.COMPLETED or o.workflow.status != WorkflowStatus.COMPLETED): if (o.version == ObjectVersion.HALTED and o.workflow.status == ObjectVersion.HALTED): warn( o, 'DONE', "wf status %s -> %s" % (o.workflow.status, WorkflowStatus.COMPLETED)) warn( o, 'DONE', "obj version %s -> %s" % (o.version, ObjectVersion.COMPLETED)) o.workflow.status = WorkflowStatus.COMPLETED o.version = ObjectVersion.COMPLETED elif (o.version == ObjectVersion.COMPLETED and o.workflow.status == 5): warn( o, 'DONE', "wf status %s -> %s" % (o.workflow.status, WorkflowStatus.COMPLETED)) o.workflow.status = WorkflowStatus.COMPLETED elif (o.version == ObjectVersion.HALTED and o.workflow.status == WorkflowStatus.COMPLETED): warn( o, 'DONE', "obj version %s -> %s" % (o.version, ObjectVersion.COMPLETED)) o.version = ObjectVersion.COMPLETED else: warn( o, 'DONE', "Unmatched version %s status %s" % (o.version, o.workflow.status if o.workflow else None)) else: info_msg(o, 'DONE') elif is_inprogress(d): if is_submitted(d): if (o.version == ObjectVersion.HALTED and o.workflow.status == WorkflowStatus.HALTED): info_msg(o, 'INPROGRESS/SUBMITTED') elif (o.version == ObjectVersion.INITIAL and o.workflow.status == WorkflowStatus.NEW): info_msg(o, 'INPROGRESS/SUBMITTED') elif (o.version == ObjectVersion.HALTED and o.workflow.status == WorkflowStatus.COMPLETED): warn( o, 'INPROGRESS/SUBMITTED', "wf status %s -> %s" % (o.workflow.status, WorkflowStatus.HALTED)) o.workflow.status = WorkflowStatus.HALTED else: warn( o, 'INPROGRESS/SUBMITTED', "Unmatched version %s status %s" % (o.version, o.workflow.status if o.workflow else None)) elif is_unsubmitted(d): if o.workflow is None: if o.version != ObjectVersion.INITIAL: warn( o, 'INPROGRESS/UNSUBMITTED', "Unmatched version %s status %s" % (o.version, o.workflow.status if o.workflow else None)) else: info_msg(o, 'INPROGRESS/UNSUBMITTED') elif (o.version == ObjectVersion.HALTED and o.workflow.status == WorkflowStatus.HALTED): info_msg(o, 'INPROGRESS/UNSUBMITTED') elif (o.version == ObjectVersion.HALTED and o.workflow.status == WorkflowStatus.RUNNING): warn( o, 'INPROGRESS/UNSUBMITTED', "wf status %s -> %s" % (o.workflow.status, WorkflowStatus.HALTED)) o.workflow.status = WorkflowStatus.HALTED elif (o.version == ObjectVersion.RUNNING and o.workflow.status == WorkflowStatus.RUNNING): warn( o, 'INPROGRESS/UNSUBMITTED', "wf status %s -> %s" % (o.workflow.status, WorkflowStatus.HALTED)) warn( o, 'INPROGRESS/UNSUBMITTED', "obj version %s -> %s" % (o.version, ObjectVersion.HALTED)) o.version = ObjectVersion.HALTED o.workflow.status = WorkflowStatus.HALTED elif (o.version == ObjectVersion.HALTED and o.workflow.status == WorkflowStatus.COMPLETED): warn( o, 'INPROGRESS/UNSUBMITTED', "wf status %s -> %s" % (o.workflow.status, WorkflowStatus.HALTED)) o.workflow.status = WorkflowStatus.HALTED else: warn( o, 'INPROGRESS/UNSUBMITTED', "Unmatched version %s status %s" % (o.version, o.workflow.status if o.workflow else None)) else: warn(o, 'INPROGRESS/?', "Unmatched version %s status %s" % (o.version, o.workflow.status if o.workflow else None)) global good, bad warnings.warn("Good: %s Bad: %s" % (good, bad)) db.session.commit()