TYPO free

home

fighting for TYPO free code

TYPO3 cleaner

lowlevel cli cleaner helper script

  1. #!/bin/sh
  2. # TYPO3cleaner.sh
  3.  
  4. php=/Applications/MAMP/bin/php5/bin/php
  5. webroot=/Users/michiel/htdocs/
  6. script="/typo3/cli_dispatch.phpsh lowlevel_cleaner"
  7.  
  8.  
  9.   # Cleaning commands
  10. clean () {
  11.   $command orphan_records -r -v 2 $options
  12.   $command versions -r -v 2 $options
  13.   $command tx_templavoila_unusedce -r --refindex update -v 2 $options
  14.   $command double_files -r --refindex update -v 2 $options
  15.   $command deleted -r -v 1 $options
  16.   $command missing_relations -r --refindex update -v 2 $options
  17.   $command cleanflexform -r -v 2 $options
  18.   $command rte_images -r --refindex update -v 2 $options
  19.   $command missing_files -r --refindex update -v 2 $options
  20.   $command lost_files -r --refindex update -v 2 $options
  21. }
  22.  
  23.  
  24.   # Usage message
  25. usage () {
  26.   echo "Usage:\n`basename $0` [--dryrun] [--autofix] [--yes] [--quiet] [domain-name]"
  27. }
  28. if [ -z "$1" ]
  29. then
  30.   usage
  31.   exit
  32. fi
  33.  
  34.  
  35.   # Initialize variables
  36. until [ -z "$1" ]
  37. do
  38.   case  "$1" in
  39.     "--quiet" )
  40.       quiet="-ss"
  41.     ;;
  42.    
  43.     "--dryrun" )
  44.     dry='--dryrun'
  45.     ;;
  46.    
  47.     "--autofix" )
  48.     autofix='--AUTOFIX'
  49.     ;;
  50.    
  51.     "--yes" )
  52.     yes='--YES'
  53.     ;;
  54.    
  55.     [a-z]* )
  56.     if [ -e $webroot$1 ]
  57.     then
  58.       domain=$1
  59.       command="$php $webroot$domain$script"
  60.       options="$autofix $dry $yes $quiet"
  61.       clean
  62.     else
  63.       echo "Directory does not exist: $webroot$1"
  64.       exit
  65.     fi
  66.    
  67.     ;;
  68.   esac
  69.   shift
  70. done

lowlevel cli cleaner helper script using getopts

  1. #!/bin/sh
  2. #
  3. # TYPO3cleaner.sh v 1.1.4
  4. # Wrapper script for lowlevel_cleaner
  5. #
  6. # Copyright (c) 2008, Michiel Roos
  7. # Last modification: di 30 sep 2008 14:10:39 CEST
  8. #
  9. # TYPO3cleaner.sh is distributed in the hope that it will be useful, but
  10. # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  12. # details: https://www.gnu.org/licenses/gpl.txt
  13.  
  14. php="/Applications/MAMP/bin/php5/bin/php -q"
  15. webRoot="/Users/michiel/htdocs/alien42/"
  16. script="typo3/cli_dispatch.phpsh lowlevel_cleaner"
  17. logRoot="${webRoot}fileadmin/log/"
  18.  
  19. emailFrom="[email protected]"
  20. emailSubject="Cleaner script result:"
  21.  
  22.  
  23.   # Cleaning tasks
  24. clean () {
  25.         runTask "orphan_records" "0"
  26.         runTask "versions" "0" "db"
  27.         runTask "tx_templavoila_unusedce" "1" "db"
  28.         runTask "double_files" "1"
  29.         runTask "deleted" "0" "db"
  30.         runTask "missing_relations" "1"
  31.         runTask "cleanflexform" "0"
  32.         runTask "rte_images" "1"
  33.         runTask "missing_files" "1"
  34.         runTask "lost_files" "1"
  35. }
  36.  
  37.  
  38.   # Run cleaning task
  39. runTask () {
  40.         now=`date "+%Y-%m-%d_%H-%M"`
  41.         logFile="${logRoot}cleaner_${now}_$1.log"
  42.  
  43.         echo "to:$emailTo" > $logFile
  44.         echo "from:$emailFrom" >> $logFile
  45.         subject="subject:$emailSubject $now $1"
  46.         echo $subject >> $logFile
  47.  
  48.         if [ "$2" == "1" ]; then
  49.                 if [ "$3" == "db" ]; then
  50.                         echo "Command:" $command $1 -r --refindex update -v 2 $dbOptions >> $logFile
  51.                         $command $1 -r --refindex update -v 2 $dbOptions >> $logFile
  52.                 else
  53.                         echo "Command:" $command $1 -r --refindex update -v 2 $options >> $logFile
  54.                         $command $1 -r --refindex update -v 2 $options >> $logFile
  55.                 fi
  56.         else
  57.                 if [ "$3" == "db" ]; then
  58.                         echo "Command:" $command $1 -r -v 2 $dbOptions >> $logFile
  59.                         $command $1 -r -v 2 $dbOptions >> $logFile
  60.                 else
  61.                         echo "Command:" $command $1 -r -v 2 $options >> $logFile
  62.                         $command $1 -r -v 2 $options >> $logFile
  63.                 fi
  64.         fi
  65.         notifySysadmins $logFile $subject
  66. }
  67.  
  68.  
  69.   # Send the log to the sysadmin
  70. notifySysadmins () {
  71.         if [ -e `which mail` ]; then
  72.                 cat $logFile | `which mail` -s "$2" "$emailTo"
  73.         else
  74.                 if [ -e `which sendmail` ]; then
  75.                         `which sendmail` -t < $1
  76.                 fi
  77.         fi
  78. }
  79.  
  80.  
  81.   # Usage message
  82. usage () {
  83.         echo "Usage:"
  84.         echo "`basename $0` [-d(ryrun)] [-a(utofix)] [-y(es)] [-e(chotree)] [-q(uiet)] [-p [root page id]]"
  85. }
  86.  
  87.  
  88.   # Get options
  89. while getopts '?adeqyp:' flag
  90. do
  91.         case "$flag" in
  92.                 'a') options="$options --AUTOFIX" ;;
  93.                 'd') options="$options --dryrun" ;;
  94.                 'e') echotree="--echotree 1" ;;
  95.                 'p')
  96.                         if [ "$OPTARG" != "" ]; then
  97.                                 pid="--pid $OPTARG"
  98.                         fi
  99.                         ;;
  100.                 'q') options="$options --quiet" ;;
  101.                 'y') options="$options --YES" ;;
  102.                 '?') usage; exit 1 ;;
  103.                 '*') usage; exit 1 ;;
  104.         esac
  105. done
  106.  
  107.  
  108. if [[ -z $options ]]
  109. then
  110.         usage
  111.         exit 1
  112. fi
  113.  
  114.  
  115. if [ -e $webRoot ]
  116. then
  117.         command="nice -n 19 $php $webRoot$script"
  118.         dbOptions="$echotree $pid $options"
  119.         clean
  120. else
  121.         echo "Directory does not exist: $webRoot$1"
  122.         exit
  123. fi