Subversion Repositories SmartDukaan

Rev

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

#!/bin/bash
if [ $# -ne 1 ]
then
    echo "Error - Invalid Arguments. Please enter itemid of ITEM table, which needs to be phased out"
    exit
fi
ITEM_ID=$1
echo $ITEM_ID

# resolve links - $0 may be a softlink
PRG="$0"
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}" | tail -1`
#echo $CATALOG_ID

COUNT=`mysql -uroot -pshop2020 catalog -e"select count(*) from item where catalog_item_id = ${CATALOG_ID} and status <> 0" | tail -1`
#echo $COUNT
if [ -z $COUNT ]
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 "======================================================="
        ${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
#TODO If there are still some items active, we should remove color from content. Solution is to regenerate content and update it.