Subversion Repositories SmartDukaan

Rev

Rev 2175 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#!/bin/bash
# resolve links - $0 may be a softlink
PRG="$0"
if [ $# -ne 1 ]
then
    echo "Error - Invalid Arguments. Please enter itemid of ITEM table, which needs to be phased ot"
    exit
fi
ITEM_ID=$1
echo $ITEM_ID

while [ -h "$PRG" ]; do
  ls=`ls -ld "$PRG"`
  link=`expr "$ls" : '.*-> \(.*\)$'`
  if expr "$link" : '/.*' > /dev/null; then
    PRG="$link"
  else
    PRG=`dirname "$PRG"`/"$link"
  fi
done

# Get standard environment variables
PRGDIR=`dirname $(readlink -f "$PRG")`

SOLR_DIR=/root/solr/apache-solr-1.4.0/example/exampledocs
CONTENT_EXPORT_PATH="/var/lib/tomcat6/webapps/export/html/"

echo "Updating mysql database for id $ITEM_ID"
echo "======================================================="
mysql -uroot -pshop2020 catalog -e"update item set status=0, status_description=\"This item has been phased out\" where id = ${ITEM_ID}"

CATALOG_ID=`mysql -uroot -pshop2020 catalog -e"select catalog_item_id from item where id = ${ITEM_ID}"`
CATALOG_ID=`echo $CATALOG_ID | cut -c17-23`
#echo $CATALOG_ID

COUNT=`mysql -uroot -pshop2020 catalog -e"select count(*) from item where catalog_item_id = ${CATALOG_ID} and status not in(0)"`
COUNT=`echo $COUNT | cut -c9-20`
#echo $COUNT
if [ $COUNT -le 0 ]
then
echo "Not a single item is active or out of stock. Removing content from solr and removing item from website."

echo "Deleting data from solr for entity id $CATALOG_ID"
echo "======================================================="
cd ${SOLR_DIR}
./deleteOne.sh $CATALOG_ID
echo "Done deleting data from solr for entity id $CATALOG_ID"


echo "======================================================="
echo "Removing content snippets for entity id $CATALOG_ID "
echo "======================================================="
cd ${CONTENT_EXPORT_PATH}
rm -rf entities/$CATALOG_ID
echo "Done removing content for entity id $CATALOG_ID"
echo "======================================================="
fi