Created
August 23, 2013 16:22
-
-
Save jhoffmann/6321239 to your computer and use it in GitHub Desktop.
Brute force clear out the SugarCRM cache folder, and repair
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Symlink as ~/bin/cache for happy fun time excitement. | |
DO_REPAIR=0 | |
DEFAULT="2" | |
LEVEL=$DEFAULT | |
LEVELS[1]="cache/smarty/templates_c" | |
LEVELS[2]="cache/modules" | |
LEVELS[3]="cache/jsLanguage cache/themes" | |
LEVELS[4]="cache/include/javascript" | |
LEVELS[5]="cache/Expressions" | |
# $program = <<<'EOT' | |
# define('sugarEntry', true); | |
# require_once ('include/entryPoint.php'); | |
# require_once ('modules/Administration/QuickRepairAndRebuild.php'); | |
# $user = new User(); | |
# $GLOBALS['current_user'] = $user->getSystemUser(); | |
# $rc = new RepairAndClear(); | |
# $rc->repairAndClearAll(array('clearAll'), null, false, false); | |
# echo 'Rebuilding Relationships.'.PHP_EOL; | |
# require_once ('modules/Administration/RebuildRelationship.php'); | |
# EOT; | |
# echo base64_encode($program) . PHP_EOL; | |
REPAIR="ZGVmaW5lKCdzdWdhckVudHJ5JywgdHJ1ZSk7CnJlcXVpcmVfb25jZSAoJ2luY2x1ZGUvZW50cnlQb2ludC5waHAnKTsKcmVxdWlyZV9vbmNlICgnbW9kdWxlcy9BZG1pbmlzdHJhdGlvbi9RdWlja1JlcGFpckFuZFJlYnVpbGQucGhwJyk7CiR1c2VyID0gbmV3IFVzZXIoKTsKJEdMT0JBTFNbJ2N1cnJlbnRfdXNlciddID0gJHVzZXItPmdldFN5c3RlbVVzZXIoKTsKJHJjID0gbmV3IFJlcGFpckFuZENsZWFyKCk7CiRyYy0+cmVwYWlyQW5kQ2xlYXJBbGwoYXJyYXkoJ2NsZWFyQWxsJyksIG51bGwsIGZhbHNlLCBmYWxzZSk7CmVjaG8gJ1JlYnVpbGRpbmcgUmVsYXRpb25zaGlwcy4nLlBIUF9FT0w7CnJlcXVpcmVfb25jZSAoJ21vZHVsZXMvQWRtaW5pc3RyYXRpb24vUmVidWlsZFJlbGF0aW9uc2hpcC5waHAnKTs="; | |
func_repair() { | |
echo "Running repair and rebuild." | |
php -d "error_reporting=E_ALL&~E_DEPRECATED&~E_WARNING&~E_NOTICE" -r "eval(base64_decode('${REPAIR}'));" | |
} | |
func_usage() { | |
echo "usage: `basename ${0}` [arguments] [level]" | |
echo | |
echo "Arguments:" | |
echo " -h This helpfile" | |
echo " -r Run Repair & Rebuild" | |
echo | |
echo "Available levels of cleaning:" | |
for i in `seq ${#LEVELS[*]}`; do | |
if [ $i == $LEVEL ]; then | |
echo -n " * " | |
else | |
echo -n " " | |
fi | |
echo "${i} ${LEVELS[$i]}" | |
done | |
exit | |
} | |
for arg in "$@"; do | |
case "$arg" in | |
-h) LEVEL=$DEFAULT func_usage | |
;; | |
-r) DO_REPAIR=1 | |
;; | |
*) LEVEL="$arg" | |
;; | |
esac | |
done | |
if [ "${#LEVELS[$LEVEL]}" == 0 ]; then | |
LEVEL=$DEFAULT func_usage | |
fi | |
if [ -d cache -a -O cache ]; then | |
echo "Running level ${LEVEL} cache cleaning:" | |
for i in `seq ${LEVEL}`; do | |
echo " Removing: ${LEVELS[$i]}" | |
rm -rf ${LEVELS[$i]} | |
done | |
if [ $DO_REPAIR -gt 0 ]; then | |
func_repair | |
fi | |
else | |
echo "Either wrong path (not sugar root) or wrong user (run as the owner of the cache folder)." | |
fi | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment