I already learned how to create a task from this page but I would like to know how to run this task? I'm creating a portal where users are allowed to give their votes and discuss several projects. Backend users can create different phases and declare a start and an end date and a few days before these phases end all members/participants of this phase should receive an email.
I know how to send the mail, I know how to create the task but I don't know how to start the task 1, 3 and 7 days before a specific date.
Do those steps run every single second?
public function runStep($step)
{
$criteria = craft()->elements->getCriteria(ElementType::Category);
$criteria->group = 'phase';
if($criteria->count()){
$phases = $criteria->find();
foreach ($phases as $phase){
$now = time();
$threeDaysBefore = $now - (60 * 60 * 24 * 3); //Seconds * Minutes * Hours * Days
$OneDaysBefore = $now - (60 * 60 * 24 * 1); //Seconds * Minutes * Hours * Days
$endTime = $phase->phaseEndDate->getTimestamp();
if($endTime == $OneDaysBefore || $endTime == $threeDaysBefore){
craft()->myplugin->sendMailToUser();
}
}
}
}
Where do I activate the task? Do I run craft()->tasks->createTask(/*parameter*/)
in my plugin init() function?
And my last question: how can I debug my function? In my chrome network tap I receive a taskInfo every second but I can't var_dump()
something from my runstep
function.
Thank you very much