awips2/deltaScripts/13.5.1/updateProviderTypeDb.sh
Steve Harris c05a6c8b50 13.5.1-4 baseline
Former-commit-id: c56be8a332 [formerly 70e4ff30a6] [formerly c56be8a332 [formerly 70e4ff30a6] [formerly e197f23ce3 [formerly d18b403b332dff67d1c85d4317bbceda337d1b41]]]
Former-commit-id: e197f23ce3
Former-commit-id: 640b022e84 [formerly f658320357]
Former-commit-id: c183e08922
2013-06-28 09:46:25 -04:00

47 lines
1.2 KiB
Bash

#!/bin/bash
XSLT_SCRIPT="updateProviderType.xsl"
# ensure that the xslt script is present
if [ ! -f ${XSLT_SCRIPT} ]; then
echo "ERROR: the required xslt script - ${XSLT_SCRIPT} was not found."
echo "FATAL: the update has failed!"
exit 1
fi
echo "INFO: update started - updating ProviderType to be a class proper in the database"
# Dump the provider rows from the database for modification
PROVIDER_ROWS=/tmp/provider_rows.tmp
psql -U awips -d metadata -c "\copy (select key, stringvalue from ebxml.value where stringvalue like '%<provider %') To '${PROVIDER_ROWS}'";
# Get old separator
OIFS=$IFS
IFS=$'\n'
for f in `cat ${PROVIDER_ROWS}`
do
IFS=$'\t'
arr2=( $f )
KEY=${arr2[0]}
XML_FILE=/tmp/${KEY}.xml
# Write out database contents
echo "${arr2[1]}" > ${XML_FILE}
# Remove carriage returns
sed -i 's/\\n//g' ${XML_FILE}
# Run the xslt transform on the tmp file
xsltproc ${XSLT_SCRIPT} ${XML_FILE} > ${XML_FILE}.new
# Insert the new xml into the database
NEW_XML=`cat ${XML_FILE}.new`
psql -U awips -d metadata -c "UPDATE ebxml.value SET stringvalue = '${NEW_XML}' WHERE key = '${KEY}'"
done
# Restore old separator
IFS=$OIFS
echo "INFO: the update has completed successfully!"
exit 0