PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 2.2.0
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v2.2.0
2.2.0 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 All 43 releases
fluent-boards / app / Hooks / Handlers / UpdateHandler.php

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

128 lines 5.9 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\Task;
6 use FluentBoards\App\Models\TaskMeta;
7 use FluentBoards\App\Services\Constant;
8 use FluentBoards\App\Services\IndexUpgradeService;
9
10 class UpdateHandler
11 {
12 public function maybeUpgradeIndexes()
13 {
14 return (new IndexUpgradeService())->maybeUpgrade();
15 }
16
17 public static function maybeSubtaskGroupSync()
18 {
19 $lastDbVersion = get_option('_fluent_boards_db_version');
20 if (!$lastDbVersion || version_compare($lastDbVersion, FLUENT_BOARDS_DB_VERSION, '<')) {
21 // the last updated version is less than the current version
22 // self::adjustOldSubtasksToSubtaskGroup();
23 update_option('_fluent_boards_db_version', FLUENT_BOARDS_DB_VERSION);
24 }
25
26 }
27 public static function maybeUpdateDbTables()
28 {
29 $lastDbVersion = get_option('_fluent_boards_db_version');
30 if (!$lastDbVersion || version_compare($lastDbVersion, FLUENT_BOARDS_DB_VERSION, '<')) {
31 // last updated version is less than current version
32 self::updateDatabase();
33 update_option('_fluent_boards_db_version', FLUENT_BOARDS_DB_VERSION);
34 }
35 }
36
37 private static function adjustOldSubtasksToSubtaskGroup()
38 {
39 $allSubtasks = Task::whereNotNull('parent_id')->get();
40 foreach ($allSubtasks as $subtask) {
41 //need to check if that subtask is in a subtaskGroup or not
42 $isInGroup = TaskMeta::where('task_id', $subtask->id)
43 ->where('key', Constant::SUBTASK_GROUP_CHILD)
44 ->exists();
45 if ($isInGroup) {
46 continue;
47 }
48
49 //check if any subtask group created for the parent task of the current subtask
50 $group = TaskMeta::where('task_id', $subtask->parent_id)
51 ->where('key', Constant::SUBTASK_GROUP_NAME)
52 ->first();
53
54 if ($group) {
55 TaskMeta::create([
56 'task_id' => $subtask->id,
57 'key' => Constant::SUBTASK_GROUP_CHILD,
58 'value' => $group->id
59 ]);
60 } else {
61 $newSubtaskGroup = TaskMeta::create([
62 'task_id' => $subtask->parent_id,
63 'key' => Constant::SUBTASK_GROUP_NAME,
64 'value' => 'Subtask Group One'
65 ]);
66
67 TaskMeta::create([
68 'task_id' => $subtask->id,
69 'key' => Constant::SUBTASK_GROUP_CHILD,
70 'value' => $newSubtaskGroup->id
71 ]);
72 }
73 }
74
75 }
76
77 private static function updateDatabase()
78 {
79 global $wpdb;
80
81 $table = $wpdb->prefix . 'fbs_board_terms';
82
83 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Schema check query, caching not applicable
84 if ($wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $table)) != $table) {
85 return;
86 } else {
87 // change column type from int to decimal - for already installed sites
88 $column_name = 'position';
89 // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name and column name cannot be prepared
90 $preparedQuery = $wpdb->prepare("DESCRIBE $table %s", $column_name);
91 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Variable contains prepared query, schema check, caching not applicable
92 $dataType = $wpdb->get_row($preparedQuery);
93 if (strpos($dataType->Type, 'int') !== false) {
94 $sql = $wpdb->prepare(
95 // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name and column name cannot be prepared
96 "ALTER TABLE $table MODIFY $column_name decimal(10,2) NOT NULL DEFAULT '1' COMMENT 'Position: 1 = top/first, 2 = second/second in top, etc.';"
97 );
98 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Variable contains prepared query, schema modification, caching not applicable
99 $wpdb->query($sql);
100 }
101 }
102
103 $table = $wpdb->prefix . 'fbs_comments';
104
105 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Schema check query, caching not applicable
106 if ($wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $table)) != $table) {
107 return;
108 } else {
109 $column_name = 'settings';
110 // Check if the column already exists
111 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- schema check, caching not applicable
112 $column_exists = $wpdb->get_var($wpdb->prepare(
113 // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Table name cannot be prepared, schema check, caching not applicable
114 "SHOW COLUMNS FROM $table LIKE %s", $column_name
115 ));
116
117 if (!$column_exists) {
118 // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name and column name cannot be prepared
119 $sql = "ALTER TABLE $table ADD $column_name TEXT NULL COMMENT 'serialize array' AFTER `created_by`";
120 // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Variable contains ALTER TABLE query, schema modification, caching not applicable
121 $wpdb->query($sql);
122 }
123 }
124
125 }
126
127 }
128