@@ -20,39 +20,78 @@ class ProcessManagerAssigned implements AssignmentRuleInterface
2020 * The task is assigned to the Manager of the Process.
2121 *
2222 * It takes in count the process version of the request.
23- * If the process does not have assigned a Manager, it throws an exception.
23+ * If the process does not have assigned a Manager, it returns null instead of throwing an exception.
2424 *
2525 * @param ActivityInterface $task
2626 * @param TokenInterface $token
2727 * @param Process $process
2828 * @param ProcessRequest $request
2929 * @return int|null
30- * @throws ThereIsNoProcessManagerAssignedException
3130 */
3231 public function getNextUser (ActivityInterface $ task , TokenInterface $ token , Process $ process , ProcessRequest $ request )
3332 {
3433 // review for multiple managers
3534 $ managers = $ request ->processVersion ->manager_id ;
36- $ user_id = $ this ->getNextManagerAssigned ($ managers , $ task , $ request );
37- if (!$ user_id ) {
38- throw new ThereIsNoProcessManagerAssignedException ($ task );
35+
36+ // Normalize: treat empty array as null
37+ if (is_array ($ managers ) && empty ($ managers )) {
38+ $ managers = null ;
3939 }
4040
41+ $ user_id = $ this ->getNextManagerAssigned ($ managers , $ task , $ request );
42+
43+ // Return null instead of throwing exception when no manager is found
44+ // This allows the process to continue without crashing
4145 return $ user_id ;
4246 }
4347
4448 /**
4549 * Get the round robin manager using a true round robin algorithm
4650 *
47- * @param array $managers
51+ * @param array|int|null $managers Manager ID(s) - can be array, single int, or null
4852 * @param ActivityInterface $task
4953 * @param ProcessRequest $request
5054 * @return int|null
5155 */
5256 private function getNextManagerAssigned ($ managers , $ task , $ request )
5357 {
54- // Validate input
55- if (empty ($ managers ) || !is_array ($ managers )) {
58+ // Handle null case
59+ if (is_null ($ managers )) {
60+ return null ;
61+ }
62+
63+ // Convert single value to array for backward compatibility
64+ if (!is_array ($ managers )) {
65+ // If it's a valid integer, convert to array
66+ if (is_numeric ($ managers ) && $ managers > 0 ) {
67+ $ managers = [(int ) $ managers ];
68+ } else {
69+ // Invalid single value (0, empty string, 'undefined', etc.)
70+ return null ;
71+ }
72+ }
73+
74+ // Validate array is not empty
75+ if (empty ($ managers )) {
76+ return null ;
77+ }
78+
79+ // Filter out invalid values (null, 0, empty strings, 'undefined', false, etc.)
80+ $ managers = array_filter ($ managers , function ($ id ) {
81+ // Only accept positive integers
82+ if (!is_numeric ($ id )) {
83+ return false ;
84+ }
85+ $ id = (int ) $ id ;
86+
87+ return $ id > 0 ;
88+ });
89+
90+ // Re-index array after filtering
91+ $ managers = array_values ($ managers );
92+
93+ // Check if we have any valid managers after filtering
94+ if (empty ($ managers )) {
5695 return null ;
5796 }
5897
0 commit comments