-
-
Save ZerooCool/fe5eb6caa30e08797ae5aecd0796b613 to your computer and use it in GitHub Desktop.
Find unused and used content files in your Joomla website
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
#!/bin/sh | |
# jfindfiles -- Find used and unused content files in your Joomla website | |
# | |
# This scripts supports Joomla versions 1.0 - 3.3 | |
# | |
# Copyright 2014 Rene Kreijveld - [email protected] | |
# | |
# This program is free software; you may redistribute it and/or modify it. | |
# | |
# Warning! This script needs the file joomlafunctions. This has to be installed in the same directory as this script. | |
# | |
# General variables | |
VERSION=2.0 | |
# Determine path of script | |
MYPATH=$( cd $(dirname $0) ; pwd -P ) | |
# Include general functions | |
. ${MYPATH}/joomlafunctions | |
# Setup Vvariables | |
START=./images | |
CURDIR=`pwd` | |
echo "Creating database dump..." | |
# Dump the database to a .sql file | |
if mysqldump --skip-opt --add-drop-table --add-locks --create-options --disable-keys --lock-tables --quick --set-charset --host=$host --user=$dbuser --password=$password --socket=$MYSOCK $database > $database.sql | |
then | |
echo "Database dump $database.sql created." | |
else | |
echo "Error creating database dump." | |
exit 1 | |
fi | |
dbdump=`pwd`/$database.sql | |
usedfile=`pwd`/$sitename-used.txt | |
notusedfile=`pwd`/$sitename-notused.txt | |
echo "The following files were mentioned in your Joomla database:" > $usedfile | |
echo "The following files were NOT mentioned in your Joomla database:" > $notusedfile | |
echo "Checking for used and unused files..." | |
# Move into the images/stories directory | |
cd ${START} | |
# Find all files and check if they are mentioned in the database dump | |
for file in `find . -type f -print | cut -c 3- | sed 's/ /#}/g'` | |
do | |
file2=`echo $file | sed 's/#}/ /g'` | |
result=`grep -c "$file2" $dbdump` | |
if [[ $result = 0 ]]; then | |
echo $file2 >> $notusedfile | |
else | |
echo $file2 >> $usedfile | |
fi | |
done | |
# Move back to the root of the website | |
cd ${CURDIR} | |
# Cleanup database dump | |
rm $dbdump | |
# Report findings | |
echo "Files checking done." | |
echo "Check the following text-files for results:" | |
echo "$usedfile" | |
echo "$notusedfile" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment