Skip to content

Commit f6c8ee3

Browse files
committed
Solved an error in demo seeder when creating a ticket without comments
1 parent d92a042 commit f6c8ee3

1 file changed

Lines changed: 29 additions & 27 deletions

File tree

src/Seeds/DemoDataSeeder.php

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -199,35 +199,37 @@ public function run()
199199
$this->comments_per_ticket_max
200200
);
201201

202-
for ($c = 1; $c <= $comments_qty; $c++) {
203-
if (is_null($ticket->completed_at)) {
204-
$random_comment_date = $faker->dateTimeBetween(
205-
'-'.$random_create.' days',
206-
'now'
207-
);
208-
} else {
209-
$random_comment_date = $faker->dateTimeBetween(
210-
'-'.$random_create.' days',
211-
'-'.($random_create - floor($minutes_random_complete / 60 / 24)).' days'
212-
);
202+
if ($comments_qty){
203+
for ($c = 1; $c <= $comments_qty; $c++) {
204+
if (is_null($ticket->completed_at)) {
205+
$random_comment_date = $faker->dateTimeBetween(
206+
'-'.$random_create.' days',
207+
'now'
208+
);
209+
} else {
210+
$random_comment_date = $faker->dateTimeBetween(
211+
'-'.$random_create.' days',
212+
'-'.($random_create - floor($minutes_random_complete / 60 / 24)).' days'
213+
);
214+
}
215+
216+
$comment = new Models\Comment();
217+
$comment->ticket_id = $ticket->id;
218+
$comment->content = $faker->paragraphs(3, true);
219+
$comment->html = nl2br($comment->content);
220+
221+
if ($c % 2 == 0) {
222+
$comment->user_id = $ticket->user_id;
223+
} else {
224+
$comment->user_id = $ticket->agent_id;
225+
}
226+
$comment->created_at = $random_comment_date;
227+
$comment->updated_at = $random_comment_date;
228+
$comment->save();
213229
}
214-
215-
$comment = new Models\Comment();
216-
$comment->ticket_id = $ticket->id;
217-
$comment->content = $faker->paragraphs(3, true);
218-
$comment->html = nl2br($comment->content);
219-
220-
if ($c % 2 == 0) {
221-
$comment->user_id = $ticket->user_id;
222-
} else {
223-
$comment->user_id = $ticket->agent_id;
224-
}
225-
$comment->created_at = $random_comment_date;
226-
$comment->updated_at = $random_comment_date;
227-
$comment->save();
230+
$last_comment = $ticket->Comments->sortByDesc('created_at')->first();
231+
$ticket->updated_at = $last_comment['created_at'];
228232
}
229-
$last_comment = $ticket->Comments->sortByDesc('created_at')->first();
230-
$ticket->updated_at = $last_comment['created_at'];
231233
$ticket->save();
232234
}
233235
}

0 commit comments

Comments
 (0)