You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.3 KiB

  1. <?php
  2. use App\Business;
  3. use App\User;
  4. use Carbon\Carbon;
  5. use Illuminate\Database\Seeder;
  6. use Illuminate\Support\Facades\DB;
  7. class TaskSeeder extends Seeder
  8. {
  9. public function run()
  10. {
  11. /** @var User $owner */
  12. // every project has it's own tasks
  13. /**
  14. * Every task has it's own tags, which must be present in business that this tags belongs to it.
  15. */
  16. $businesses = Business::with('owners', 'projects')->get();
  17. $tasks = [];
  18. $left = count($businesses);
  19. $now = Carbon::now()->toDateTimeString();
  20. $future = Carbon::now()->addDays(10)->toDateTimeString();
  21. foreach ($businesses as $business) {
  22. foreach ($business->owners as $owner) {
  23. foreach ($business->projects as $project) {
  24. foreach ($business->members as $member) {
  25. for ($i = 1; $i <= 30; $i++) {
  26. foreach ($business->workflows as $workflow) {
  27. $status = $workflow->workstatuses->random();
  28. $tasks[] = [
  29. 'business_id' => $business->id,
  30. // 'creator_id' => $owner->id,
  31. // 'project_id' => $project->id,
  32. // 'user_id' => $member->id,
  33. // 'workflow_id' => $workflow->id,
  34. // 'work_status_id' => $status->id,
  35. // 'name' => 'Task #' . rand(111111, 999999),
  36. // 'time' => "10:00:00",
  37. // 'cost' => 10000,
  38. // 'completed' => $status->done,
  39. // 'due_date' => $status->done ? $now : $future,
  40. ];
  41. }
  42. }
  43. }
  44. }
  45. }
  46. $this->command->info(--$left . " Business is left.");
  47. }
  48. dd('here');
  49. $chunks = array_chunk($tasks, 1000);
  50. $number = count($chunks);
  51. foreach ($chunks as $value) {
  52. DB::table('tasks')->insert($value);
  53. $this->command->info(--$number . " Chunk is left.");
  54. }
  55. }
  56. }