0

したがって、次のコードを含む 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 がインストールされ、実行されていることが示されます。ただし、1 日に複数回実行されるため、1 日に 1 回だけ実行する必要があります。それで、私は何を間違っていますか?

この問題の別の解決策も受け入れます (1 日の決まった時間にメールを送信する)。私は Yii を使用していることを考慮してください。そのため、フレームワーク内でこれを行う方法が必要です (たとえば、拡張機能を使用)。

PS: 良いドキュメント ソースを知っていれば (Usergroups、Cron-tab、および Yii 自体は、これらすべてがどのように機能するかをドキュメント化するのにそれほど強力ではないため)、これらすべてについて、私はまだ興味があります。

4

1 に答える 1

0

私は以前にこの拡張機能を使用したことがありません。しかし、私はソース コードを見て、次のフラグメントに注意を払います。

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();
}

そして、次の質問をしたいと思います。

  1. あなたifの場合、オペレーターは正しく動作しますか?
  2. $cItem->last_occurrencecron の実行後に更新されますか?
  3. どのバージョンの PHP を使用していますか?
于 2012-11-12T20:39:40.460 に答える