I was trying to figure out this about a year ago, but then got busy. Now I have a few more twists.
So, I have 3 db tables. First able (t1) stores project data, second table (t2) stores task data and the last one (t3) user information.
What happens?
User creates a project. Then he/she adds tasks to projects.
What I need?
I need to retire old projects and notify user by email.
t1
----------------
t1.projectID
t1.projectName
t1.projectStatus -- enum('active', 'closed', 'expired', 'draft')
t1.projectExpiration
t1.userPosterID
t2
----------------
t2.taskID
t2.projectID
t2.taskStatus -- enum('active', 'closed', 'expired')
t3
----------------
t3.userID
t3.userName
t3.userEmail
Sometimes project can have the t1.projectExpiration = '0000-00-00', which means it is set to never expire and will continue to have active status (t1.projectStatus = 'active')
I need to run a script that will check every project and if
- currently there are no tasks (t2.taskStatus) with ACTIVE status and
- no new tasks have been posted under this Project for at least 30 days
it'll change t1.projectStatus from 'active' to 'expired'. Once the status is changed I need to send email.
mail("$userEmail", "Project Expired", "$userName, Your project expired...", "From: <auto@site.com>");
Intentionally do not want to put my attempts here in order not to cloud a possible simple solution that may exist. Mine's way to convoluted and requires multiple queries. I think there's a way to get it all in one.