salesagility / SuiteCRM

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

Creation of Project with Template Causes 500 Error #10321

Closed pstevens71 closed 4 months ago

pstevens71 commented 8 months ago

Issue

When a project is created with a template a 500 error is generated:

[18-Jan-2024 21:30:25 UTC] PHP Fatal error:  Uncaught Error: Call to a member function format() on bool in MYINSTALL.com/modules/Project/Project.php:625
Stack trace:
#0 MYINSTALL.com/modules/AOW_Actions/actions/actionCreateRecord.php(410): Project->save(false)
#1 MYINSTALL.com/modules/AOW_Actions/actions/actionModifyRecord.php(126): actionCreateRecord->set_record(Object(Project), Object(Project), Array, true)
#2 MYINSTALL.com/modules/AOW_WorkFlow/AOW_WorkFlow.php(1027): actionModifyRecord->run_action(Object(Project), Array, true)
#3 MYINSTALL.com/modules/AOW_WorkFlow/AOW_WorkFlow.php(231): AOW_WorkFlow->run_actions(Object(Project), true)
#4 MYINSTALL.com/include/utils/LogicHook.php(261): AOW_WorkFlow->run_bean_flows(Object(Project), 'after_save', '')
#5 MYINSTALL.com/include/utils/LogicHook.php(202): LogicHook->process_hooks(Array, 'after_save', '')
#6 MYINSTALL.com/data/SugarBean.php(3185): LogicHook->call_custom_logic('Project', 'after_save', '')
#7 MYINSTALL.com/data/SugarBean.php(2432): SugarBean->call_custom_logic('after_save', '')
#8 MYINSTALL.com/modules/Project/Project.php(436): SugarBean->save(false)
#9 MYINSTALL.com/modules/Project/Save.php(112): Project->save(false)
#10 MYINSTALL.com/include/MVC/View/SugarView.php(824): include_once('/home/pablostev...')
#11 MYINSTALL.com/include/MVC/View/views/view.classic.php(72): SugarView->includeClassicFile('modules/Project...')
#12 MYINSTALL.com/include/MVC/View/SugarView.php(210): ViewClassic->display()
#13 MYINSTALL.com/include/MVC/Controller/SugarController.php(432): SugarView->process()
#14 MYINSTALL.com/include/MVC/Controller/SugarController.php(363): SugarController->processView()
#15 MYINSTALL.com/include/MVC/SugarApplication.php(101): SugarController->execute()
#16 MYINSTALL.com/index.php(52): SugarApplication->execute()
#17 {main}
  thrown in MYINSTALL.com/modules/Project/Project.php on line 625

Upon further investigation line 625: $start = $startdate->format('Y-m-d'); $start_date is null after first iteration causing it to return Boolean false instead of the date.

Expected Behavior

The function should iterate through the loop and populate the $start_date with the start date of the task.

Actual Behavior

What actually happens is after the first loop, the $enddate_array[] is re-inialized causing it to be empty and thus causing the rest of the function to fail because a Boolean value false cannot be converted to a date.

Possible Fix

I've reviewed this recent update. https://github.com/salesagility/SuiteCRM/commit/9aff7071bb86df7e06e2cf56aa3060fc00e3978a

Where:

$enddate_array = []; is supposed to be inserted at line 330, but it's actually inserted on line 613 commenting it out at line 613 solves the problem and it works as expected. Adding it back at line 330 causes no issues.

Steps to Reproduce

  1. Create a project
  2. Add a template with MORE than one task
  3. Save the Project
  4. 500 error

Context

This bug prevents projects from being created from templates.

Your Environment

pstevens71 commented 8 months ago

Here's the PR to fix this:

https://github.com/salesagility/SuiteCRM/pull/10322