Skip to content

Commit 50458bc

Browse files
Fix value managerId
1 parent 7baa570 commit 50458bc

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

ProcessMaker/Http/Controllers/Api/ProcessController.php

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -623,33 +623,43 @@ public function update(Request $request, Process $process)
623623

624624
private function validateMaxManagers(Request $request)
625625
{
626-
$managerIds = $request->input('manager_id', '[]');
626+
$managerIds = $request->input('manager_id', []);
627627

628+
// Handle different input types
628629
if (is_string($managerIds)) {
629-
$managerIds = json_decode($managerIds, true);
630-
631-
// Handle JSON decode failure
632-
if (json_last_error() !== JSON_ERROR_NONE) {
633-
throw new \Illuminate\Validation\ValidationException(
634-
validator([], []),
635-
['manager_id' => [__('Invalid JSON format for manager_id')]]
636-
);
637-
}
630+
// If it's a string, try to decode it as JSON
631+
if (empty($managerIds)) {
632+
$managerIds = [];
633+
} else {
634+
$decoded = json_decode($managerIds, true);
635+
636+
// Handle JSON decode failure
637+
if (json_last_error() !== JSON_ERROR_NONE) {
638+
throw new \Illuminate\Validation\ValidationException(
639+
validator([], []),
640+
['manager_id' => [__('Invalid JSON format for manager_id')]]
641+
);
642+
}
638643

639-
// Ensure we have an array
640-
if (!is_array($managerIds)) {
641-
$managerIds = [$managerIds];
644+
$managerIds = $decoded;
642645
}
643646
}
644647

645-
// Filter out null values and validate each manager ID
648+
// Ensure we have an array
649+
if (!is_array($managerIds)) {
650+
// If it's a single value (not array), convert to array
651+
$managerIds = [$managerIds];
652+
}
653+
654+
// Filter out null, empty values and validate each manager ID
646655
$managerIds = array_filter($managerIds, function ($id) {
647-
return $id !== null && is_numeric($id) && $id > 0;
656+
return $id !== null && $id !== '' && is_numeric($id) && $id > 0;
648657
});
649658

650-
// Re-index the array to remove gaps from filtered null values
659+
// Re-index the array to remove gaps from filtered values
651660
$managerIds = array_values($managerIds);
652661

662+
// Validate maximum number of managers
653663
if (count($managerIds) > 10) {
654664
throw new \Illuminate\Validation\ValidationException(
655665
validator([], []),

0 commit comments

Comments
 (0)