$lastcron usage on /block_configurable_reports.php 183

$lastcron usage on /block_configurable_reports.php 183

Luis de Vasconcelos發表於
Number of replies: 4
Particularly helpful Moodlers的相片

Refer https://github.com/jleyva/moodle-block_configurablereports/blob/MOODLE_36_STABLE/block_configurable_reports.php#L183

Line 183 of block_configurable_reports.php shows:

        $lastcron = $DB->get_field('block', 'lastcron', array('name' => 'configurable_reports'));
        if (!$lastcron and ($lastcron + $this->cron < time()) ) {
            return false;
        }

Should that if() statement use !$lastcron or $lastcron?

評比平均分數: -
In reply to Luis de Vasconcelos

Re: $lastcron usage on /block_configurable_reports.php 183

Luis de Vasconcelos發表於
Particularly helpful Moodlers的相片
I searched the forum and found this forum message.

Please clarify this !$lastcron usage for me. Shouldn't it be $lastcron instead of !$lastcron ?
In reply to Luis de Vasconcelos

Re: $lastcron usage on /block_configurable_reports.php 183

Miguel González Laredo發表於
Plugin developers的相片
Hi Luis. I have tested that php code (stand-alone script) and I consider that the post and you are correct. For the first time, the logical condition goes to a "return false" infinite loop. You could change the IF clause or could avoid the first execution situation by preventing $lastcron as null. Maybe using https://www.php.net/manual/es/function.empty.php

Good luck!
評比平均分數:Useful (1)
In reply to Miguel González Laredo

Re: $lastcron usage on /block_configurable_reports.php 183

Luis de Vasconcelos發表於
Particularly helpful Moodlers的相片
So what is the correct fix?

if ($lastcron || ($lastcron + $this->cron < time()) )
or:
if ($lastcron and ($lastcron + $this->cron < time()) )
or:
if (!$lastcron || ($lastcron + $this->cron < time()) )