| @@ -508,14 +508,21 @@ | ||
| 508 | 508 | |
| 509 | 509 | public function moveAllTasks($oldStageId, $newStageId) |
| 510 | 510 | { |
| 511 | 511 | $tasks = Task::where('stage_id', $oldStageId)->whereNull('parent_id')->whereNull('archived_at')->get(); |
| 512 | + $sourceStage = Stage::findOrFail($oldStageId); | |
| 513 | + $targetStage = Stage::findOrFail($newStageId); | |
| 512 | 514 | |
| 515 | + // Load shared watcher data once; stage data is injected per task below. | |
| 516 | + $tasks->load('watchers'); | |
| 517 | + | |
| 513 | 518 | // get the last position available of that stage |
| 514 | 519 | $position = (new TaskService())->getLastPositionOfTasks($newStageId); |
| 515 | 520 | |
| 516 | 521 | // update tasks stage and position |
| 517 | 522 | foreach ($tasks as $key => $task) { |
| 523 | + $taskOldStageId = $task->stage_id; | |
| 524 | + | |
| 518 | 525 | // Clean up archived_by_stage meta when moving to different stage |
| 519 | 526 | TaskMeta::where('task_id', $task->id) |
| 520 | 527 | ->where('key', Constant::META_KEY_ARCHIVED_BY_STAGE) |
| 521 | 528 | ->delete(); |
| @@ -521,10 +528,29 @@ | ||
| 521 | 528 | ->delete(); |
| 522 | 529 | |
| 523 | 530 | $task->stage_id = $newStageId; |
| 524 | 531 | $task->position = $position + $key; |
| 532 | + $task->setRelation('stage', $targetStage); | |
| 525 | 533 | $task->save(); |
| 534 | + | |
| 535 | + if ((int) $taskOldStageId !== (int) $newStageId) { | |
| 536 | + do_action('fluent_boards/task_stage_updated', $task, $taskOldStageId, [ | |
| 537 | + 'source' => $sourceStage, | |
| 538 | + 'target' => $targetStage, | |
| 539 | + ]); | |
| 540 | + } | |
| 526 | 541 | } |
| 542 | + | |
| 543 | + if ($tasks->count() && (int) $sourceStage->id !== (int) $targetStage->id) { | |
| 544 | + do_action( | |
| 545 | + 'fluent_boards/tasks_moved_between_stages', | |
| 546 | + $sourceStage->board_id, | |
| 547 | + $sourceStage, | |
| 548 | + $targetStage, | |
| 549 | + $tasks->count() | |
| 550 | + ); | |
| 551 | + } | |
| 552 | + | |
| 527 | 553 | return $tasks; |
| 528 | 554 | } |
| 529 | 555 | public function archiveAllTasksInStage($stage_id, $boardId = null) |
| 530 | 556 | { |