I work on CakePHP 3.2 Project..
I have a Property
Entity..
when a user creates a property, the admin must validate it to become active..
After that I put in field called date_of_expiration
the current date + 10 days for example ...
What I want is that this property expires in this date (current date + 10 day).. By changing a field called status
from active to inactive..
I searched in Google and i found that what i nead called Sheduled Task..
I ask about the best way to do this in CakePHP 3.2
You could set up a cron job which would call a function in your controller. Your function then would select all the records from your properties
table, check if date_of_expiration
is expired and then set the status
to inactive
.
You have to allow the method to be called without you are logged in and possibly disable the CSRF component (if you are using it):
public function beforeFilter(Event $event){
$this->Auth->allow('cronjob_expiration_date');
if(in_array($this->request->action, ['cronjob_expiration_date'])) {
$this->eventManager()->off($this->Csrf);
}
}
This is necessary, because the cron job "user" is not logged in.