| @@ -8,8 +8,9 @@ | ||
| 8 | 8 | use FluentCrm\App\Models\Tag; |
| 9 | 9 | use WP_CLI; |
| 10 | 10 | |
| 11 | 11 | use FluentBoards\App\Models\Board; |
| 12 | +use FluentBoards\App\Models\Task; | |
| 12 | 13 | |
| 13 | 14 | class Commands |
| 14 | 15 | { |
| 15 | 16 | public function crm_role_assign() |
| @@ -115,6 +116,72 @@ | ||
| 115 | 116 | $added++; |
| 116 | 117 | } |
| 117 | 118 | |
| 118 | 119 | \WP_CLI::success('Operation Completed. ' . $added . ' contacts added to the board'); |
| 120 | + } | |
| 121 | + | |
| 122 | + /** | |
| 123 | + * Create random tasks for a board. | |
| 124 | + * | |
| 125 | + * ## OPTIONS | |
| 126 | + * | |
| 127 | + * [--board_id=<board_id>] | |
| 128 | + * : The ID of the board to create tasks for. Default is the first board. | |
| 129 | + * | |
| 130 | + * [--count=<count>] | |
| 131 | + * : The number of tasks to create. Default is 10. | |
| 132 | + * | |
| 133 | + * ## EXAMPLES | |
| 134 | + * | |
| 135 | + * wp fluent_boards create_random_tasks --board_id=85 --count=1000 | |
| 136 | + * | |
| 137 | + * @when after_wp_load | |
| 138 | + */ | |
| 139 | + public function create_random_tasks($args, $assoc_args) | |
| 140 | + { | |
| 141 | + // wp fluent_boards create_random_tasks --board_id=85 --count=1500 | |
| 142 | + $board_id = isset($assoc_args['board_id']) ? intval($assoc_args['board_id']) : 0; | |
| 143 | + $total_tasks = isset($assoc_args['count']) ? intval($assoc_args['count']) : 10; | |
| 144 | + | |
| 145 | + if ($board_id === 0) { | |
| 146 | + $board = Board::first(); | |
| 147 | + } else { | |
| 148 | + $board = Board::find($board_id); | |
| 149 | + } | |
| 150 | + | |
| 151 | + if (!$board) { | |
| 152 | + WP_CLI::error('Board not found.'); | |
| 153 | + return; | |
| 154 | + } | |
| 155 | + | |
| 156 | + $stageIds = $board->stages()->pluck('id')->toArray(); | |
| 157 | + | |
| 158 | + if (empty($stageIds)) { | |
| 159 | + WP_CLI::error('No stages found for this board.'); | |
| 160 | + return; | |
| 161 | + } | |
| 162 | + | |
| 163 | + $progress = \WP_CLI\Utils\make_progress_bar('Creating tasks', $total_tasks); | |
| 164 | + | |
| 165 | + $currentDateTime = new \DateTime(); | |
| 166 | + $formattedDateTime = $currentDateTime->format('Y-m-d H:i:s'); | |
| 167 | + | |
| 168 | + $tasks = []; | |
| 169 | + for ($i = 0; $i < $total_tasks; $i++) { | |
| 170 | + $tasks[] = [ | |
| 171 | + 'title' => 'Task Random ' . ($i + 1), | |
| 172 | + 'board_id' => $board->id, | |
| 173 | + 'stage_id' => $stageIds[array_rand($stageIds)], | |
| 174 | + 'created_at' => $formattedDateTime, | |
| 175 | + 'updated_at' => $formattedDateTime, | |
| 176 | + ]; | |
| 177 | + $progress->tick(); | |
| 178 | + } | |
| 179 | + | |
| 180 | + // Bulk insert | |
| 181 | + Task::insert($tasks); | |
| 182 | + | |
| 183 | + $progress->finish(); | |
| 184 | + | |
| 185 | + WP_CLI::success("$total_tasks tasks created successfully for board ID: {$board->id}"); | |
| 119 | 186 | } |
| 120 | 187 | } |