Skip to content

Instantly share code, notes, and snippets.

@tzi
Created November 9, 2011 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tzi/1351364 to your computer and use it in GitHub Desktop.
Save tzi/1351364 to your computer and use it in GitHub Desktop.
A #shell #script : recreate the #ezpublish back-office tree from the media files
# USAGE
usage()
{
echo "usage: $0 [ -v ] <storage> <destination>"
echo ""
echo " -v : Increase the verbose"
echo ""
exit
}
# OPTIONS
VERBOSE=false;
while getopts "v" option
do
echo ${option}
case ${option} in
v) VERBOSE=true;;
\?) usage
exit 1;;
esac
done
shift $(( $OPTIND - 1 ))
# ARGUMENTS
if [[ $# -lt 2 ]]
then
usage
fi
root_folder=$1
if [[ ${root_folder:${#root_folder}-1} == '/' ]]
then
root_folder=${root_folder:0:${#root_folder}-1}
fi
root_destination=$2
if [[ ${root_destination:${#root_destination}-1} == '/' ]]
then
root_destination=${root_destination:0:${#root_destination}-1}
fi
# FOREACH SOURCE FILE
for file in `ls -R "${root_folder}"`
do
# IT IS THE CONTAINER
if [[ ${file:${#file}-1} == ':' ]]
then
# THERE WAS AT LEAST ONE FILE IN THE PREVIOUS CONTAINER
if [ ${#files[@]} -gt 0 ]
then
# WE SEARCH THE ORIGINAL MEDIA
original_file=${files[0]}
for my_file in ${files[@]}
do
if [[ ${#my_file} -lt ${#original_file} ]]
then
original_file=${my_file}
fi
done
# WE WILL COPY THE ORIGINAL MEDIA IN THE NEW TREE
destination=${folder:${#root_folder}}
destination=${destination%/*}
destination=${root_destination}${destination%/*}
mkdir -p ${destination}
cp ${folder}"/"${original_file} ${destination}"/"${original_file}
if $VERBOSE
then
echo ""${folder}"/"${original_file}" => "${destination}"/"${original_file}
fi
fi
# DEFINE NEW CONTAINER
folder=${file:0:${#file}-1}
files=( )
# IT IS ELEMENT INSIDE THE CONTAINER
else
# WE ARE NOT IN THE ROOT FOLDER
if [[ ${#folder} -gt 0 ]]
then
# THE ELEMENT IS A FILE
if [[ ${file} == *.* ]]
then
files[${#files[@]}]=$file;
fi
fi
fi
done
@tzi
Copy link
Author

tzi commented Nov 9, 2011

The storage folder in eZ Publish loks like this :
ezpublish/var/ezflow_site_clean/storage/images/media/folder/image/622548-1-fre-FR/Image.jpg
ezpublish/var/ezflow_site_clean/storage/images/media/folder/image/622548-1-fre-FR/Image_multiuploadthumbnail.jpg
ezpublish/var/ezflow_site_clean/storage/images/media/folder/image/622548-1-fre-FR/Image_reference.jpg

If you execute the following command :
ezcopy_media.sh ezpublish/var/ezflow_site_clean/storage/images/media/ /tmp/ezmedia

You will create the following file tree :
/tmp/ezmedia/folder/Image.jpg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment