因此,我有一个包含以下代码的cron作业:
class UGCJReminder extends UGCronJob {
/**
* return the cron description
*/
protected function getDescription()
{
return Yii::t('userGroupsModule.cron', 'manda email para os usuarios cadastrados para cadastrar suas atividades');
}
/**
* return the cron table model name
*/
protected function getCronTable()
{
return 'UserGroupsCron';
}
/**
* return the cron name
*/
protected function getName()
{
return 'reminder';
}
/**
* returns the number of days that have to pass before performing this cron job
*/
protected function getLapse()
{
return 1;
}
/**
* return the model
*/
protected function getModel()
{
return new UserGroupsUser;
}
/**
* return the action method
*/
protected function getAction()
{
Yii::import('ext.yii-mail.YiiMailMessage');
$message = new YiiMailMessage;
$message->setBody('Message', 'text/html');
$message->subject = 'Lembrete';
$message->addTo('my-email');
$message->from = Yii::app()->params['adminEmail'];
return Yii::app()->mail->send($message);
}
/**
* return the action criteria
*/
protected function getCriteria()
{
return new CDbCriteria;
}
/**
* return the interested database fields
*/
protected function getColumns()
{
return array('email' => UserGroupsUser::ACTIVE);
#return NULL;
}
}我对UserGroups (Yii模块)要求的文档进行了所有其他更改,cron列表显示我的cron已安装并正在运行。但是,它一天运行多次,应该每天只运行一次。那么我做错了什么呢?
我也会接受这个问题的另一种解决方案(每天在确定的时间发送一封电子邮件)。请考虑我正在使用Yii,因此希望在框架内实现这一点(例如,使用扩展)。
PS:如果你知道好的文档来源(因为Usergroups,Cron-tab和Yii本身在记录所有这些是如何工作的方面没有那么强),我仍然会对此感兴趣
发布于 2012-11-13 04:39:40
我以前从来没有用过这个扩展。但我正在看源代码,并注意这段代码:
https://github.com/nickcv/userGroups/blob/master/components/UGCron.php#L206
if ($cItem->last_occurrence <= date('Y-m-d', time() - (3600 * 24 * $cItem->lapse)).' 00:00:00') {
...
$cItem->last_occurrence = date('Y-m-d').' 00:00:00';
$cItem->save();
}我想问你下面几个问题:
if运算符在您的情况下是否正常工作?$cItem->last_occurrence是否会更新??
https://stackoverflow.com/questions/13350685
复制相似问题