Deleting Expired Announcements in phpWebsite

phpWebsite announcements have an expiration date used to determine when to stop displaying them. After they stop displaying, the announcements simply remain in the database until they are deleted manually. This is my solution to delete expired announcements automatically.

Rather than include something in the phpWebsite code that checks for expired records every time the announcements module is loaded, I created a separate file to execute once per day via my server’s crontab. It would have been simplest to just do a few sql queries to delete the records directly from the database. But, I’m not that familiar with the database structure and relationships, so it would have required a lot of research to make sure I was doing it correctly.

Instead, I copied code from existing phpWebsite files to create a separate execution loop to use the announcements module to delete the announcements. I ended up combining code from /index.php, /mod/announce/class/Announcement.php and /mod/announce/class/AnnouncementManager.php.

AnnDeleteExpired.phps is the result of my efforts.
AnnDeleteExpiredCron.pl.txt is the perl script I use to call it from my crontab.

AnnSyncWithFatCat.phps was my first experiment with this method. It is the same as pressing the “Sync With FatCat” button in the announcements module.

All of these files are for use with phpWebsite 0.9.3-4.

Leave a Reply