Purge unused email addresses from the database
Email addresses are one of the few record types that can't be deleted from within Cerb's user interface. This restriction exists to maintain referential integrity within the database -- which is a fancy way of saying that many other records (like tickets, messages, and workers) are linked to email addresses. If these addresses were deleted then the records they are linked to would become incomplete and various features would break.
Some customers have been using Cerb for the entire 12+ years of its existence. Over such a long time period, junk email addresses can create a lot of clutter when browsing address worklists. For instance, spammers often use disposable email addresses, and once those tickets and messages are deleted then the same address is never encountered again. In this situation, it's not useful to keep a record of these senders, even if they are flagged as spammers, because they won't create new messages in the future using the same identity.
It is possible to delete these junk email addresses directly from the database, but this should only be done after confirming that these addresses are indeed not linked to any other important records. The script provided in this article will perform these checks automatically before removing unused addresses.
Make a backup!
This process will modify your database. While these instructions have been tested in many environments, it is always wise to [make a backup](http://cerbweb.com/book/latest/admin_guide/backups/ "") in case something goes wrong.
Install the script
Download the attached
cerb670_address_purge.txt script and copy it to your
/cerb web directory.
Rename the file to
Run the script
This script will compile a list of email addresses from the database that are not linked to any other records. This is accomplished by making a temporary copy of the entire address book and then deleting copied records that are linked to tickets, messages, workers, etc. The remaining records are unused and can be safely deleted. This script will automatically delete those unused records.
Execute the script on the command line using the
If addresses will be purged, the script will output:
1234 unused email addresses would be purged.
To delete these unused email addresses, run the command again with the
php cerb670_address_purge.php --delete
After deleting, the script will output:
Purged 1234 unused email addresses.
If there are no unused email addresses, the script will output:
No unused email addresses were found.
Once you have purged the unused addresses, delete the
cerb670_address_purge.php script from your web server.