PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 2.0.4
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v2.0.4
2.1.0 2.0.15 2.0.12 2.0.10 2.0.4 2.0.1 2.0.0 1.95.3 1.95.2 1.95 1.91.6 trunk 1.11 1.12 1.13 1.20 1.21 1.22 1.23 1.30 1.31 1.32 1.35 1.40 1.41 All 42 releases
fluent-boards / app / Hooks / Handlers / StageArchiveHandler.php

StageArchiveHandler.php in FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration 2.0.4, at app/Hooks/Handlers/StageArchiveHandler.php

80 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentBoards\App\Hooks\Handlers;
4
5 use FluentBoards\App\Models\Board;
6 use FluentBoards\App\Models\Task;
7 use FluentBoards\App\Models\TaskMeta;
8 use FluentBoards\App\Models\Stage;
9 use FluentBoards\App\Services\Constant;
10
11 class StageArchiveHandler
12 {
13 public function onStageArchived($boardId, $stage)
14 {
15 try {
16 $tasks = Task::where('stage_id', $stage->id)
17 ->whereNull('parent_id')
18 ->whereNull('archived_at')
19 ->get();
20
21 foreach ($tasks as $task) {
22 $task->position = 0;
23 $task->archived_at = current_time('mysql');
24 $task->save();
25
26 TaskMeta::updateOrCreate(
27 ['task_id' => $task->id, 'key' => Constant::META_KEY_ARCHIVED_BY_STAGE],
28 ['value' => $stage->id]
29 );
30 }
31 (new BoardHandler())->updateBoardTaskCount($boardId);
32
33 } catch (\Exception $e) {
34 error_log($e->getMessage());
35 }
36 }
37
38 public function onStageRestored($boardId, $stage)
39 {
40 try {
41 if (!$stage || !isset($stage->id)) {
42 return;
43 }
44
45 // Prevent task restoration if the stage is still archived
46 if ($stage->archived_at !== null) {
47 return;
48 }
49
50 $restorableTaskIds = TaskMeta::where('key', Constant::META_KEY_ARCHIVED_BY_STAGE)
51 ->where('value', $stage->id)
52 ->pluck('task_id')
53 ->toArray();
54
55 if (empty($restorableTaskIds)) {
56 return;
57 }
58
59 $tasks = Task::whereIn('id', $restorableTaskIds)
60 ->where('stage_id', $stage->id)
61 ->whereNotNull('archived_at')
62 ->get();
63
64 foreach ($tasks as $task) {
65 $task->archived_at = null;
66 $task->save();
67
68 TaskMeta::where('task_id', $task->id)
69 ->where('key', Constant::META_KEY_ARCHIVED_BY_STAGE)
70 ->delete();
71 }
72 (new BoardHandler())->updateBoardTaskCount($boardId);
73 } catch (\Exception $e) {
74 error_log( $e->getMessage());
75 }
76 }
77
78 }
79
80