salesagility / SuiteCRM

SuiteCRM - Open source CRM for the world
https://www.suitecrm.com
GNU Affero General Public License v3.0
4.26k stars 2.03k forks source link

Fix #10453 - Workflow fails when action used business hours to calculate date when running via cron #10454

Open JackBuchanan opened 2 weeks ago

JackBuchanan commented 2 weeks ago

Use fixUpFormatting to correct date formats back to DB format so that fromDB is passed a date in DB format:

$value = $businessHours->addBusinessHours($amount, $timedate->fromDb($bean->$dateToUse))

Description

Use fix up formatting to set dates to db format, if not set and running from cron then a 500 is thrown:

[16-Jun-2024 15:12:15 UTC] PHP Fatal error: Uncaught TypeError: AOBH_BusinessHours::addBusinessHours(): Argument https://github.com/salesagility/SuiteCRM/issues/2 ($date) must be of type ?DateTime, bool given, called in /var/www/SuiteCRMCorePR/modules/AOW_Actions/actions/actionCreateRecord.php on line 279 and defined in /var/www/SuiteCRMCorePR/modules/AOBH_BusinessHours/AOBH_BusinessHours.php:185 Stack trace:

0 /var/www/SuiteCRMCorePR/modules/AOW_Actions/actions/actionCreateRecord.php(279): AOBH_BusinessHours->addBusinessHours()

https://github.com/salesagility/SuiteCRM/pull/1 /var/www/SuiteCRMCorePR/modules/AOW_Actions/actions/actionCreateRecord.php(170): actionCreateRecord->set_record() https://github.com/salesagility/SuiteCRM/issues/2 /var/www/SuiteCRMCorePR/modules/AOW_WorkFlow/AOW_WorkFlow.php(1046): actionCreateRecord->run_action() https://github.com/salesagility/SuiteCRM/pull/3 /var/www/SuiteCRMCorePR/modules/AOW_WorkFlow/AOW_WorkFlow.php(214): AOW_WorkFlow->run_actions() https://github.com/salesagility/SuiteCRM/issues/4 /var/www/SuiteCRMCorePR/modules/AOW_WorkFlow/AOW_WorkFlow.php(198): AOW_WorkFlow->run_flow() https://github.com/salesagility/SuiteCRM/issues/5 /var/www/SuiteCRMCorePR/modules/Schedulers/_AddJobsHere.php(836): AOW_WorkFlow->run_flows() https://github.com/salesagility/SuiteCRM/issues/6 /var/www/SuiteCRMCorePR/modules/SchedulersJobs/SchedulersJob.php(529): processAOW_Workflow() https://github.com/salesagility/SuiteCRM/pull/7 /var/www/SuiteCRMCorePR/include/SugarQueue/SugarCronJobs.php(191): SchedulersJob->runJob() https://github.com/salesagility/SuiteCRM/pull/8 /var/www/SuiteCRMCorePR/include/SugarQueue/SugarCronJobs.php(233): SugarCronJobs->executeJob() https://github.com/salesagility/SuiteCRM/pull/9 /var/www/SuiteCRMCorePR/cron.php(100): SugarCronJobs->runCycle() https://github.com/salesagility/SuiteCRM/pull/10 {main} thrown in /var/www/SuiteCRMCorePR/modules/AOBH_BusinessHours/AOBH_BusinessHours.php on line 185

Motivation and Context

How To Test This

  1. Create Workflow
  2. Create Action where the business hours is used to calculate date field e.g. Date Created -> Date -> Date Created -> + -> 5 Business Hours
  3. Run WF via cron

Types of changes

Final checklist