-3

I have a question. Is there a possibility in Cakephp but also in PHP in general, to write a function that will do something by itself without user interaction? I mean, for example, to change the status of a record based on the date. If now () is bigger than "start_date", then the function, change status to "completed". Until now, the user always had to change the status in edit view.

My Lesson table has these field:

ID, Title, Start_date, Add_user, description, status

I am using Cakephp 3.6.

l3nox
  • 15
  • 2
  • 8

1 Answers1

0

You could create a Command (Shell for CakePHP v3.5 and less) in your CakePHP application to check each row in your database to see if the date has passed your timer and run a cron job to run that Command every X time.

Console Tools, Shells & Tasks - For examples of Commands

In your Command you will have a function which gets your row from the database, checks to see if now() > start_date and if true then set the status to expired or true or whatever.

Then run the Command every minute or hour via a cron job - Cron Job Tutorial

donny
  • 88
  • 1
  • 12
  • Surely instead of looking at all rows, you'd build a query that selects only rows where the status has not been updated and the date condition is true. Or even just executes an `update` query instead of `select`, `foreach` and `save`. – Greg Schmidt Sep 21 '18 at 16:29
  • Yeah of course you would only select rows which haven't been given a status or are in a current state of needing to be checked, although the question is vague at best and if no effort is put into asking for help then a detailed response isn't going to be given. – donny Sep 24 '18 at 07:45