#!/bin/bash
# Licensed Materials - Property of IBM
# 5724-I68
#
# (C) Copyright IBM Corp. 2000, 2006
#
# US Government Users Restricted Rights - Use, duplication, or
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp.

# The purpose of this script is to migrate the database schema used by WPC from 3.5.0 or later releases to 3.5.2.
# Please consult WPC support before attempting to use this script

# 
# # Copyright (c) 2000, 2004 IBM Corp. - All Rights Reserved.
# # IBM makes no representations or warranties about the suitability of
# # this program, either express or implied, including but not limited to
# # the implied warranties of merchantability, fitness for a particular
# # purpose, or non-infringement. 
# 
#


if [ -z "$TOP" -o ! -r "$TOP" ]; then
   ${ECHO} TOP variable not defined
   exit 1
fi

# Set variable based on the parameter passed into the script
ARG1=$1

if [ $# -gt 0 ]; then
   ${ECHO} "Usage: $0 --help"
   ${ECHO} "--help to display this usage text."
   ${ECHO} "To perform the migartion, invoke this script without any arguments."
   exit 2
fi

   ${ECHO} "ARG1=" $ARG1

# Asking for Confirmation - just in case.
${ECHO}
${ECHO} "This script will cause permanent changes to the database schema use by WPC."
${ECHO} "This change is irreversible. We urge you take a backup of the database schema before you continue."
${ECHO} "Do you want to continue ? (y/n) "
read res
if [ ! "$res" = "y" ]; then
    ${ECHO} "!! exiting"
    exit
fi
# Asking for re-confirmation - just in case. 
${ECHO} "Have you taken a back-up  of the database schema ? (y/n) "
read res1
if [ ! "$res1" = "y" ]; then
    ${ECHO} "!! exiting"
    exit
fi


${ECHO} "Schema upgrade has been initiated"

# Set variables based on the parameters passed into the script
LDAPURL=$1
NAMEATTR=$2
PARENT_DN=$3

. ${TOP}/src/db/schema/util/set_db.sh


${ECHO} "Generating default scripts new for WebSphere Product Center 5.3.2..."

GET_COMPANIES=`. ${DB_DIR}/util/run_db_cmd.sh --file=$DB_CMN_SCRIPTS/get_cmpcode.sql --errorfilter=yes | ${GREP} 'cmpcode-' `
COMPANIES="${GET_COMPANIES}"

for CMP_CODE_COL in $COMPANIES; 
do
    CMP_CODE=`${ECHO} ${CMP_CODE_COL} | ${GREP} 'cmpcode-' | ${CUT} -f2 -d "-"`
    ${ECHO} Updating WPC scripts for company $CMP_CODE
    ${JAVA_RT_NOOUT} com.ibm.ccd.docstore.util.DocLoader $CMP_CODE Admin $SCRIPTS_DIR/common/report_scripts.xml Cp1252
done

${ECHO} "Schema Migration complete"



