CSV export out of eZ Publish

A team member requested a list of users and email addresses from an eZ publish site, and I remembered seeing a file called ezcsvexport.com under php/bin.

After a few tries, I found the following sequence of commands worked really well.

CSV_EXPORT_BASE=~/tools/export
cd ~/public_html/ez
/usr/local/bin/php -C bin/php/ezcsvexport.php 12 –storage-dir=$CSV_EXPORT_BASE -smsite -q -l export -p password 2> /dev/null
rm $CSV_EXPORT_BASE/*.png 2> /dev/null
rm $CSV_EXPORT_BASE/*.jpg 2> /dev/null
rm $CSV_EXPORT_BASE/*.gif 2> /dev/null
rm $CSV_EXPORT_BASE/*.bmp 2> /dev/null
sed “s/\([^\;]*\);\([^\;]*\);[^\|]*[\|]\(\|[^\|]*\)[\|].*$/\1,\2,\3/” $CSV_EXPORT_BASE/user.csv | grep -v ‘;’ | grep ‘@’ | mail email@domain.com -s “eZ Guest Accounts”

This created a file called user.csv, which was delimited with semicolons and included all the information. The account information (username, email, etc) was serialized, meaning separated with vertical bars or piping characters. I used sed to replace the semicolons with commas, and find the second element of the user account data (the email address). Some people had added signatures, so one grep command was used to get only those lines with @s in them, since that indicates an email address. Finally the whole thing was piped through mail and sent to the requestor.

The export script saved me a lot of time.