A
A
Alexander Ampleev2017-08-06 10:58:53
Yii
Alexander Ampleev, 2017-08-06 10:58:53

Why does the console controller behave differently than the Yii2 web controller?

I have a script like this:

$timeNow = new \DateTime(date("Y-m-d H:i:s"), new \DateTimeZone('UTC'));
        $interval = new \DateInterval('PT'. Yii::$app->params['intervalMinForDescicionIssue'] .'M');
        $timeCorrect = $timeNow->sub($interval);
        $issues = Issue::find()
            ->where(['between', 'createdDate', $timeCorrect->format("Y-m-d H:i:s"), date("Y-m-d H:i:s")])
            ->all();

        foreach ($issues as $issue) {

            $issue->countMin++;

            if($issue->countMin >= Yii::$app->params['intervalMinForIssuePrice']){

                $issue->price++;
                $issue->countMin = 0;

            }
            
            $issue->save();

if you run it through actionTest in SiteController, then everything is ok.
if run through the console via cron every minute in basic/commands/CronController, then for some reason it updates the data not in all rows of the table, but strictly in 6 rows. It looks like some kind of cache, but I don’t understand how to fix it. Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question