#!/bin/bash

# Perform the two stages of MPC export if the export flag file is present.
#
# This script enables the global processing mode for MPC export. That is, all
# DOs in the instance will be processed for export.
#
# Stage 1 Determine exportable DOs and create revision records and set them as pending for export.
# Stage 2 Export detections and orbits associated with pending revision records.
#
# Usage
#
#     mpc-export-all

export PERL5LIB=/usr/local/MOPS/mpc-export/lib/perl5:$PERL5LIB
export PATH=/usr/local/MOPS/mpc-export/bin:$PATH
export MPC_EXPORT_BIN=/usr/local/MOPS/mpc-export/bin

EXPORT_IS_SET=`get-mpc-export-flag.pl $MOPS_DBINSTANCE`;

if [ $EXPORT_IS_SET == 1 ]; then
    echo "Performing MPC export (all) on database $MOPS_DBINSTANCE."

    $MPC_EXPORT_BIN/process-dos-all.pl --noprompt $MOPS_DBINSTANCE
    $MPC_EXPORT_BIN/export-pending-mops-objects-to-mpc-datastore.pl --noprompt $MOPS_DBINSTANCE
else
    echo "Data will NOT be exported to the MPC."
fi
