#!/bin/sh
#
# TYPO3cleaner.sh v 1.1.4
# Wrapper script for lowlevel_cleaner
#
# Copyright (c) 2008, Michiel Roos
# Last modification: di 30 sep 2008 14:10:39 CEST
#
# TYPO3cleaner.sh is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details: http://www.gnu.org/licenses/gpl.txt
php="/Applications/MAMP/bin/php5/bin/php -q"
webRoot="/Users/michiel/htdocs/alien42/"
script="typo3/cli_dispatch.phpsh lowlevel_cleaner"
logRoot="${webRoot}fileadmin/log/"
emailFrom="ldx@monosock.org"
emailSubject="Cleaner script result:"
emailTo="ldx@monosock.org"
# Cleaning tasks
clean () {
runTask "orphan_records" "0"
runTask "versions" "0" "db"
runTask "tx_templavoila_unusedce" "1" "db"
runTask "double_files" "1"
runTask "deleted" "0" "db"
runTask "missing_relations" "1"
runTask "cleanflexform" "0"
runTask "rte_images" "1"
runTask "missing_files" "1"
runTask "lost_files" "1"
}
# Run cleaning task
runTask () {
now=`date "+%Y-%m-%d_%H-%M"`
logFile="${logRoot}cleaner_${now}_$1.log"
echo "to:$emailTo" > $logFile
echo "from:$emailFrom" >> $logFile
subject="subject:$emailSubject $now $1"
echo $subject >> $logFile
if [ "$2" == "1" ]; then
if [ "$3" == "db" ]; then
echo "Command:" $command $1 -r --refindex update -v 2 $dbOptions >> $logFile
$command $1 -r --refindex update -v 2 $dbOptions >> $logFile
else
echo "Command:" $command $1 -r --refindex update -v 2 $options >> $logFile
$command $1 -r --refindex update -v 2 $options >> $logFile
fi
else
if [ "$3" == "db" ]; then
echo "Command:" $command $1 -r -v 2 $dbOptions >> $logFile
$command $1 -r -v 2 $dbOptions >> $logFile
else
echo "Command:" $command $1 -r -v 2 $options >> $logFile
$command $1 -r -v 2 $options >> $logFile
fi
fi
notifySysadmins $logFile $subject
}
# Send the log to the sysadmin
notifySysadmins () {
if [ -e `which mail` ]; then
cat $logFile | `which mail` -s "$2" "$emailTo"
else
if [ -e `which sendmail` ]; then
`which sendmail` -t < $1
fi
fi
}
# Usage message
usage () {
echo "Usage:"
echo "`basename $0` [-d(ryrun)] [-a(utofix)] [-y(es)] [-e(chotree)] [-q(uiet)] [-p [root page id]]"
}
# Get options
while getopts '?adeqyp:' flag
do
case "$flag" in
'a') options="$options --AUTOFIX" ;;
'd') options="$options --dryrun" ;;
'e') echotree="--echotree 1" ;;
'p')
if [ "$OPTARG" != "" ]; then
pid="--pid $OPTARG"
fi
;;
'q') options="$options --quiet" ;;
'y') options="$options --YES" ;;
'?') usage; exit 1 ;;
'*') usage; exit 1 ;;
esac
done
if [[ -z $options ]]
then
usage
exit 1
fi
if [ -e $webRoot ]
then
command="nice -n 19 $php $webRoot$script"
dbOptions="$echotree $pid $options"
clean
else
echo "Directory does not exist: $webRoot$1"
exit
fi