$lastcron usage on /block_configurable_reports.php 183

$lastcron usage on /block_configurable_reports.php 183

by Luis de Vasconcelos -
Number of replies: 4
Picture of 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?

Average of ratings: -
In reply to Luis de Vasconcelos

Re: $lastcron usage on /block_configurable_reports.php 183

by Luis de Vasconcelos -
Picture of 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

by Miguel González Laredo -
Picture of 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!
Average of ratings:Useful (1)
In reply to Miguel González Laredo

Re: $lastcron usage on /block_configurable_reports.php 183

by Luis de Vasconcelos -
Picture of 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()) )