Suitecrm: New Scheduled Report does not run. It creates PHP Fatal error AOR_Scheduled_Reports line 195

Created on 24 Apr 2020  ·  11Comments  ·  Source: salesagility/SuiteCRM

Issue

Newly created Schedule for a report , does not work . No email is sent. I get an error in suite log.

Expected Behavior

An email with the Report attached to be sent on specific Hour and Minute.

Actual Behavior

Get in php.log the followind lines when cron executes.

[24-Apr-2020 14:39:44 Europe/Athens] PHP Fatal error:  Uncaught TypeError: Argument 1 passed to AOR_Scheduled_Reports::handleTimeZone() must be an instance of DateTime, bool given, called in C:\Apache24\htdocs\modules\AOR_Scheduled_Reports\AOR_Scheduled_Reports.php on line 195 and defined in C:\web\Apache24\htdocs\modules\AOR_Scheduled_Reports\AOR_Scheduled_Reports.php:204
Stack trace:
#0 C:\Apache24\htdocs\modules\AOR_Scheduled_Reports\AOR_Scheduled_Reports.php(195): AOR_Scheduled_Reports->handleTimeZone(false)
#1 C:\Apache24\htdocs\modules\Schedulers\_AddJobsHere.php(786): AOR_Scheduled_Reports->shouldRun(Object(DateTime))
#2 C:\Apache24\htdocs\modules\SchedulersJobs\SchedulersJob.php(540): aorRunScheduledReports(Object(SchedulersJob))
#3 C:\Apache24\htdocs\include\SugarQueue\SugarCronJobs.php(191): SchedulersJob->runJob()
#4 C:\Apache24\htdocs\include\SugarQueue\SugarCronJobs.php(231): SugarCronJobs->executeJob(Object(SchedulersJob))
#5 C:\Apache24\htdocs\cron.php(100): SugarCronJobs->runCycle()
#6 {main}
  thrown in C:\Apache24\htdocs\modules\AOR_Scheduled_Reports\AOR_Scheduled_Reports.php on line 204

Possible Fix


In AOR_Scheduled_Reports.php(195) there is a handleTimeZone($lastRun);
lastRun is null in Database, because the job is a new one.

Steps to Reproduce


  1. https://community.suitecrm.com/t/help-run-report-generation-scheduled-tasks-failed-in-cron-run/72435/9
  2. https://github.com/salesagility/SuiteCRM/pull/8181
    3.
    4.

Context



It seems to be a high priority, because affects all new Scheduled Reports .

Your Environment


Windows Server
Suite CRM Version 7.11.13 - Sugar Version 6.5.25 (Build 344)
PHP Version 7.3.17
Apache/2.4.43 (Win64) OpenSSL/1.1.1f PHP/7.3.17

Setting in php.ini for timezone :
date.timezone = “Europe/Athens”

Reports Important Bug

Most helpful comment

I Just edited the file:

..../modules/AOR_Scheduled_Reports/AOR_Scheduled_Reports.php:195

And modify the line that fetch the $lastRun to the following:

$lastRun = $timedate->fromDb($this->last_run);
if (!$lastRun) {
$lastRun=$timedate->fromDb($this->date_entered);
}

I dont know if date_entered its the right value, but once the report is executed, lastRun will have the right value

All 11 comments

@eliaski
Which database and version?

If you manually run the report first, then does the scheduled report start to run without this error lastRun = NULL ?

@eliaski
Which database and version?

MySQL Community Server (GPL)
5.7.24
version_compile_machine | x86_64
version_compile_os | Win64

Same issue for me
CentOS 8.1 - php 7.3.16 - 10.3.17-MariaDB - mysqlnd 5.0.12 - SuiteCRM 7.11.13 clean install

`[05-May-2020 18:59:02 Europe/Berlin] PHP Fatal error: Uncaught TypeError: Argument 1 passed to AOR_Scheduled_Reports::handleTimeZone() must be an instance of DateTime, bool given, called in /var/www/html/suitecrm/modules/AOR_Scheduled_Reports/AOR_Scheduled_Reports.php on line 195 and defined in /var/www/html/suitecrm/modules/AOR_Scheduled_Reports/AOR_Scheduled_Reports.php:204
Stack trace:

0 /var/www/html/suitecrm/modules/AOR_Scheduled_Reports/AOR_Scheduled_Reports.php(195): AOR_Scheduled_Reports->handleTimeZone(false)

1 /var/www/html/suitecrm/modules/Schedulers/_AddJobsHere.php(786): AOR_Scheduled_Reports->shouldRun(Object(DateTime))

2 /var/www/html/suitecrm/modules/SchedulersJobs/SchedulersJob.php(540): aorRunScheduledReports(Object(SchedulersJob))

3 /var/www/html/suitecrm/include/SugarQueue/SugarCronJobs.php(191): SchedulersJob->runJob()

4 /var/www/html/suitecrm/include/SugarQueue/SugarCronJobs.php(231): SugarCronJobs->executeJob(Object(SchedulersJob))

5 /var/www/html/suitecrm/cron.php(100): SugarCronJobs->runCycle()

6 {main}

thrown in /var/www/html/suitecrm/modules/AOR_Scheduled_Reports/AOR_Scheduled_Reports.php on line 204
`
All the schedulers are running. None of them has lastRun=Null. In Admin - Schedulers, I see Last Successful run for "Run report generation scheduled tasks" as 05.05.2020:18:14, this is before I set scheduled reports for sending as emails.

It tries every possible minutes and fails with above messages in php_errors.log. As you can see time zone is "Europe/Berlin".

Any idea?

There's an idea (in the form of a question) in Chris' post above

It would be nice to update the code so that when the lastRun date parameter was "never", a NULL value, ie a new one that hasn't run before, it wouldn't crash, it'd run smoothly. Should be an easy tweak.

If I understand you correctly it did not help. I have prepared the report first, ran it and adjusted conditions and ran it. My users started to review report. And then I have created a schedule for the report and then the issue happened.

Yesterday I have only looked for Scheduler table and no NULL in the last_run column for all schedulers. Now I see aor_scheduled_reports and last_run is NULL in this table.

I have manually update last_run = date_entered and see the updated run in the frontend for scheduled reports Las run column.

And in next cycle it ran and sent the email. Thanks.

One more issue, after having the email(report run), I have checked front end View Scheduled Reports and also aor_scheduled_reports table, Last run is not updated and still shows the date as I update manually.

I Just edited the file:

..../modules/AOR_Scheduled_Reports/AOR_Scheduled_Reports.php:195

And modify the line that fetch the $lastRun to the following:

$lastRun = $timedate->fromDb($this->last_run);
if (!$lastRun) {
$lastRun=$timedate->fromDb($this->date_entered);
}

I dont know if date_entered its the right value, but once the report is executed, lastRun will have the right value

I can confirm that what proposed @afernandez2000 worked for me on a 7.10.29

The scope of this is actually even worse. If you have multiple scheduled reports, then you create a New one (blank last_run), then the Fatal Error is thrown and (depending on how things are sorted), all of the other reports will NOT be run.

I applied @afernandez2000 suggestion in #9059 to address the issue

Was this page helpful?
0 / 5 - 0 ratings