# IBM Confidential
# OCO Source Materials
# 5724-V51
#
# (c) Copyright IBM Corp. 2000, 2008 All Rights Reserved.
#
# The source code for this program is not published or otherwise
# divested of its trade secrets, irrespective of what has been
# deposited with the U.S. Copyright Office.

#!/bin/bash

#	Copyright 2005, IBM Corporation


#      Do clean for all collaboration area.


#
# Usage of the file
if [[ $# -ne 3 ]]
then
 echo "Usage "
 echo "docleanall.sh --db=databasename --dbuser=dbusername --dbpassword=dbuserpassword"
 echo "Example docleanall.sh --db=wpcdb --dbuser=wpc1 --dbpassword=wpc1"
  
 exit 0
fi

# Declare the variables
DBName=`echo $1 |cut -d "=" -f2`;export DBName
DBUSER=`echo $2 |cut -d "=" -f2`;export DBUSER
DBUserPassword=`echo $3 |cut -d "=" -f2`;export DBUserPassword

if [ "$TOP" ]
then
mkdir ${TOP}/logs 2>&1 >>/dev/null
mkdir ${TOP}/logs/ghostItemsCleanings  2>&1 >>/dev/null
else
mkdir logs 2>&1 >>/dev/null
mkdir logs/ghostItemsCleanings 2>&1 >>/dev/null
fi


#
sqlplus ${DBUSER}/${DBUserPassword}@${DBName} <<EOF


set heading off;
set pagesize 0;
set feedback off;
spool temp_catalog.txt;
SELECT COA_ID FROM COA where COA_CONTAINER_TYPE='CATALOG';
spool off;
spool temp_category_tree.txt;
SELECT COA_ID FROM COA where COA_CONTAINER_TYPE='CATEGORY_TREE';
spool off;

EOF

# Do the item-workflow collab areas
cat temp_catalog.txt| grep -v SQL > collabId.txt
for i in `cat collabId.txt`
do
echo " "
echo "REPORT FOR ITEM-WORKFLOW COLLABORATION AREA ${i}"
echo " "
./doclean.sh --db="${DBName}" --dbuser="${DBUSER}"  --dbpassword="${DBUserPassword}" --coaid="${i}"
done

# Do the category-workflow collab areas
# 9/21/07 disable
#cat temp_category_tree.txt| grep -v SQL > collabId.txt
#for i in `cat collabId.txt`
#do
#echo " "
#echo "REPORT FOR CATEGORY-WORKFLOW COLLABORATION AREA ${i}"
#echo " "
#./doclean_category.sh --db="${DBName}" --dbuser="${DBUSER}"  --dbpassword="${DBUserPassword}" --coaid="${i}"
#done

rm temp_catalog.txt 
rm temp_category_tree.txt
rm collabId.txt


if [ "$TOP" ]
then
rm ${TOP}/logs/ghostItemsCleanings/lastcleanall.txt
echo "`date |awk '{print "lastClean_"$2"_"$3"_"$6"_"$4}'|sed s/":"//g`" >> ${TOP}/logs/ghostItemsCleanings/lastcleanall.txt
else
rm logs/ghostItemsCleanings/lastcleanall.txt
echo "`date |awk '{print "lastClean_"$2"_"$3"_"$6"_"$4}'|sed s/":"//g`" >> logs/ghostItemsCleanings/lastcleanall.txt
fi

exit $?

