Movable Type 3.2 introduced a new status for comments and trackbacks - 'junk'. Rather than blocking comments and trackbacks that are deemed to be spam, such comments and trackbacks are kept in the system. How long these 'junk' comments and trackbacks are kept in the MT database is controlled by following settings, found on the "Feedback" tab of the weblog's "Settings" page:
If enabled, junk feedback will be automatically erased after a number of days.
This setting controls whether you want to have junk comments and TrackBacks automatically deleted after a certain period of time specified in the next option.
Delete Junk After X days:
When an item has been marked as junk for this many days, it is automatically deleted.
This setting defines the number of days since a junk comment or TrackBack was received or marked as Junk until the item is deleted.
The value of this setting depends completely on how often you look in your Junk folder for false positives. The default is 60 days, but most people will be satisfied with 7 days.
When "Auto Delete Junk" is enabled, the deletion of junk comments and trackbacks is not truly automatic (despite what the MT documentation says). MT will only "auto-delete" junk comments and trackbacks when you browse to a weblog's main admin page in MT (the page displayed when click on a weblog's title on the main mt.cgi page). If you never browse to this page, which is surprisingly easy to do with all of the new weblog shortcut links present in MT 3.2, MT will not delete old junk comments and trackbacks.
I receive hundreds of spam comments and trackbacks every day. Assuming an average of 500 spams per day (not an unreasonable number), if I do not trigger an auto-delete of junk comments and trackbacks, my MT database would have 3,500 junk comments and trackbacks stored in it after just 1 week, and 15,000 in just one month (30 days). This is unacceptable to me - I have no need to store that many junk comments and trackbacks ever, taking up large amounts of database and disk space.
I don't want to have to remember to periodically browse to the main admin page of each weblog where comments and trackbacks are enabled just to delete old junk comments and trackbacks, so I created a script to be run from a cron job that will indeed automatically delete junk comments and trackbacks for me. Even if I decide to take a break from weblogging for a week or a month, the script will keep deleting junk comments and trackbacks as they get too old and keep the size of my MT database from growing out of control.
This script can be downloaded / viewed here: expire-junk.txt
Download the above script.
Rename script to 'expire-junk' (remove the '.txt' extension).
Upload 'expire-junk' script in ASCII mode to server in the MT 'tools' directory.
Set permissions on script to '0755'.
Create cron job to periodically run script. The following is recommended as the command to run:
cd <mt.cgi directory>; ./tools/expire-junk
Replace <mt.cgi directory>' with the server path to your mt.cgi directory.
I have "Auto Delete Junk" enabled on my weblogs, with "Delete Junk After" set to 2 days. The expire-junk script does not need to be run very often - I've set my cron job to run expire-junk 2 times a day (every 12 hours). When the expire-junk script runs and junk comments or trackbacks are deleted, the number of comments and trackbacks deleted is logged in the MT Activity Log:
|Date||IP Address||Log Message|
|15 hours, 39 minutes ago||127.0.0.1||ExpireJunk: 4 junk ping(s) deleted from weblog 'The Tweezer's Edge'|
|15 hours, 39 minutes ago||127.0.0.1||ExpireJunk: 149 junk comment(s) deleted from weblog 'The Tweezer's Edge'|
If no junk comments or trackbacks are deleted, no entry is made to the MT Activity Log.
The run-periodic-tasks script was used as a model for the expire-junk script, then I took the junk expiration code from CMS.pm and tweaked it a little to work in this script. I did consider developing this as a plugin instead, but it would be invoked on every comment and trackback submission, which would impose unnecessary overhead on MT's comment and trackback processing, and the timing of comment/trackback submissions is unpredictable and inconsistent. A script run by cron seemed a much better and cleaner solution to me.
If you find this script useful, let me know. Comments and suggestions welcome.