Last active
March 11, 2021 07:03
-
-
Save renekreijveld/27d9062b941a2d0c80f3 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 2.5 - 3.x | |
# | |
# 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 jfunctions. This has to be installed in the same directory as this script. | |
# | |
# general variables | |
mypath=$(cd $(dirname ${0}); pwd -P) | |
myname=$(basename ${0}) | |
# include general functions | |
. ${mypath}/jfunctions | |
# version | |
version=2.2 | |
# 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} ${database} > ${database}.sql | |
then | |
echo "Database dump ${database}.sql created." | |
else | |
echo "Error creating database dump." | |
exit 1 | |
fi | |
dbdump=${curdir}/${database}.sql | |
usedfile=${curdir}/${sitename}-used.txt | |
notusedfile=${curdir}/${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'` | |
file3=`echo $file | sed 's/#}/%20/g'` | |
result1=`grep -c "$file2" ${dbdump}` | |
result2=`grep -c "$file3" ${dbdump}` | |
if [[ $result1 = 0 ]]; then | |
if [[ $result2 = 0 ]]; then | |
echo $file2 >> ${notusedfile} | |
else | |
echo $file2 >> ${usedfile} | |
fi | |
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}" |
First of All let me say T H A N K S ! to Author Rene for sharing this fantastic "time saving" script.
It works fine on my joomla 3.x
Some notes
MANDATORY
2 files:
- jfindfiles
https://gist.github.com/renekreijveld/27d9062b941a2d0c80f3- - jfunctions
https://gist.github.com/renekreijveld/9663741 - SSH Session, better if you use root
STEPS
- Download and upload jfindfiles and jfunctions on your joomla root, in my case in keep joomla on site folder
- chmod +x jfindfiles (I also done for jfunction but I think it's not necessary)
- ./findfiles
OUTPUT
findfiles created 2 files : mysitename-notused.txt and mysitename--used.thx
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you so much renekreijveld, wehseman and psyray!
With the usage comment by user psyray and his adapted files (as commented above) I was able to get it to work (I'm new to ssh).
I learned
ls -lh
there is a list of who owns the files and what the permissions are (the user that uses Putty has to have execute rights) and via ftp thechmod
command changes the permissionsThere were three errors for the jfunctions.sh file
just because the version directory does not exist in in my Joomla 3.9.6 installation. That is not a problem at all though!