|
34 | 34 | use ProcessMaker\Models\UserResourceView; |
35 | 35 | use ProcessMaker\Notifications\TaskReassignmentNotification; |
36 | 36 | use ProcessMaker\Query\SyntaxError; |
| 37 | +use ProcessMaker\Repositories\ProcessExecutionRawRepository; |
37 | 38 | use ProcessMaker\SanitizeHelper; |
38 | 39 | use ProcessMaker\Traits\TaskControllerIndexMethods; |
39 | 40 |
|
40 | 41 | class TaskController extends Controller |
41 | 42 | { |
42 | 43 | use TaskControllerIndexMethods; |
43 | 44 |
|
| 45 | + private ?ProcessExecutionRawRepository $processExecutionRaw = null; |
| 46 | + |
| 47 | + private function processExecutionRaw(): ProcessExecutionRawRepository |
| 48 | + { |
| 49 | + return $this->processExecutionRaw ??= app(ProcessExecutionRawRepository::class); |
| 50 | + } |
| 51 | + |
44 | 52 | /** |
45 | 53 | * A whitelist of attributes that should not be |
46 | 54 | * sanitized by our SanitizeInput middleware. |
@@ -354,28 +362,48 @@ public function show(ProcessRequestToken $task) |
354 | 362 | */ |
355 | 363 | public function update(Request $request, ProcessRequestToken $task) |
356 | 364 | { |
| 365 | + if (!$task->relationLoaded('process')) { |
| 366 | + $task->setRelation('process', $this->processExecutionRaw()->getProcessForAuthorizeRaw($task->process_id)); |
| 367 | + } |
357 | 368 | $this->authorize('update', $task); |
358 | 369 | if ($request->input('status') === 'COMPLETED') { |
359 | 370 | if ($task->status === 'CLOSED') { |
360 | 371 | return abort(422, __('Task already closed')); |
361 | 372 | } |
362 | 373 | // Skip ConvertEmptyStringsToNull and TrimStrings middlewares |
363 | 374 | $data = json_optimize_decode($request->getContent(), true); |
364 | | - $data = SanitizeHelper::sanitizeData($data['data'], null, $task->processRequest->do_not_sanitize ?? []); |
| 375 | + $instance = $this->processExecutionRaw()->getProcessRequestForCompleteRaw($task->process_request_id); |
| 376 | + $data = SanitizeHelper::sanitizeData($data['data'], null, $instance->do_not_sanitize ?? []); |
| 377 | + |
365 | 378 | //Call the manager to trigger the start event |
366 | | - $process = $task->process; |
367 | | - $instance = $task->processRequest; |
368 | | - TaskDraft::moveDraftFiles($task); |
| 379 | + $process = $this->processExecutionRaw()->getProcessForCompleteRaw($task->process_id); |
| 380 | + $instance->setRelation('process', $process); |
| 381 | + if ($processVersion = $this->processExecutionRaw()->getProcessVersionForCompleteRaw($instance->process_version_id)) { |
| 382 | + $instance->setRelation('processVersion', $processVersion); |
| 383 | + } |
| 384 | + $task->setRelation('processRequest', $instance); |
| 385 | + $task->setRelation('process', $process); |
| 386 | + |
| 387 | + if ($this->processExecutionRaw()->taskHasDraftRaw($task->id)) { |
| 388 | + TaskDraft::moveDraftFiles($task); |
| 389 | + } |
| 390 | + |
369 | 391 | WorkflowManager::completeTask($process, $instance, $task, $data); |
370 | 392 |
|
371 | | - return new Resource($task->refresh()); |
| 393 | + $responseInstance = $this->processExecutionRaw()->getProcessRequestForResponseRaw($task->process_request_id); |
| 394 | + $responseInstance->setRelation('process', $process); |
| 395 | + $taskRefreshed = $this->processExecutionRaw()->refreshTaskRaw($task, $process, $responseInstance); |
| 396 | + |
| 397 | + return new Resource($taskRefreshed); |
372 | 398 | } elseif (!empty($request->input('user_id'))) { |
| 399 | + $process = $this->processExecutionRaw()->getProcessForReassignRaw($task->process_id); |
| 400 | + $task->setRelation('process', $process); |
| 401 | + |
373 | 402 | $userToAssign = $request->input('user_id'); |
374 | 403 | $comments = $request->input('comments'); |
375 | 404 | $task->reassign($userToAssign, $request->user(), $comments); |
376 | 405 |
|
377 | | - $taskRefreshed = $task->refresh(); |
378 | | - |
| 406 | + $taskRefreshed = $this->processExecutionRaw()->refreshTaskRaw($task, $process, $task->processRequest); |
379 | 407 | CaseUpdate::dispatchSync($task->processRequest, $taskRefreshed); |
380 | 408 |
|
381 | 409 | return new Resource($taskRefreshed); |
|
0 commit comments